Skip to content

Commit 0191f0c

Browse files
committed
Preserve ports when munging repository URLs
When repository URLs were altered to remove user information, we did not preserve the port. This fixes that by using the better library for munging the URL and adds tests to ensure no regression. Closes #1111
1 parent c588793 commit 0191f0c

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Fix bug for Repository URLs with auth where the port was lost. When attempting
3+
to prevent printing authentication credentials in URLs provided with username
4+
and password, we did not properly handle the case where the URL also contains
5+
a port (when reconstructing the URL). This is now handled and tested to ensure
6+
no regressions.

tests/test_utils.py

+32-9
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,38 @@ def test_get_repository_config_missing(config_file):
150150
assert utils.get_repository_from_config(config_file, "pypi") == exp
151151

152152

153-
def test_get_repository_config_url_with_auth(config_file):
154-
repository_url = "https://user:[email protected]/pypi"
155-
exp = {
156-
"repository": "https://notexisting.python.org/pypi",
157-
"username": "user",
158-
"password": "pass",
159-
}
160-
assert utils.get_repository_from_config(config_file, "foo", repository_url) == exp
161-
assert utils.get_repository_from_config(config_file, "pypi", repository_url) == exp
153+
@pytest.mark.parametrize(
154+
"repository_url, expected_config",
155+
[
156+
(
157+
"https://user:[email protected]/pypi",
158+
{
159+
"repository": "https://notexisting.python.org/pypi",
160+
"username": "user",
161+
"password": "pass",
162+
},
163+
),
164+
(
165+
"https://auser:[email protected]:8443",
166+
{
167+
"repository": "https://pypi.proxy.local.repo.net:8443",
168+
"username": "auser",
169+
"password": "pass",
170+
},
171+
),
172+
],
173+
)
174+
def test_get_repository_config_url_with_auth(
175+
config_file, repository_url, expected_config
176+
):
177+
assert (
178+
utils.get_repository_from_config(config_file, "foo", repository_url)
179+
== expected_config
180+
)
181+
assert (
182+
utils.get_repository_from_config(config_file, "pypi", repository_url)
183+
== expected_config
184+
)
162185

163186

164187
@pytest.mark.parametrize(

tox.ini

+11
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,22 @@ commands =
9595

9696
[testenv:changelog]
9797
basepython = python3
98+
skip_install = True
9899
deps =
99100
towncrier
100101
commands =
101102
towncrier build {posargs}
102103

104+
105+
# Usage:
106+
# tox -e create-changelog-item -- [additional arguments] {filename}.{bugfix,feature,doc,removal,misc}
107+
[testenv:create-changelog-item]
108+
basepython = python3
109+
skip_install = True
110+
deps = towncrier
111+
commands =
112+
towncrier create --config pyproject.toml {posargs}
113+
103114
[testenv:release]
104115
# specify Python 3 to use platform's default Python 3
105116
basepython = python3

twine/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def _config_from_repository_url(url: str) -> RepositoryConfig:
174174
if parsed.username:
175175
config["username"] = parsed.username
176176
config["password"] = parsed.password
177-
config["repository"] = urlunparse((parsed.scheme, parsed.hostname) + parsed[2:])
177+
config["repository"] = cast(
178+
str, rfc3986.urlparse(url).copy_with(userinfo=None).unsplit()
179+
)
178180
config["repository"] = normalize_repository_url(cast(str, config["repository"]))
179181
return config
180182

0 commit comments

Comments
 (0)