Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
joegasewicz committed Dec 14, 2020
2 parents 96ab83d + f52c88a commit 5323c9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 1 addition & 5 deletions flask_jwt_router/_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def _handle_token(self):
Checks to see that the route is white listed.
:return None:
"""
self.entity.clean_up()
try:
if request.args.get("auth"):
token = request.args.get("auth")
Expand All @@ -183,13 +184,10 @@ def _handle_token(self):
)
setattr(g, self.entity.get_entity_from_ext().__tablename__, entity)
setattr(g, "access_token", token)
self.entity.clean_up()
return None
except InvalidTokenError:
self.entity.clean_up()
return abort(401)
except AttributeError:
self.entity.clean_up()
return abort(401)
else:
# Sometimes a developer may define the auth field name as Bearer or Basic
Expand All @@ -214,8 +212,6 @@ def _handle_token(self):
self.entity_key = self.config.entity_key
entity = self.entity.get_entity_from_token_or_tablename(decoded_token)
setattr(g, self.entity.get_entity_from_ext().__tablename__, entity)
self.entity.clean_up()
return None
except ValueError:
self.entity.clean_up()
return abort(401)
22 changes: 14 additions & 8 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,44 @@ def fc_one():
with ctx:
# token from args
monkeypatch.setattr("flask.request.args", MockArgs(mock_token))
routing.before_middleware()
assert ctx.g.test_entities == [(1, 'joe')]
entity.clean_up()
assert routing.entity.entity_key == None
assert routing.entity.tablename == None
routing.before_middleware()
assert ctx.g.test_entities == [(1, 'joe')]

entity.clean_up()
with ctx:
# token from OAuth headers - X-Auth-Token
monkeypatch.setattr("flask.request.args", MockArgs())
monkeypatch.setattr("flask.request.headers", MockArgs(mock_token, True))
routing.before_middleware()
assert ctx.g.test_entities == [(1, 'joe')]
assert routing.entity.entity_key == None
entity.clean_up()
assert routing.entity.oauth_entity_key == None
assert routing.entity.tablename == None
routing.before_middleware()
assert ctx.g.test_entities == [(1, 'joe')]


with ctx:
# token from oauth headers
monkeypatch.setattr("flask.request.headers", MockArgs("<access_token>", "X-Auth-Token"))
routing.before_middleware()
assert ctx.g.oauth_tablename == [(1, "jaco@gmail.com")]
entity.clean_up()
assert routing.entity.entity_key == None
assert routing.entity.oauth_entity_key == None
assert routing.entity.tablename == None
routing.before_middleware()
assert ctx.g.oauth_tablename == [(1, "jaco@gmail.com")]


# Fixes bug - "entity key state gets stale between requests #171"
# https://github.com/joegasewicz/flask-jwt-router/issues/171
with ctx:
monkeypatch.setattr("flask.request.headers", MockArgs("<after_token>", "Authorization"))
routing.before_middleware()
entity.clean_up()
assert routing.entity.entity_key == None
assert routing.entity.oauth_entity_key == None
assert routing.entity.tablename == None
routing.before_middleware()

@pytest.mark.parametrize(
"jwt_router_client,entity_model,expected", [
Expand Down

0 comments on commit 5323c9b

Please sign in to comment.