Skip to content

Commit 00b3559

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

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

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 'www.elastic.co'"""
72+
sock = socket.create_connection(("www.elastic.co", 443))
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -290,40 +290,45 @@ 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):
294+
print('***', cert_fingerprint)
294295
with warnings.catch_warnings(record=True) as w:
295296
node = AiohttpHttpNode(
296297
NodeConfig(
297298
scheme="https",
298-
host="httpbin.org",
299+
host="www.elastic.co",
299300
port=443,
300-
ssl_assert_fingerprint=httpbin_cert_fingerprint,
301+
ssl_assert_fingerprint=cert_fingerprint,
301302
)
302303
)
303304
resp, _ = await node.perform_request("GET", "/")
304305

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

308309

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

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

319324

320325
@pytest.mark.asyncio
321326
async def test_custom_headers():
322327
node = AiohttpHttpNode(
323328
NodeConfig(
324-
scheme="https",
325-
host="httpbin.org",
326-
port=443,
329+
scheme="http",
330+
host="localhost",
331+
port=8080,
327332
headers={"accept-encoding": "gzip", "Content-Type": "application/json"},
328333
)
329334
)
@@ -341,8 +346,9 @@ async def test_custom_headers():
341346
headers.pop("X-Amzn-Trace-Id", None)
342347
assert headers == {
343348
"Accept-Encoding": "gzip",
349+
"Connection": "keep-alive",
344350
"Content-Type": "application/x-ndjson",
345-
"Host": "httpbin.org",
351+
"Host": "localhost:8080",
346352
"User-Agent": "custom-agent/1.2.3",
347353
}
348354

@@ -351,9 +357,9 @@ async def test_custom_headers():
351357
async def test_custom_user_agent():
352358
node = AiohttpHttpNode(
353359
NodeConfig(
354-
scheme="https",
355-
host="httpbin.org",
356-
port=443,
360+
scheme="http",
361+
host="localhost",
362+
port=8080,
357363
headers={
358364
"accept-encoding": "gzip",
359365
"Content-Type": "application/json",
@@ -371,8 +377,9 @@ async def test_custom_user_agent():
371377
headers.pop("X-Amzn-Trace-Id", None)
372378
assert headers == {
373379
"Accept-Encoding": "gzip",
380+
"Connection": "keep-alive",
374381
"Content-Type": "application/json",
375-
"Host": "httpbin.org",
382+
"Host": "localhost:8080",
376383
"User-Agent": "custom-agent/1.2.3",
377384
}
378385

@@ -385,7 +392,7 @@ def test_repr():
385392
@pytest.mark.asyncio
386393
async def test_head():
387394
node = AiohttpHttpNode(
388-
NodeConfig(scheme="https", host="httpbin.org", port=443, http_compress=True)
395+
NodeConfig(scheme="http", host="localhost", port=8080, http_compress=True)
389396
)
390397
resp, data = await node.perform_request("HEAD", "/anything")
391398

tests/node/test_http_httpx.py

Lines changed: 3 additions & 3 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",
153+
host="www.elastic.co",
154154
port=443,
155-
ssl_assert_fingerprint=httpbin_cert_fingerprint,
155+
ssl_assert_fingerprint=cert_fingerprint,
156156
)
157157
)

tests/node/test_urllib3_chain_certs.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_ssl_assert_fingerprint_invalid_length(node_cls):
3535
node_cls(
3636
NodeConfig(
3737
"https",
38-
"httpbin.org",
38+
"www.elastic.co",
3939
443,
4040
ssl_assert_fingerprint="0000",
4141
)
@@ -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)