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

fix: change base class for JwtAuthenticationError #433

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

syedsajjadkazmii
Copy link
Contributor

@syedsajjadkazmii syedsajjadkazmii commented Feb 1, 2024

Description:

Issue: When JwtAuthentication class raises JwtUserEmailMismatchError custom exception, it is not identified by the default exception handler of rest framework, therefore, returns response = None and hence we get 500 Server error.

Fix: This PR handles this issue by subclassing JwtAuthenticationError from the AuthenticationFailed exception which is a known exception and will be handled by the default exception handler.

JIRA:

VAN-1694

Additional Details

  • Dependencies:: List dependencies on other outstanding PRs, issues, etc.
  • Merge deadline: List merge deadline (if any)
  • Testing instructions: Provide non-trivial testing instructions
  • Author concerns: List any concerns about this PR

Reviewers:

  • tag reviewer

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bump if needed
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Create a tag
  • Check new version is pushed to PyPi after tag-triggered build is
    finished.
  • Delete working branch (if not needed anymore)

@syedsajjadkazmii
Copy link
Contributor Author

Hi @robrap, could i please get your review here?

@syedsajjadkazmii syedsajjadkazmii force-pushed the sajjad/VAN-1694-handle-exception branch from a2147bc to 6d17379 Compare February 1, 2024 18:45
@@ -34,7 +34,7 @@ class JwtSessionUserMismatchError(JwtAuthenticationError):
pass


class JwtUserEmailMismatchError(JwtAuthenticationError):
class JwtUserEmailMismatchError(exceptions.AuthenticationFailed):
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Could we change the base class instead?
class JwtAuthenticationError(exceptions.AuthenticationFailed):
  1. Is there any additional assertion we could add to a test to ensure that the right type of exception is being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we change the base class instead?

Yes, done.

Is there any additional assertion we could add to a test to ensure that the right type of exception is being used?

Since AuthenticationFailed is a known exception to the default exception handler therefore it gets handled by the exception handler and we only get a 401 Unauthorized response. Exception is not being propagated up and we are not getting it in the test. So, I don't think we can assert the exception type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Although it is unlikely that someone will break this, a unit test that creates an instance of JwtSessionUserMismatchError and asserts that it is also an instance of AuthenticationFailed would prevent regressions. I'm not sure if it is worth it, but it is also very quick to implement. I'll leave it to you to decide.

@syedsajjadkazmii syedsajjadkazmii force-pushed the sajjad/VAN-1694-handle-exception branch 2 times, most recently from 87c7b47 to 71c5b64 Compare February 2, 2024 07:45
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

I left a unit test idea, but I'll leave that to you to decide. See #433 (comment). Thanks.

@syedsajjadkazmii syedsajjadkazmii changed the title fix: change base class for JwtUserEmailMismatchError fix: change base class for JwtAuthenticationError Feb 6, 2024
@syedsajjadkazmii syedsajjadkazmii force-pushed the sajjad/VAN-1694-handle-exception branch from 71c5b64 to 0ca3546 Compare February 6, 2024 07:49
@syedsajjadkazmii syedsajjadkazmii force-pushed the sajjad/VAN-1694-handle-exception branch from 0ca3546 to 9a75d40 Compare February 6, 2024 07:54
@syedsajjadkazmii
Copy link
Contributor Author

I left a unit test idea, but I'll leave that to you to decide. See #433 (comment). Thanks.

Thanks, I have added the test

@syedsajjadkazmii syedsajjadkazmii merged commit 09216ed into master Feb 6, 2024
9 checks passed
@syedsajjadkazmii syedsajjadkazmii deleted the sajjad/VAN-1694-handle-exception branch February 6, 2024 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants