Use certifi provided certificates when downloading files (#455)
* Use certifi provided certificates when downloading files * fix typo * Add comment about certifi usage Co-authored-by: Joe Rickerby <joerick@mac.com> Co-authored-by: Joe Rickerby <joerick@mac.com>
This commit is contained in:
co-authored by
Joe Rickerby
parent
7dcd6826a4
commit
336c80b694
@@ -0,0 +1,31 @@
|
||||
import certifi
|
||||
import pytest
|
||||
import ssl
|
||||
|
||||
from cibuildwheel.util import download
|
||||
|
||||
|
||||
DOWNLOAD_URL = 'https://raw.githubusercontent.com/joerick/cibuildwheel/v1.6.3/requirements-dev.txt'
|
||||
|
||||
|
||||
def test_download(monkeypatch, tmp_path):
|
||||
monkeypatch.delenv('SSL_CERT_FILE', raising=False)
|
||||
dest = tmp_path / 'file.txt'
|
||||
download(DOWNLOAD_URL, dest)
|
||||
assert len(dest.read_bytes()) == 134
|
||||
|
||||
|
||||
def test_download_good_ssl_cert_file(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv('SSL_CERT_FILE', certifi.where())
|
||||
dest = tmp_path / 'file.txt'
|
||||
download(DOWNLOAD_URL, dest)
|
||||
assert len(dest.read_bytes()) == 134
|
||||
|
||||
|
||||
def test_download_bad_ssl_cert_file(monkeypatch, tmp_path):
|
||||
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'
|
||||
with pytest.raises(ssl.SSLError):
|
||||
download(DOWNLOAD_URL, dest)
|
||||
Reference in New Issue
Block a user