-
Notifications
You must be signed in to change notification settings - Fork 75
feat:(oidc) derive audience claim from client_id in IdentityToken #1402
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
436b09d
feat:(oidc) derive audience claim from client_id in IdentityToken
SequeI 6d7e867
fixing lint errors
SequeI 6894d43
Merge branch 'main' into audClaim
SequeI 0c80a9e
code review changes
SequeI e83b2dd
fixes
SequeI dabac66
changelog
SequeI 68bc344
fix
SequeI 3dd91f1
removing unneeded tests
SequeI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,13 +18,15 @@ | |
|
|
||
| from sigstore import oidc | ||
|
|
||
| TEST_CLIENT_ID = "sigstore" | ||
|
||
|
|
||
|
|
||
| class TestIdentityToken: | ||
| def test_invalid_jwt(self): | ||
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken("invalid jwt") | ||
| oidc.IdentityToken("invalid jwt", TEST_CLIENT_ID) | ||
|
|
||
| def test_missing_iss(self, dummy_jwt): | ||
| now = int(datetime.datetime.now().timestamp()) | ||
|
|
@@ -41,7 +43,7 @@ def test_missing_iss(self, dummy_jwt): | |
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| def test_missing_aud(self, dummy_jwt): | ||
| now = int(datetime.datetime.now().timestamp()) | ||
|
|
@@ -58,7 +60,7 @@ def test_missing_aud(self, dummy_jwt): | |
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| @pytest.mark.parametrize("aud", (None, "not-sigstore")) | ||
| def test_invalid_aud(self, dummy_jwt, aud): | ||
|
|
@@ -77,7 +79,7 @@ def test_invalid_aud(self, dummy_jwt, aud): | |
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| def test_missing_iat(self, dummy_jwt): | ||
| now = int(datetime.datetime.now().timestamp()) | ||
|
|
@@ -94,7 +96,7 @@ def test_missing_iat(self, dummy_jwt): | |
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| @pytest.mark.parametrize("iat", (None, "not-an-int")) | ||
| def test_invalid_iat(self, dummy_jwt, iat): | ||
|
|
@@ -113,7 +115,7 @@ def test_invalid_iat(self, dummy_jwt, iat): | |
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| def test_missing_nbf_ok(self, dummy_jwt): | ||
| now = int(datetime.datetime.now().timestamp()) | ||
|
|
@@ -127,7 +129,7 @@ def test_missing_nbf_ok(self, dummy_jwt): | |
| } | ||
| ) | ||
|
|
||
| assert oidc.IdentityToken(jwt) is not None | ||
| assert oidc.IdentityToken(jwt, TEST_CLIENT_ID) is not None | ||
|
|
||
| def test_invalid_nbf(self, dummy_jwt): | ||
| now = int(datetime.datetime.now().timestamp()) | ||
|
|
@@ -146,7 +148,7 @@ def test_invalid_nbf(self, dummy_jwt): | |
| oidc.IdentityError, | ||
| match="Identity token is not within its validity period", | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| def test_missing_exp(self, dummy_jwt): | ||
| now = int(datetime.datetime.now().timestamp()) | ||
|
|
@@ -163,7 +165,7 @@ def test_missing_exp(self, dummy_jwt): | |
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| def test_invalid_exp(self, dummy_jwt): | ||
| now = int(datetime.datetime.now().timestamp()) | ||
|
|
@@ -182,7 +184,7 @@ def test_invalid_exp(self, dummy_jwt): | |
| with pytest.raises( | ||
| oidc.IdentityError, match="Identity token is malformed or missing claims" | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "iss", [k for k, v in oidc._KNOWN_OIDC_ISSUERS.items() if v != "sub"] | ||
|
|
@@ -204,7 +206,7 @@ def test_missing_identity_claim(self, dummy_jwt, iss): | |
| oidc.IdentityError, | ||
| match=r"Identity token is missing the required '.+' claim", | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| @pytest.mark.parametrize("fed", ("notadict", {"connector_id": 123})) | ||
| def test_invalid_federated_claims(self, dummy_jwt, fed): | ||
|
|
@@ -226,7 +228,7 @@ def test_invalid_federated_claims(self, dummy_jwt, fed): | |
| oidc.IdentityError, | ||
| match="unexpected claim type: federated_claims.*", | ||
| ): | ||
| oidc.IdentityToken(jwt) | ||
| oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| ("iss", "identity_claim", "identity_value", "fed_iss"), | ||
|
|
@@ -263,7 +265,7 @@ def test_ok(self, dummy_jwt, iss, identity_claim, identity_value, fed_iss): | |
| } | ||
| ) | ||
|
|
||
| identity = oidc.IdentityToken(jwt) | ||
| identity = oidc.IdentityToken(jwt, TEST_CLIENT_ID) | ||
| assert identity.in_validity_period() | ||
| assert identity.identity == identity_value | ||
| assert identity.issuer == iss | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.