Skip to content

Commit

Permalink
Add test to detect repository credentials get overwritten by .netrc
Browse files Browse the repository at this point in the history
  • Loading branch information
hugofvs committed Oct 7, 2024
1 parent 8a23986 commit 946aae7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/utils/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,35 @@ def test_authenticator_uses_env_provided_credentials(

request = http.last_request()

basic_auth = base64.b64encode(b"bar:baz").decode()

assert request.headers["Authorization"] == f"Basic {basic_auth}"


def test_authenticator_uses_env_provided_credentials_over_netrc(
config: Config,
repo: dict[str, dict[str, str]],
environ: None,
mock_remote: type[httpretty.httpretty],
http: type[httpretty.httpretty],
monkeypatch: MonkeyPatch,
tmp_path: Path
) -> None:
# Create .netrc file inside the temporary directory
temp_file = tmp_path / ".netrc"
temp_file.write_text("machine foo.bar\nlogin foor\npassword fooz")

monkeypatch.setenv("NETRC", str(temp_file))
monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_USERNAME", "bar")
monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_PASSWORD", "baz")

config.merge({"repositories": repo})

authenticator = Authenticator(config, NullIO())
authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz")

request = http.last_request()

basic_auth = base64.b64encode(b"bar:baz").decode()
assert request.headers["Authorization"] == f"Basic {basic_auth}"

Expand Down

0 comments on commit 946aae7

Please sign in to comment.