-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Verify github.io URLs with Trusted Publishing #16499
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4799,84 +4799,6 @@ def test_missing_trailing_slash_redirect(pyramid_request): | |
assert resp.headers["Location"] == "/legacy/" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("url", "publisher_url", "expected"), | ||
[ | ||
( # GitHub trivial case | ||
"https://github.com/owner/project", | ||
"https://github.com/owner/project", | ||
True, | ||
), | ||
( # ActiveState trivial case | ||
"https://platform.activestate.com/owner/project", | ||
"https://platform.activestate.com/owner/project", | ||
True, | ||
), | ||
( # GitLab trivial case | ||
"https://gitlab.com/owner/project", | ||
"https://gitlab.com/owner/project", | ||
True, | ||
), | ||
( # URL is a sub-path of the TP URL | ||
"https://github.com/owner/project/issues", | ||
"https://github.com/owner/project", | ||
True, | ||
), | ||
( # Normalization | ||
"https://GiThUB.com/owner/project/", | ||
"https://github.com/owner/project", | ||
True, | ||
), | ||
( # TP URL is a prefix, but not a parent of the URL | ||
"https://github.com/owner/project22", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # URL is a parent of the TP URL | ||
"https://github.com/owner", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # Scheme component does not match | ||
"http://github.com/owner/project", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # Host component does not match | ||
"https://gitlab.com/owner/project", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # Host component matches, but contains user and port info | ||
"https://[email protected]:443/owner/project", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # URL path component is empty | ||
"https://github.com", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # TP URL path component is empty | ||
# (currently no TPs have an empty path, so even if the given URL is a | ||
# sub-path of the TP URL, we fail the verification) | ||
"https://github.com/owner/project", | ||
"https://github.com", | ||
False, | ||
), | ||
( # Both path components are empty | ||
# (currently no TPs have an empty path, so even if the given URL is the | ||
# same as the TP URL, we fail the verification) | ||
"https://github.com", | ||
"https://github.com", | ||
False, | ||
), | ||
], | ||
) | ||
def test_verify_url_with_trusted_publisher(url, publisher_url, expected): | ||
assert legacy._verify_url_with_trusted_publisher(url, publisher_url) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("url", "project_name", "project_normalized_name", "expected"), | ||
[ | ||
|
@@ -4992,24 +4914,27 @@ def test_verify_url_pypi(url, project_name, project_normalized_name, expected): | |
|
||
def test_verify_url(): | ||
# `_verify_url` is just a helper function that calls `_verify_url_pypi` and | ||
# `_verify_url_with_trusted_publisher`, where the actual verification logic lives. | ||
# `OIDCPublisher.verify_url`, where the actual verification logic lives. | ||
publisher_verifies = pretend.stub(verify_url=lambda url: True) | ||
publisher_fails = pretend.stub(verify_url=lambda url: False) | ||
|
||
assert legacy._verify_url( | ||
url="https://pypi.org/project/myproject/", | ||
publisher_url=None, | ||
publisher=None, | ||
project_name="myproject", | ||
project_normalized_name="myproject", | ||
) | ||
|
||
assert legacy._verify_url( | ||
url="https://github.com/org/myproject/issues", | ||
publisher_url="https://github.com/org/myproject", | ||
publisher=publisher_verifies, | ||
project_name="myproject", | ||
project_normalized_name="myproject", | ||
) | ||
|
||
assert not legacy._verify_url( | ||
url="example.com", | ||
publisher_url="https://github.com/or/myproject", | ||
publisher=publisher_fails, | ||
project_name="myproject", | ||
project_normalized_name="myproject", | ||
) |
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 |
---|---|---|
|
@@ -54,6 +54,89 @@ def test_oidc_publisher_not_default_verifiable(self): | |
publisher.verify_claims(signed_claims={}, publisher_service=pretend.stub()) | ||
assert str(e.value) == "No required verifiable claims" | ||
|
||
@pytest.mark.parametrize( | ||
("url", "publisher_url", "expected"), | ||
[ | ||
( # GitHub trivial case | ||
"https://github.com/owner/project", | ||
"https://github.com/owner/project", | ||
True, | ||
), | ||
( # ActiveState trivial case | ||
"https://platform.activestate.com/owner/project", | ||
"https://platform.activestate.com/owner/project", | ||
True, | ||
), | ||
( # GitLab trivial case | ||
"https://gitlab.com/owner/project", | ||
"https://gitlab.com/owner/project", | ||
True, | ||
), | ||
( # URL is a sub-path of the TP URL | ||
"https://github.com/owner/project/issues", | ||
"https://github.com/owner/project", | ||
True, | ||
), | ||
( # Normalization | ||
"https://GiThUB.com/owner/project/", | ||
"https://github.com/owner/project", | ||
True, | ||
), | ||
( # TP URL is a prefix, but not a parent of the URL | ||
"https://github.com/owner/project22", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # URL is a parent of the TP URL | ||
"https://github.com/owner", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # Scheme component does not match | ||
"http://github.com/owner/project", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # Host component does not match | ||
"https://gitlab.com/owner/project", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # Host component matches, but contains user and port info | ||
"https://[email protected]:443/owner/project", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # URL path component is empty | ||
"https://github.com", | ||
"https://github.com/owner/project", | ||
False, | ||
), | ||
( # TP URL path component is empty | ||
# (currently no TPs have an empty path, so even if the given URL is a | ||
# sub-path of the TP URL, we fail the verification) | ||
"https://github.com/owner/project", | ||
"https://github.com", | ||
False, | ||
), | ||
( # Both path components are empty | ||
# (currently no TPs have an empty path, so even if the given URL is the | ||
# same as the TP URL, we fail the verification) | ||
"https://github.com", | ||
"https://github.com", | ||
False, | ||
), | ||
], | ||
) | ||
def test_verify_url(self, monkeypatch, url, publisher_url, expected): | ||
class ConcretePublisher(_core.OIDCPublisher): | ||
@property | ||
def publisher_base_url(self): | ||
return publisher_url | ||
|
||
publisher = ConcretePublisher() | ||
assert publisher.verify_url(url) == expected | ||
|
||
|
||
def test_check_existing_jti(): | ||
publisher = pretend.stub( | ||
|
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
Oops, something went wrong.
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.