Skip to content

Commit

Permalink
Add test for unauthorized audience
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwang committed Nov 3, 2023
1 parent b2ce2e6 commit 79c0c67
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/galaxy/authnz/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,11 @@ def find_user_by_access_token_in_provider(self, sa_session, provider, access_tok
return user
return None
except Exception as e:
msg = f"An error occurred when finding user by token: {e}"
msg = f"An error occurred with provider: {provider} when finding user by token: {e}"
log.error(msg)
return None

def find_user_by_access_token(self, sa_session, access_token):
# decoded_token = jwt.decode(access_token, options={"verify_signature": False})
# issuer = decoded_token["iss"]
# audience = decoded_token["aud"]
for provider in self.oidc_backends_config:
user = self.find_user_by_access_token_in_provider(sa_session, provider, access_token)
if user:
Expand Down
7 changes: 7 additions & 0 deletions test/integration/oidc/test_auth_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ def test_auth_with_another_authorized_client(self):
access_token = self._get_keycloak_access_token(client_id="bpaclient", scopes=["gx:*"])
response = self._get("users/current", headers={"Authorization": f"Bearer {access_token}"})
self._assert_status_code_is(response, 200)
assert response.json()["email"] == "[email protected]"

def test_auth_with_authorized_client_but_unauthorized_audience(self):
_, response = self._login_via_keycloak("bpaonlyuser", KEYCLOAK_TEST_PASSWORD)
access_token = self._get_keycloak_access_token(client_id="bpaclient", username="bpaonlyuser")
response = self._get("users/current", headers={"Authorization": f"Bearer {access_token}"})
self._assert_status_code_is(response, 400)

def test_auth_with_unauthorized_client(self):
_, response = self._login_via_keycloak(KEYCLOAK_TEST_USERNAME, KEYCLOAK_TEST_PASSWORD)
Expand Down

0 comments on commit 79c0c67

Please sign in to comment.