-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move verification to its own function, and make the verification checks more exhaustive by parsing the URL and adding more test cases.
- Loading branch information
1 parent
a654664
commit 5065bbd
Showing
2 changed files
with
125 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3296,7 3296,7 @@ def test_upload_succeeds_creates_release( | |
@pytest.mark.parametrize( | ||
"url, expected", | ||
[ | ||
("https://xpto.com", False), # Totally different | ||
("https://google.com", False), # Totally different | ||
("https://github.com/foo", False), # Missing parts | ||
("https://github.com/foo/bar/", True), # Exactly the same | ||
("https://github.com/foo/bar/readme.md", True), # Additonal parts | ||
|
@@ -4168,3 4168,86 @@ def test_missing_trailing_slash_redirect(pyramid_request): | |
"/legacy/ (with a trailing slash)" | ||
) | ||
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, | ||
), | ||
( # Publisher URL is None | ||
"https://github.com/owner/project", | ||
None, | ||
False, | ||
), | ||
], | ||
) | ||
def test_verify_url(url, publisher_url, expected): | ||
assert legacy._verify_url(url, publisher_url) == expected |
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