Skip to content

Commit ed1fd3e

Browse files
authored
Normalize both sides of case-insensitive fields for GitLab publisher lookup query (#18905)
* Add a failing test * Normalize both sides of the query
1 parent f6aff4d commit ed1fd3e

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

tests/unit/oidc/models/test_gitlab.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,36 @@ def test_lookup_fails_invalid_ci_config_ref_uri(self, environment):
7373
):
7474
gitlab.GitLabPublisher.lookup_by_claims(pretend.stub(), signed_claims)
7575

76-
def test_lookup_succeeds_with_mixed_case_project_path(self, db_request):
76+
@pytest.mark.parametrize(
77+
("configured_namespace", "configured_project", "project_path"),
78+
[
79+
(
80+
"Foo",
81+
"Bar",
82+
"foo/bar",
83+
),
84+
(
85+
"foo",
86+
"bar",
87+
"Foo/Bar",
88+
),
89+
],
90+
)
91+
def test_lookup_succeeds_with_mixed_case_project_path(
92+
self, db_request, configured_namespace, configured_project, project_path
93+
):
7794
# Test that we find a matching publisher when the project_path claims match
7895
# even if the case is different.
7996
stored_publisher = GitLabPublisherFactory(
80-
namespace="Foo",
81-
project="Bar",
97+
namespace=configured_namespace,
98+
project=configured_project,
8299
workflow_filepath=".gitlab-ci.yml",
83100
environment="",
84101
)
85102

86103
signed_claims = {
87-
"project_path": "foo/bar", # different case than stored publisher
88-
"ci_config_ref_uri": ("gitlab.com/foo/bar//.gitlab-ci.yml@refs/heads/main"),
104+
"project_path": project_path,
105+
"ci_config_ref_uri": "gitlab.com/foo/bar//.gitlab-ci.yml@refs/heads/main",
89106
"environment": "some_environment",
90107
}
91108

warehouse/oidc/models/gitlab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def lookup_by_claims(cls, session: Session, signed_claims: SignedClaims) -> Self
246246

247247
query: Query = Query(cls).filter(
248248
# claims `project_path` is case-insensitive
249-
func.lower(cls.namespace) == namespace,
250-
func.lower(cls.project) == project,
249+
func.lower(cls.namespace) == func.lower(namespace),
250+
func.lower(cls.project) == func.lower(project),
251251
cls.workflow_filepath == workflow_filepath,
252252
)
253253
publishers = query.with_session(session).all()

0 commit comments

Comments
 (0)