smolnar82 commented on code in PR #1407:
URL: https://github.com/apache/knox/pull/1407#discussion_r4035030926
##########
.github/workflows/tests/test_token_exchange.py:
##########
@@ -210,6 +276,83 @@ def
test_same_subject_exchange_succeeds_on_delegation_enabled_topology(self):
self.assertEqual(body.get("issued_token_type"), ISSUED_TOKEN_TYPE_JWT,
response.text)
self.assertEqual(get_token_claim(body["access_token"], "sub"),
GUEST_USER)
+ # ---- KNOX-3466: same-subject requested-audience authorization (KNOX-3461
code) ----
+ # These exercise delegation.same.subject.requested.audience.enabled and
therefore fail
+ # until the KNOX-3461 gateway code is present in the image.
+
+ def test_same_subject_requested_audience_authorized_succeeds(self):
+ """Flag on: a requested audience the subject token already carries is
honored and minted."""
+ subject_token = self._mint_subject_token_with_aud()
+ # Precondition: the subject token actually carries the audience we
will request.
+ self.assertIn(SUBJECT_AUDIENCE, self._aud_values(subject_token),
+ "precondition: subject token must carry the requested
audience in its aud")
+
+ response = self._exchange(
+ self.same_subject_aud_exchange_url, subject_token,
resources=[SUBJECT_AUDIENCE],
+ )
+ self.assertEqual(response.status_code, 200, response.text)
+ exchanged = response.json().get("access_token")
+ self.assertTrue(exchanged, "exchange did not return an access_token")
+ self.assertEqual(get_token_claim(exchanged, "sub"), GUEST_USER)
+ # The authorized audience is passed through onto the exchanged token.
+ self.assertIn(SUBJECT_AUDIENCE, self._aud_values(exchanged),
+ "authorized requested audience must appear on the
exchanged token")
+
+ def test_same_subject_requested_audience_unauthorized_rejected(self):
+ """Flag on: a requested audience the subject token does not carry is
rejected."""
+ subject_token = self._mint_subject_token_with_aud()
+ self.assertNotIn(UNAUTHORIZED_AUDIENCE,
self._aud_values(subject_token),
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]