| 1 |
""" |
| 2 |
Test what happens if Python was built without SSL |
| 3 |
|
| 4 |
* Everything that does not involve HTTPS should still work |
| 5 |
* HTTPS requests must fail with an error that points at the ssl module |
| 6 |
""" |
| 7 |
|
| 8 |
from __future__ import annotations |
| 9 |
|
| 10 |
import sys |
| 11 |
from test import ImportBlocker, ModuleStash |
| 12 |
|
| 13 |
import pytest |
| 14 |
|
| 15 |
ssl_blocker = ImportBlocker("ssl", "_ssl") |
| 16 |
module_stash = ModuleStash("urllib3") |
| 17 |
|
| 18 |
|
| 19 |
class TestWithoutSSL: |
| 20 |
@classmethod |
| 21 |
def setup_class(cls) -> None: |
| 22 |
sys.modules.pop("ssl", None) |
| 23 |
sys.modules.pop("_ssl", None) |
| 24 |
|
| 25 |
module_stash.stash() |
| 26 |
sys.meta_path.insert(0, ssl_blocker) |
| 27 |
|
| 28 |
@classmethod |
| 29 |
def teardown_class(cls) -> None: |
| 30 |
sys.meta_path.remove(ssl_blocker) |
| 31 |
module_stash.pop() |
| 32 |
|
| 33 |
|
| 34 |
class TestImportWithoutSSL(TestWithoutSSL): |
| 35 |
def test_cannot_import_ssl(self) -> None: |
| 36 |
with pytest.raises(ImportError): |
| 37 |
import ssl # noqa: F401 |
| 38 |
|
| 39 |
def test_import_urllib3(self) -> None: |
| 40 |
import urllib3 # noqa: F401 |