Skip to content

Commit 8254da5

Browse files
use a www.elastic.co instead of httpbin.org for SSL tests
1 parent 840f87d commit 8254da5

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ jobs:
6161
image: kennethreitz/httpbin
6262
ports:
6363
- 8080:80
64+
elasticsearch:
65+
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.2
66+
env:
67+
discovery.type: single-node
68+
ports:
69+
- 9200:9200
6470
steps:
6571
- name: Checkout repository
6672
uses: actions/checkout@v2

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ async def perform_request(self, *args, **kwargs):
6767

6868

6969
@pytest.fixture(scope="session", params=[True, False])
70-
def httpbin_cert_fingerprint(request) -> str:
71-
"""Gets the SHA256 fingerprint of the certificate for 'httpbin.org'"""
72-
sock = socket.create_connection(("httpbin.org", 443))
70+
def cert_fingerprint(request) -> str:
71+
"""Gets the SHA256 fingerprint of the certificate for localhost:9200"""
72+
sock = socket.create_connection(("localhost", 9200))
7373
ctx = ssl.create_default_context()
7474
ctx.check_hostname = False
7575
ctx.verify_mode = ssl.CERT_NONE

tests/node/test_http_aiohttp.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,40 +290,44 @@ async def test_head_workaround(self, aiohttp_fixed_head_bug):
290290

291291

292292
@pytest.mark.asyncio
293-
async def test_ssl_assert_fingerprint(httpbin_cert_fingerprint):
293+
async def test_ssl_assert_fingerprint(cert_fingerprint):
294294
with warnings.catch_warnings(record=True) as w:
295295
node = AiohttpHttpNode(
296296
NodeConfig(
297297
scheme="https",
298-
host="httpbin.org",
299-
port=443,
300-
ssl_assert_fingerprint=httpbin_cert_fingerprint,
298+
host="localhost",
299+
port=9200,
300+
ssl_assert_fingerprint=cert_fingerprint,
301301
)
302302
)
303303
resp, _ = await node.perform_request("GET", "/")
304304

305-
assert resp.status == 200
305+
assert resp.status == 401
306306
assert [str(x.message) for x in w if x.category != DeprecationWarning] == []
307307

308308

309309
@pytest.mark.asyncio
310310
async def test_default_headers():
311-
node = AiohttpHttpNode(NodeConfig(scheme="https", host="httpbin.org", port=443))
311+
node = AiohttpHttpNode(NodeConfig(scheme="http", host="localhost", port=8080))
312312
resp, data = await node.perform_request("GET", "/anything")
313313

314314
assert resp.status == 200
315315
headers = json.loads(data)["headers"]
316316
headers.pop("X-Amzn-Trace-Id", None)
317-
assert headers == {"Host": "httpbin.org", "User-Agent": DEFAULT_USER_AGENT}
317+
assert headers == {
318+
"Connection": "keep-alive",
319+
"Host": "localhost:8080",
320+
"User-Agent": DEFAULT_USER_AGENT,
321+
}
318322

319323

320324
@pytest.mark.asyncio
321325
async def test_custom_headers():
322326
node = AiohttpHttpNode(
323327
NodeConfig(
324-
scheme="https",
325-
host="httpbin.org",
326-
port=443,
328+
scheme="http",
329+
host="localhost",
330+
port=8080,
327331
headers={"accept-encoding": "gzip", "Content-Type": "application/json"},
328332
)
329333
)
@@ -341,8 +345,9 @@ async def test_custom_headers():
341345
headers.pop("X-Amzn-Trace-Id", None)
342346
assert headers == {
343347
"Accept-Encoding": "gzip",
348+
"Connection": "keep-alive",
344349
"Content-Type": "application/x-ndjson",
345-
"Host": "httpbin.org",
350+
"Host": "localhost:8080",
346351
"User-Agent": "custom-agent/1.2.3",
347352
}
348353

@@ -351,9 +356,9 @@ async def test_custom_headers():
351356
async def test_custom_user_agent():
352357
node = AiohttpHttpNode(
353358
NodeConfig(
354-
scheme="https",
355-
host="httpbin.org",
356-
port=443,
359+
scheme="http",
360+
host="localhost",
361+
port=8080,
357362
headers={
358363
"accept-encoding": "gzip",
359364
"Content-Type": "application/json",
@@ -371,8 +376,9 @@ async def test_custom_user_agent():
371376
headers.pop("X-Amzn-Trace-Id", None)
372377
assert headers == {
373378
"Accept-Encoding": "gzip",
379+
"Connection": "keep-alive",
374380
"Content-Type": "application/json",
375-
"Host": "httpbin.org",
381+
"Host": "localhost:8080",
376382
"User-Agent": "custom-agent/1.2.3",
377383
}
378384

@@ -385,7 +391,7 @@ def test_repr():
385391
@pytest.mark.asyncio
386392
async def test_head():
387393
node = AiohttpHttpNode(
388-
NodeConfig(scheme="https", host="httpbin.org", port=443, http_compress=True)
394+
NodeConfig(scheme="http", host="localhost", port=8080, http_compress=True)
389395
)
390396
resp, data = await node.perform_request("HEAD", "/anything")
391397

tests/node/test_http_httpx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ async def test_merge_headers(self):
145145
assert request.headers["h3"] == "v3"
146146

147147

148-
def test_ssl_assert_fingerprint(httpbin_cert_fingerprint):
148+
def test_ssl_assert_fingerprint(cert_fingerprint):
149149
with pytest.raises(ValueError, match="httpx does not support certificate pinning"):
150150
HttpxAsyncHttpNode(
151151
NodeConfig(
152152
scheme="https",
153-
host="httpbin.org",
154-
port=443,
155-
ssl_assert_fingerprint=httpbin_cert_fingerprint,
153+
host="localhost",
154+
port=9200,
155+
ssl_assert_fingerprint=cert_fingerprint,
156156
)
157157
)

tests/node/test_urllib3_chain_certs.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def test_ssl_assert_fingerprint_invalid_length(node_cls):
3535
node_cls(
3636
NodeConfig(
3737
"https",
38-
"httpbin.org",
39-
443,
38+
"localhost",
39+
9200,
4040
ssl_assert_fingerprint="0000",
4141
)
4242
)
@@ -52,17 +52,17 @@ def test_ssl_assert_fingerprint_invalid_length(node_cls):
5252
@pytest.mark.parametrize(
5353
"ssl_assert_fingerprint",
5454
[
55-
"8ecde6884f3d87b1125ba31ac3fcb13d7016de7f57cc904fe1cb97c6ae98196e",
56-
"8e:cd:e6:88:4f:3d:87:b1:12:5b:a3:1a:c3:fc:b1:3d:70:16:de:7f:57:cc:90:4f:e1:cb:97:c6:ae:98:19:6e",
57-
"8ECDE6884F3D87B1125BA31AC3FCB13D7016DE7F57CC904FE1CB97C6AE98196E",
55+
"18efbd94dda87e3598a1251f9440cd2f4fd1dbf08be007c1012e992e830ca262",
56+
"18:EF:BD:94:DD:A8:7E:35:98:A1:25:1F:94:40:CD:2F:4F:D1:DB:F0:8B:E0:07:C1:01:2E:99:2E:83:0C:A2:62",
57+
"18EFBD94DDA87E3598A1251F9440CD2F4FD1DBF08BE007C1012E992E830CA262",
5858
],
5959
)
6060
def test_assert_fingerprint_in_cert_chain(node_cls, ssl_assert_fingerprint):
6161
with warnings.catch_warnings(record=True) as w:
6262
node = node_cls(
6363
NodeConfig(
6464
"https",
65-
"httpbin.org",
65+
"www.elastic.co",
6666
443,
6767
ssl_assert_fingerprint=ssl_assert_fingerprint,
6868
)
@@ -79,7 +79,7 @@ def test_assert_fingerprint_in_cert_chain_failure(node_cls):
7979
node = node_cls(
8080
NodeConfig(
8181
"https",
82-
"httpbin.org",
82+
"www.elastic.co",
8383
443,
8484
ssl_assert_fingerprint="0" * 64,
8585
)
@@ -89,11 +89,12 @@ def test_assert_fingerprint_in_cert_chain_failure(node_cls):
8989
node.perform_request("GET", "/")
9090

9191
err = str(e.value)
92+
print(err)
9293
assert "Fingerprints did not match." in err
9394
# This is the bad value we "expected"
9495
assert (
9596
'Expected "0000000000000000000000000000000000000000000000000000000000000000",'
9697
in err
9798
)
9899
# This is the root CA for httpbin.org with a leading comma to denote more than one cert was listed.
99-
assert ', "8ecde6884f3d87b1125ba31ac3fcb13d7016de7f57cc904fe1cb97c6ae98196e"' in err
100+
assert '"18efbd94dda87e3598a1251f9440cd2f4fd1dbf08be007c1012e992e830ca262"' in err

0 commit comments

Comments
 (0)