Skip to content

Conversation

@ludusrusso
Copy link
Contributor

@ludusrusso ludusrusso commented Feb 9, 2018

This shoud fix #119!

All test passes!

$ python -m pytest
=================================================== test session starts ===================================================
platform darwin -- Python 3.6.1, pytest-3.4.0, py-1.5.2, pluggy-0.6.0
rootdir: /Users/ludus/develop/playground/flask-jwt-extended, inifile:
collected 91 items

tests/test_asymmetric_crypto.py .                                                                                   [  1%]
tests/test_blacklist.py ...........                                                                                 [ 13%]
tests/test_claims_verification.py ............                                                                      [ 26%]
tests/test_config.py ..........                                                                                     [ 37%]
tests/test_cookies.py ..................                                                                            [ 57%]
tests/test_decode_tokens.py ............                                                                            [ 70%]
tests/test_headers.py ...                                                                                           [ 73%]
tests/test_headers_and_cookies.py ...                                                                               [ 76%]
tests/test_options_method.py ..                                                                                     [ 79%]
tests/test_user_claims_loader.py ....                                                                               [ 83%]
tests/test_user_loader.py ......                                                                                    [ 90%]
tests/test_view_decorators.py .........                                                                             [100%]

@ludusrusso ludusrusso changed the title Fix Issue #119 (ignoring OPTIONS method in jwt_required) Ignoring OPTIONS method in jwt_required (fix #119) Feb 9, 2018
@coveralls
Copy link

coveralls commented Feb 9, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling ea5fa12 on ludusrusso:master into 32a6604 on vimalloc:master.

@coveralls
Copy link

coveralls commented Feb 9, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 4ad8d64 on ludusrusso:master into 32a6604 on vimalloc:master.

Copy link
Owner

@vimalloc vimalloc left a comment

Choose a reason for hiding this comment

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

Got some minor nit-picks here, but all in all this looks great! Most of these relate to the fact that flask allows you to create your own OPTIONS method, and even though I'm sure no one actually does that, because it is something supported by flask I want to make sure this extension doesn't break that.

Thanks for contributing! 👍

if not verify_token_claims(jwt_data[config.user_claims_key]):
raise UserClaimsVerificationError('User claims verification failed')
_load_user(jwt_data[config.identity_claim_key])
return fn(*args, **kwargs)
Copy link
Owner

Choose a reason for hiding this comment

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

If we don't return fn(*args, **kwargs) in an else block here, this will break if someone is creating their own OPTIONS endpoint via someting like @app.route('/foo', methods=['GET', 'OPTIONS']). I doubt anyone is doing that, but because flask allows this to happen, I would rather get that fixed up anyways, just in case :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right! I didn't mean to indent also return fn(*args, **kwargs)!

raise UserClaimsVerificationError('User claims verification failed')
_load_user(jwt_data[config.identity_claim_key])
return fn(*args, **kwargs)
if request.method not in config.exempt_methods:
Copy link
Owner

Choose a reason for hiding this comment

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

Could we add this same logic to the other view decorators in this file as well, for completeness sake? I'm alright with having the unit tests be only for the @jwt_required decorator (unless you feel like adding unit tests for the other decorators as well, in which case 👍 👍)

Copy link
Contributor Author

@ludusrusso ludusrusso Feb 9, 2018

Choose a reason for hiding this comment

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

Yea! I'll add it also in fresh_jwt_required and jwt_refresh_token_required! I'm not sure if we need to implement it in jwt_optional, since it should works well!

I'll wrote more tests anyway :D

app.config['JWT_SECRET_KEY'] = 'secret'
JWTManager(app)

protected_bp = Blueprint('protected', __name__)
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think you need to check this with a blueprint here. Testing it with just an app should be sufficient and a bit cleaner to read.


def test_access_protected_enpoint_options(app):
client = app.test_client()
assert client.options('/protected').status_code == 200 # test fails
Copy link
Owner

Choose a reason for hiding this comment

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

Could we add one more test here for creating a custom OPTIONS endpiont, and verifying that the data returned is the returned value of that endpoint? Not likely that this is happening in real codebases, but I want to make sure we don't break flask functionality with this extension, and that is something flask allows you to do.


@property
def exempt_methods(self):
return set(["OPTIONS"])
Copy link
Owner

Choose a reason for hiding this comment

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

We don't need to support python2.6, so you could write this as the set literal (ex: {'foo'}) instead.

`jwt_refresh_token_required`, improve and add tests
@ludusrusso
Copy link
Contributor Author

Ok! I've improved the code according to the review!
I've also rewrite tests in order to only check the options ignoring feature, since protecting enpoints are already tested.

@vimalloc vimalloc merged commit c78d37a into vimalloc:master Feb 9, 2018
@vimalloc
Copy link
Owner

vimalloc commented Feb 9, 2018

Great, thanks! I'll get a new released pushed out with these changes later today 👍

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.

Disable jwt_required for OPTIONS requests

3 participants