Skip to content

Commit 09d5343

Browse files
authored
oidc/gitlab: make project path comparison case insensitive (#15512)
1 parent f87e97d commit 09d5343

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

tests/unit/oidc/models/test_gitlab.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,32 @@ def test_gitlab_publisher_verifies(self, monkeypatch, environment, missing_claim
238238
optional_verifiable_claims
239239
)
240240

241+
@pytest.mark.parametrize(
242+
("truth", "claim", "valid"),
243+
[
244+
# invalid: claim should never be empty or missing
245+
("", None, False),
246+
("foo/bar", None, False),
247+
("", "", False),
248+
("foo/bar", "", False),
249+
# valid: exact and case-insensitive matches
250+
("foo/bar", "foo/bar", True),
251+
("Foo/bar", "foo/bar", True),
252+
("Foo/bar", "Foo/bar", True),
253+
("foo/bar", "Foo/bar", True),
254+
("FOO/bar", "foo/bar", True),
255+
("foo/bar", "FOO/bar", True),
256+
("foo/Bar", "foo/bar", True),
257+
("foo/Bar", "Foo/Bar", True),
258+
("foo/bar", "foo/Bar", True),
259+
("foo/BAR", "foo/bar", True),
260+
("foo/bar", "foo/BAR", True),
261+
],
262+
)
263+
def test_check_project_path(self, truth, claim, valid):
264+
check = gitlab.GitLabPublisher.__required_verifiable_claims__["project_path"]
265+
assert check(truth, claim, pretend.stub()) == valid
266+
241267
@pytest.mark.parametrize(
242268
("claim", "ref_path", "sha", "valid", "expected"),
243269
[

warehouse/oidc/models/gitlab.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@
2323
CheckClaimCallable,
2424
OIDCPublisher,
2525
PendingOIDCPublisher,
26-
check_claim_binary,
2726
)
2827

2928

29+
def _check_project_path(ground_truth, signed_claim, all_signed_claims):
30+
# Defensive: GitLab should never give us an empty project_path claim.
31+
if not signed_claim:
32+
return False
33+
34+
# GitLab project paths are case-insensitive.
35+
return signed_claim.lower() == ground_truth.lower()
36+
37+
3038
def _check_ci_config_ref_uri(ground_truth, signed_claim, all_signed_claims):
3139
# We expect a string formatted as follows:
3240
# gitlab.com/OWNER/REPO//WORKFLOW_PATH/WORKFLOW_FILE.yml@REF
@@ -108,7 +116,7 @@ class GitLabPublisherMixin:
108116

109117
__required_verifiable_claims__: dict[str, CheckClaimCallable[Any]] = {
110118
"sub": _check_sub,
111-
"project_path": check_claim_binary(str.__eq__),
119+
"project_path": _check_project_path,
112120
"ci_config_ref_uri": _check_ci_config_ref_uri,
113121
}
114122

0 commit comments

Comments
 (0)