Skip to content

Commit

Permalink
Merge pull request #20 from edx/iahmad/ENT-1836-Fix-implicit-check-fo…
Browse files Browse the repository at this point in the history
…r-absent-JWT

ENT-1836 Check for JWT presence in implicit permission
  • Loading branch information
irfanuddinahmad authored Apr 30, 2019
2 parents d84c030 + 43c5f4a commit f8472ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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

0 comments on commit f8472ed

Please sign in to comment.