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

ENT-1836 Check for JWT presence in implicit permission #20

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Change Log

.. There should always be an "Unreleased" section for changes pending release.

[0.2.0] - 2019-04-30
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Check for JWT presence in implicit permission.
* Refactor role retrieval to remove the dependency on django models for assigning roles.

[0.1.11] - 2019-04-08
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions edx_rbac/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def request_user_has_implicit_access_via_jwt(decoded_jwt, role_name, context=Non
'coupon-manager': ['coupon-management']
}
"""
if not decoded_jwt:
return False
jwt_roles_claim = decoded_jwt.get('roles', [])

feature_roles = {}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ def test_request_user_has_no_implicit_access_via_jwt(self):
'superuser-access',
)

def test_request_user_has_no_implicit_access_when_jwt_absent(self):
"""
Helper function should return False when JWT is absent
"""
toy_decoded_jwt = None
assert not request_user_has_implicit_access_via_jwt(
toy_decoded_jwt,
'superuser-access',
)

def test_request_user_has_implicit_access_via_jwt_with_context(self):
"""
Helper function should discern what roles user has based on role data
Expand Down