Debian Codegraph @

test/with_dummyserver/test_no_ssl.py

raw
1 """
2 Test connections without the builtin ssl module
3
4 Note: Import urllib3 inside the test functions to get the importblocker to work
5 """
6
7 from __future__ import annotations
8
9 import pytest
10
11 import urllib3
12 from dummyserver.testcase import (
13 HTTPSHypercornDummyServerTestCase,
14 HypercornDummyServerTestCase,
15 )
16 from urllib3.exceptions import InsecureRequestWarning
17
18 from ..test_no_ssl import TestWithoutSSL
19
20
21 class TestHTTPWithoutSSL(HypercornDummyServerTestCase, TestWithoutSSL):
22 def test_simple(self) -> None:
23 with urllib3.HTTPConnectionPool(self.host, self.port) as pool:
24 r = pool.request("GET", "/")
25 assert r.status == 200, r.data
26
27
28 class TestHTTPSWithoutSSL(HTTPSHypercornDummyServerTestCase, TestWithoutSSL):
29 def test_simple(self) -> None:
30 with urllib3.HTTPSConnectionPool(
31 self.host, self.port, cert_reqs="NONE"
32 ) as pool:
33 with pytest.warns(InsecureRequestWarning):
34 try:
35 pool.request("GET", "/")
36 except urllib3.exceptions.SSLError as e:
37 assert "SSL module is not available" in str(e)