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

Add --trusted-host for non HTTPS repo (#1894) #3014

Merged
merged 10 commits into from
Oct 19, 2020
2 changes: 2 additions & 0 deletions poetry/utils/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def _export_requirements_txt(
url = (
repository.authenticated_url if with_credentials else repository.url
)
if repository.url.startswith("http://"):
estyxx marked this conversation as resolved.
Show resolved Hide resolved
indexes_header += "--trusted-host {}\n".format(url)
estyxx marked this conversation as resolved.
Show resolved Hide resolved
indexes_header += "--extra-index-url {}\n".format(url)

content = indexes_header + "\n" + content
Expand Down
55 changes: 55 additions & 0 deletions tests/utils/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,61 @@ def test_exporter_exports_requirements_txt_with_legacy_packages(tmp_dir, poetry)
assert expected == content


def test_exporter_exports_requirements_txt_with_legacy_packages_trusted_host(
tmp_dir, poetry
):
poetry.pool.add_repository(LegacyRepository("custom", "http://example.com/simple",))
poetry.locker.mock_lock_data(
estyxx marked this conversation as resolved.
Show resolved Hide resolved
{
"package": [
{
"name": "foo",
"version": "1.2.3",
"category": "main",
"optional": False,
"python-versions": "*",
},
{
"name": "bar",
"version": "4.5.6",
"category": "dev",
"optional": False,
"python-versions": "*",
"source": {
"type": "legacy",
"url": "http://example.com/simple",
"reference": "",
},
},
],
"metadata": {
"python-versions": "*",
"content-hash": "123456789",
"hashes": {"foo": ["12345"], "bar": ["67890"]},
},
}
)
set_package_requires(poetry)
exporter = Exporter(poetry)

exporter.export("requirements.txt", Path(tmp_dir), "requirements.txt", dev=True)

with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()

expected = """\
--trusted-host http://example.com/simple
--extra-index-url http://example.com/simple

bar==4.5.6 \\
--hash=sha256:67890
foo==1.2.3 \\
--hash=sha256:12345
"""

assert expected == content


@pytest.mark.parametrize(
("dev", "expected"),
[
Expand Down