Skip to content

Commit 1c61afe

Browse files
dimblebyCopilotradoering
authored
fix: respect verify=False in authenticator requests (#10803)
kwargs.get("verify") or certs.cert evaluated False as falsy, silently overriding an explicit verify=False with configured certificates. Use a None check to distinguish "not passed" from "explicitly False". Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
1 parent e6f1ded commit 1c61afe

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/poetry/utils/authenticator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ def request(
206206
stream: bool | None = kwargs.get("stream")
207207

208208
certs = self.get_certs_for_url(url)
209-
verify: bool | str | Path = kwargs.get("verify") or certs.cert or certs.verify
209+
verify: bool | str | Path | None = kwargs.get("verify")
210+
if verify is None:
211+
verify = certs.cert or certs.verify
210212
cert: str | Path | None = kwargs.get("cert") or certs.client_cert
211213

212214
if cert is not None:

tests/utils/test_authenticator.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,37 @@ def test_authenticator_uses_certs_from_config_if_not_provided(
422422
assert Path(kwargs["cert"]) == Path(client_cert or configured_client_cert)
423423

424424

425+
@pytest.mark.parametrize("verify", [True, False, None])
426+
def test_authenticator_request_verify_is_respected(
427+
config: Config,
428+
mock_remote: responses.RequestsMock,
429+
mock_config: Config,
430+
http: responses.RequestsMock,
431+
mocker: MockerFixture,
432+
verify: bool | None,
433+
) -> None:
434+
"""especially verify=False must not be overridden by configured certificates."""
435+
mock_config.merge(
436+
{
437+
"certificates": {
438+
"foo": {"cert": "/path/to/cert", "client-cert": "/path/to/client-cert"}
439+
},
440+
}
441+
)
442+
443+
authenticator = Authenticator(mock_config, NullIO())
444+
url = "https://foo.bar/files/foo-0.1.0.tar.gz"
445+
session = authenticator.get_session(url)
446+
session_send = mocker.patch.object(session, "send")
447+
authenticator.request("get", url, verify=verify)
448+
kwargs = session_send.call_args[1]
449+
450+
if verify is None:
451+
assert kwargs["verify"] == str(Path("/path/to/cert"))
452+
else:
453+
assert kwargs["verify"] is verify
454+
455+
425456
def test_authenticator_uses_credentials_from_config_matched_by_url_path(
426457
config: Config, mock_remote: None, http: responses.RequestsMock
427458
) -> None:

0 commit comments

Comments
 (0)