2020-10-31 10:06:14 +01:00
|
|
|
import ssl
|
|
|
|
|
|
2021-01-06 13:50:58 -05:00
|
|
|
import certifi
|
|
|
|
|
import pytest
|
2020-10-31 10:06:14 +01:00
|
|
|
|
2025-01-27 20:35:56 +01:00
|
|
|
from cibuildwheel.util.file import download
|
2020-10-31 10:06:14 +01:00
|
|
|
|
2025-05-19 16:58:28 +01:00
|
|
|
DOWNLOAD_URL = "https://cdn.jsdelivr.net/gh/pypa/cibuildwheel@v1.6.3/requirements-dev.txt"
|
2020-10-31 10:06:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_download(monkeypatch, tmp_path):
|
2021-05-03 11:45:43 -04:00
|
|
|
monkeypatch.delenv("SSL_CERT_FILE", raising=False)
|
|
|
|
|
dest = tmp_path / "file.txt"
|
2020-10-31 10:06:14 +01:00
|
|
|
download(DOWNLOAD_URL, dest)
|
|
|
|
|
assert len(dest.read_bytes()) == 134
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_download_good_ssl_cert_file(monkeypatch, tmp_path):
|
2021-05-03 11:45:43 -04:00
|
|
|
monkeypatch.setenv("SSL_CERT_FILE", certifi.where())
|
|
|
|
|
dest = tmp_path / "file.txt"
|
2020-10-31 10:06:14 +01:00
|
|
|
download(DOWNLOAD_URL, dest)
|
|
|
|
|
assert len(dest.read_bytes()) == 134
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_download_bad_ssl_cert_file(monkeypatch, tmp_path):
|
2021-05-03 11:45:43 -04:00
|
|
|
bad_cafile = tmp_path / "ca.pem"
|
|
|
|
|
bad_cafile.write_text("bad certificates")
|
|
|
|
|
monkeypatch.setenv("SSL_CERT_FILE", str(bad_cafile))
|
|
|
|
|
dest = tmp_path / "file.txt"
|
2020-10-31 10:06:14 +01:00
|
|
|
with pytest.raises(ssl.SSLError):
|
|
|
|
|
download(DOWNLOAD_URL, dest)
|