Skip to content

Commit 688cae1

Browse files
committed
Fix credential stripping in the test
1 parent 1ebbccd commit 688cae1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/test_pip_repositories.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import os
3+
import re
34
import tarfile
45

56
from io import BytesIO
@@ -101,11 +102,14 @@ def _make_response(
101102
response.raw.write(file_handler.read())
102103
response.raw.seek(0)
103104

104-
url = urlparse(request.url)
105105
if fixture_request.param == "response_url_with_credentials":
106106
response.url = request.url
107107
else:
108-
response.url = request.url.replace(url.netloc, url.hostname)
108+
# Strip credentials using regex, preserving port if present:
109+
# ^([^:]+://) - Capture group 1: scheme (http:// or https://)
110+
# [^@]+@ - Match and remove credentials (anything up to @)
111+
# \1 - Replace with just the captured scheme
112+
response.url = re.sub(r"^([^:]+://)[^@]+@", r"\1", request.url)
109113
response.reason = reason
110114
return response
111115

0 commit comments

Comments
 (0)