forked from pypi/warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve OIDC error messages (pypi#14308)
* Add more detailed OIDC errors * Update tests
- Loading branch information
Showing
11 changed files
with
118 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import pytest | ||
|
||
from tests.common.db.oidc import GooglePublisherFactory, PendingGooglePublisherFactory | ||
from warehouse.oidc import errors | ||
from warehouse.oidc.models import _core, google | ||
|
||
|
||
|
@@ -84,7 +85,9 @@ def test_google_publisher_unaccounted_claims(self, monkeypatch): | |
} | ||
signed_claims["fake-claim"] = "fake" | ||
signed_claims["another-fake-claim"] = "also-fake" | ||
assert not publisher.verify_claims(signed_claims=signed_claims) | ||
with pytest.raises(errors.InvalidPublisherError) as e: | ||
publisher.verify_claims(signed_claims=signed_claims) | ||
assert str(e.value) == "Check failed for required claim 'email'" | ||
assert sentry_sdk.capture_message.calls == [ | ||
pretend.call( | ||
"JWT for GooglePublisher has unaccounted claims: " | ||
|
@@ -118,7 +121,9 @@ def test_google_publisher_missing_claims(self, monkeypatch): | |
signed_claims.pop("email") | ||
assert "email" not in signed_claims | ||
assert publisher.__required_verifiable_claims__ | ||
assert not publisher.verify_claims(signed_claims=signed_claims) | ||
with pytest.raises(errors.InvalidPublisherError) as e: | ||
publisher.verify_claims(signed_claims=signed_claims) | ||
assert str(e.value) == "Missing claim 'email'" | ||
assert sentry_sdk.capture_message.calls == [ | ||
pretend.call("JWT for GooglePublisher is missing claim: email") | ||
] | ||
|
@@ -139,7 +144,13 @@ def test_google_publisher_email_verified(self, email_verified, valid): | |
"email": "[email protected]", | ||
"email_verified": email_verified, | ||
} | ||
assert publisher.verify_claims(signed_claims=signed_claims) is valid | ||
if valid: | ||
# Does not raise | ||
publisher.verify_claims(signed_claims=signed_claims) | ||
else: | ||
with pytest.raises(errors.InvalidPublisherError) as e: | ||
publisher.verify_claims(signed_claims=signed_claims) | ||
assert str(e.value) == "Check failed for required claim 'email_verified'" | ||
|
||
@pytest.mark.parametrize( | ||
("expected_sub", "actual_sub", "valid"), | ||
|
@@ -164,7 +175,13 @@ def test_google_publisher_sub_is_optional(self, expected_sub, actual_sub, valid) | |
"email": "[email protected]", | ||
"email_verified": True, | ||
} | ||
assert publisher.verify_claims(signed_claims=signed_claims) is valid | ||
if valid: | ||
# Does not raise | ||
publisher.verify_claims(signed_claims=signed_claims) | ||
else: | ||
with pytest.raises(errors.InvalidPublisherError) as e: | ||
publisher.verify_claims(signed_claims=signed_claims) | ||
assert str(e.value) == "Check failed for optional claim 'sub'" | ||
|
||
|
||
class TestPendingGooglePublisher: | ||
|
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
class InvalidPublisherError(Exception): | ||
pass |
This file contains 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 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 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
Oops, something went wrong.