Skip to content

Commit

Permalink
chore: strip any basic auth information before matching
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Aug 12, 2023
1 parent 41dfeea commit acc6840
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/trestlebot/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
[
"https://gitlab.com/owner/repo",
"https://gitlab.com/owner/repo.git",
"https://test:[email protected]/owner/repo.git",
"gitlab.com/owner/repo.git",
],
)
Expand Down
7 changes: 5 additions & 2 deletions trestlebot/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ def parse_repository(self, repo_url: str) -> Tuple[str, str]:
Owner and project name in a tuple, respectively
"""

match = re.match(self.pattern, repo_url)
# Strip out any basic auth
stripped_url = re.sub(r"https?://.*?@", "https://", repo_url)

match = re.match(self.pattern, stripped_url)

if not match:
raise GitProviderException(f"{repo_url} is an invalid repo URL")
raise GitProviderException(f"{stripped_url} is an invalid repo URL")

owner = match.group(1)[1:] # Removing the leading slash
repo = match.group(2)
Expand Down

0 comments on commit acc6840

Please sign in to comment.