Skip to content

Commit

Permalink
Fix URL verification for GitHub/GitLab (pypi#17154)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkaMaul authored Nov 22, 2024
1 parent b837b1d commit 5845366
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
22 changes: 19 additions & 3 deletions tests/unit/oidc/models/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,20 @@ def test_github_publisher_duplicates_cant_be_created(self, db_request):
with pytest.raises(sqlalchemy.exc.IntegrityError):
db_request.db.commit()

@pytest.mark.parametrize(
"repository_name",
[
"repository_name",
"Repository_Name",
],
)
@pytest.mark.parametrize(
"repository_owner",
[
"repository_owner",
"Repository_Owner",
],
)
@pytest.mark.parametrize(
("url", "expected"),
[
Expand All @@ -640,10 +654,12 @@ def test_github_publisher_duplicates_cant_be_created(self, db_request):
("https://repository_owner.github.io/RePoSiToRy_NaMe/subpage", True),
],
)
def test_github_publisher_verify_url(self, url, expected):
def test_github_publisher_verify_url(
self, url, expected, repository_name, repository_owner
):
publisher = github.GitHubPublisher(
repository_name="repository_name",
repository_owner="repository_owner",
repository_name=repository_name,
repository_owner=repository_owner,
repository_owner_id="666",
workflow_filename="workflow_filename.yml",
environment="",
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/oidc/models/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,18 @@ def test_gitlab_publisher_duplicates_cant_be_created(self, db_request):
f"https://gitlab.com/{NAMESPACE}/{PROJECT_NAME}.git",
True,
),
(
"Project_Name",
NAMESPACE,
f"https://gitlab.com/{NAMESPACE}/{PROJECT_NAME}.git",
True,
),
(
PROJECT_NAME,
"Project_Owner",
f"https://gitlab.com/{NAMESPACE}/{PROJECT_NAME}.git",
True,
),
(
PROJECT_NAME,
NAMESPACE,
Expand Down
5 changes: 4 additions & 1 deletion warehouse/oidc/models/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ def verify_url(self, url: str):
break

url_for_generic_check = url.removesuffix("/").removesuffix(".git")
if super().verify_url(url_for_generic_check):
if verify_url_from_reference(
reference_url=self.publisher_base_url.lower(),
url=url_for_generic_check,
):
return True

return verify_url_from_reference(reference_url=docs_url, url=url)
Expand Down
4 changes: 3 additions & 1 deletion warehouse/oidc/models/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ def verify_url(self, url: str):
url = lowercase_base_url + url[len(lowercase_base_url) :]

url_for_generic_check = url.removesuffix("/").removesuffix(".git")
if super().verify_url(url_for_generic_check):
if verify_url_from_reference(
reference_url=lowercase_base_url, url=url_for_generic_check
):
return True

try:
Expand Down

0 comments on commit 5845366

Please sign in to comment.