Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle wrong library ProblemDetailException (PP-1860) #2170

Merged
merged 2 commits into from
Nov 19, 2024

Conversation

jonathangreen
Copy link
Member

Description

Handle ProblemDetailException that results when a patron tries to log into the wrong library.

Because of the way the tests mocked things, there were a few changes to the tests to make sure the right function gets mocked.

Motivation and Context

By far the most common unhandled exception we are seeing from the webserver is this one:

Traceback (most recent call last):
  File "/var/www/circulation/env/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/circulation/env/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/var/www/circulation/src/palace/manager/api/routes.py", line 120, in decorated
    return f(*args, **kwargs)
  File "/var/www/circulation/src/palace/manager/api/routes.py", line 93, in wrapped_function
    resp = make_response(f(*args, **kwargs))
  File "/var/www/circulation/src/palace/manager/api/routes.py", line 43, in decorated
    patron = app.manager.index_controller.authenticated_patron_from_request()
  File "/var/www/circulation/src/palace/manager/api/controller/base.py", line 73, in authenticated_patron_from_request
    patron = self.authenticated_patron(auth)
  File "/var/www/circulation/src/palace/manager/api/controller/base.py", line 96, in authenticated_patron
    patron = self.manager.auth.authenticated_patron(self._db, authorization_header)
  File "/var/www/circulation/src/palace/manager/api/authenticator.py", line 159, in authenticated_patron
    return self.invoke_authenticator_method("authenticated_patron", _db, header)
  File "/var/www/circulation/src/palace/manager/api/authenticator.py", line 154, in invoke_authenticator_method
    return getattr(self.library_authenticators[short_name], method_name)(
  File "/var/www/circulation/src/palace/manager/api/authenticator.py", line 452, in authenticated_patron
    return self.basic_auth_provider.authenticated_patron(_db, auth.parameters)
  File "/var/www/circulation/src/palace/manager/api/authentication/basic.py", line 859, in authenticated_patron
    patron = self.authenticate(_db, authorization)
  File "/var/www/circulation/src/palace/manager/api/authentication/basic.py", line 495, in authenticate
    patrondata = self.enforce_library_identifier_restriction(patrondata)
  File "/var/www/circulation/src/palace/manager/api/authentication/basic.py", line 834, in enforce_library_identifier_restriction
    raise ProblemDetailException(
palace.manager.util.problem_detail.ProblemDetailException: Wrong library

It occurs when trying to log into the wrong library. It seems like maybe Aspen has some users misconfigured, since many of these requests originate from them.

This is causing unnecessary alerts, since this is an "expected" exception in this case, so we handle the exception.

How Has This Been Tested?

  • Running tests in CI

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@jonathangreen jonathangreen added the bug Something isn't working label Nov 15, 2024
@jonathangreen jonathangreen requested a review from a team November 15, 2024 19:07
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.80%. Comparing base (05748ac) to head (1bf5522).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2170   +/-   ##
=======================================
  Coverage   90.79%   90.80%           
=======================================
  Files         351      351           
  Lines       40716    40714    -2     
  Branches     8822     8821    -1     
=======================================
  Hits        36969    36969           
+ Misses       2438     2437    -1     
+ Partials     1309     1308    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@jonathangreen jonathangreen changed the title Handle wrong library ProblemDetailException Handle wrong library ProblemDetailException (PP-1860) Nov 15, 2024
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@jonathangreen jonathangreen merged commit 172403b into main Nov 19, 2024
21 checks passed
@jonathangreen jonathangreen deleted the bugfix/unhandled-auth-exception branch November 19, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants