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

Update authentication.py Code Simplification #9502

Closed
wants to merge 1 commit into from

Conversation

Codex-v
Copy link

@Codex-v Codex-v commented Aug 18, 2024

Reduced redundant checks in the authenticate method by combining the conditions for the length of auth. Removed the unnecessary elif in favor of an if to make the code flow clearer

Note: Before submitting a code change, please review our contributing guidelines.

Description

Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use refs #... in the description of the pull request.


Reduced redundant checks in the authenticate method by combining the conditions for the length of auth.
Removed the unnecessary elif in favor of an if to make the code flow clearer
Comment on lines -170 to -175
"""
A custom token model may be used, but must have the following properties.

* key -- The string identifying the token
* user -- The user to which the token belongs
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would this need to be removed?

Comment on lines -183 to -188
if len(auth) == 1:
msg = _('Invalid token header. No credentials provided.')
raise exceptions.AuthenticationFailed(msg)
elif len(auth) > 2:
msg = _('Invalid token header. Token string should not contain spaces.')
raise exceptions.AuthenticationFailed(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened to these error messages? The idea is to validate the shape of the token header; with your proposed code, an invalid token will go unnoticed.

Comment on lines -193 to +182
msg = _('Invalid token header. Token string should not contain invalid characters.')
raise exceptions.AuthenticationFailed(msg)
raise exceptions.AuthenticationFailed(
_('Invalid token header. Token string should not contain invalid characters.')
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change necessary?

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

I am closing this PR as not needed for now

@auvipy auvipy closed this Aug 27, 2024
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.

3 participants