Skip to content

Commit

Permalink
Fix GitLab Trusted Publisher not accepting valid namespaces (#15839)
Browse files Browse the repository at this point in the history
Namespaces can have forward slash ("/") characters, since a repo
inside a subgroup will have a namespace where the subgroups are
delimited using slashes (e.g: `gitlab.com/group/subgroup/repo` has
a namespace of `group/subgroup`).
  • Loading branch information
facutuesca committed Apr 23, 2024
1 parent c2b207d commit 1036b14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions tests/unit/oidc/forms/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ def test_validate_project_name_already_in_use(self):


class TestGitLabPublisherForm:
def test_validate(self):
data = MultiDict(
@pytest.mark.parametrize(
"data",
[
{
"namespace": "some-owner",
"project": "some-repo",
"workflow_filepath": "subfolder/some-workflow.yml",
}
)
},
{
"namespace": "some-group/some-subgroup",
"project": "some-repo",
"workflow_filepath": "subfolder/some-workflow.yml",
},
],
)
def test_validate(self, data):
form = gitlab.GitLabPublisherForm(MultiDict(data))

# We're testing only the basic validation here.
Expand All @@ -76,6 +84,11 @@ def test_validate(self):
"project": "some",
"workflow_filepath": "some",
},
{
"namespace": "/start_with_slash",
"project": "some",
"workflow_filepath": "some",
},
{
"namespace": "some",
"project": "invalid space",
Expand Down
2 changes: 1 addition & 1 deletion warehouse/oidc/forms/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# https://docs.gitlab.com/ee/user/reserved_names.html#limitations-on-project-and-group-names
_VALID_GITLAB_PROJECT = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9-_.]*$")
_VALID_GITLAB_NAMESPACE = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9-_.]*$")
_VALID_GITLAB_NAMESPACE = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9-_./]*$")
_VALID_GITLAB_ENVIRONMENT = re.compile(r"^[a-zA-Z0-9\-_/${} ]+$")


Expand Down

0 comments on commit 1036b14

Please sign in to comment.