2020-05-02 22:50:52 +01:00
|
|
|
import textwrap
|
|
|
|
|
|
2025-09-08 22:54:55 +01:00
|
|
|
import pytest
|
|
|
|
|
|
2021-01-06 13:50:58 -05:00
|
|
|
from . import test_projects, utils
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2020-05-17 16:54:33 +01:00
|
|
|
project_with_ssl_tests = test_projects.new_c_project(
|
2021-04-30 17:56:34 -04:00
|
|
|
setup_py_add=textwrap.dedent(
|
2021-05-03 11:45:43 -04:00
|
|
|
r"""
|
2026-02-06 20:35:20 +00:00
|
|
|
import ssl, time, urllib.request, urllib.error
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2026-02-06 20:35:20 +00:00
|
|
|
def check_https(context=None):
|
|
|
|
|
# google hosts this endpoint that returns a 204 No Content, it's used for
|
|
|
|
|
# connectivity checks in Android & Chrome
|
|
|
|
|
url = "https://google.com/generate_204"
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2026-02-06 20:35:20 +00:00
|
|
|
for i in range(5):
|
|
|
|
|
try:
|
|
|
|
|
urllib.request.urlopen(url, context=context, timeout=5)
|
|
|
|
|
return
|
|
|
|
|
except (OSError, urllib.error.URLError) as e:
|
|
|
|
|
print(f"Attempt {i+1}: Could not connect to {url}: {e}")
|
|
|
|
|
time.sleep(2 ** i) # Backoff: 1s, 2s, 4s, 8s...
|
|
|
|
|
|
|
|
|
|
raise ConnectionError(f"Could not connect to {url} after retries.")
|
|
|
|
|
|
|
|
|
|
check_https()
|
|
|
|
|
check_https(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2))
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
2020-05-02 16:54:19 +01:00
|
|
|
)
|
|
|
|
|
|
2020-05-02 22:50:52 +01:00
|
|
|
|
2025-09-08 22:54:55 +01:00
|
|
|
@pytest.mark.flaky(reruns=2)
|
2020-05-03 14:08:57 +01:00
|
|
|
def test(tmp_path):
|
2020-05-02 16:54:19 +01:00
|
|
|
# this test checks that SSL is working in the build environment using
|
|
|
|
|
# some checks in setup.py.
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-05-02 16:54:19 +01:00
|
|
|
project_with_ssl_tests.generate(project_dir)
|
|
|
|
|
|
2020-05-15 12:19:38 +01:00
|
|
|
actual_wheels = utils.cibuildwheel_run(project_dir)
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
2020-05-15 12:19:38 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|