Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Prioritize url credentials over netrc" #11134

Merged
merged 2 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/10979.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Revert `#10979 <https://github.com/pypa/pip/issues/10979>`_ since it introduced a regression in certain edge cases.
5 changes: 2 additions & 3 deletions src/pip/_internal/network/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def _get_index_url(self, url: str) -> Optional[str]:
def _get_new_credentials(
self,
original_url: str,
*,
allow_netrc: bool = False,
allow_netrc: bool = True,
allow_keyring: bool = False,
) -> AuthInfo:
"""Find and return credentials for the specified URL."""
Expand Down Expand Up @@ -261,7 +260,7 @@ def handle_401(self, resp: Response, **kwargs: Any) -> Response:
# Query the keyring for credentials:
username, password = self._get_new_credentials(
resp.url,
allow_netrc=True,
allow_netrc=False,
allow_keyring=True,
)

Expand Down
43 changes: 0 additions & 43 deletions tests/functional/test_install_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,46 +415,3 @@ def get_credential(url, username):
assert "get_credential was called" in result.stderr
else:
assert "get_credential was called" not in result.stderr


def test_prioritize_url_credentials_over_netrc(
script: PipTestEnvironment,
data: TestData,
cert_factory: CertFactory,
) -> None:
cert_path = cert_factory()
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.load_cert_chain(cert_path, cert_path)
ctx.load_verify_locations(cafile=cert_path)
ctx.verify_mode = ssl.CERT_REQUIRED

server = make_mock_server(ssl_context=ctx)
server.mock.side_effect = [
package_page(
{
"simple-3.0.tar.gz": "/files/simple-3.0.tar.gz",
}
),
authorization_response(str(data.packages / "simple-3.0.tar.gz")),
]

url = f"https://USERNAME:PASSWORD@{server.host}:{server.port}/simple"

netrc = script.scratch_path / ".netrc"
netrc.write_text(
f"machine {server.host} login wrongusername password wrongpassword"
)
with server_running(server):
script.environ["NETRC"] = netrc
script.pip(
"install",
"--no-cache-dir",
"--index-url",
url,
"--cert",
cert_path,
"--client-cert",
cert_path,
"simple",
)
script.assert_installed(simple="3.0")