Skip to content

Commit a286535

Browse files
use a locally hosted elastcsearch for SSL tests
1 parent 840f87d commit a286535

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def perform_request(self, *args, **kwargs):
6969
@pytest.fixture(scope="session", params=[True, False])
7070
def httpbin_cert_fingerprint(request) -> str:
7171
"""Gets the SHA256 fingerprint of the certificate for 'httpbin.org'"""
72-
sock = socket.create_connection(("httpbin.org", 443))
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: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,35 +295,35 @@ async def test_ssl_assert_fingerprint(httpbin_cert_fingerprint):
295295
node = AiohttpHttpNode(
296296
NodeConfig(
297297
scheme="https",
298-
host="httpbin.org",
299-
port=443,
298+
host="localhost",
299+
port=9200,
300300
ssl_assert_fingerprint=httpbin_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 == {"Connection": "keep-alive", "Host": "localhost:8080", "User-Agent": DEFAULT_USER_AGENT}
318318

319319

320320
@pytest.mark.asyncio
321321
async def test_custom_headers():
322322
node = AiohttpHttpNode(
323323
NodeConfig(
324-
scheme="https",
325-
host="httpbin.org",
326-
port=443,
324+
scheme="http",
325+
host="localhost",
326+
port=8080,
327327
headers={"accept-encoding": "gzip", "Content-Type": "application/json"},
328328
)
329329
)
@@ -341,8 +341,9 @@ async def test_custom_headers():
341341
headers.pop("X-Amzn-Trace-Id", None)
342342
assert headers == {
343343
"Accept-Encoding": "gzip",
344+
"Connection": "keep-alive",
344345
"Content-Type": "application/x-ndjson",
345-
"Host": "httpbin.org",
346+
"Host": "localhost:8080",
346347
"User-Agent": "custom-agent/1.2.3",
347348
}
348349

@@ -351,9 +352,9 @@ async def test_custom_headers():
351352
async def test_custom_user_agent():
352353
node = AiohttpHttpNode(
353354
NodeConfig(
354-
scheme="https",
355-
host="httpbin.org",
356-
port=443,
355+
scheme="http",
356+
host="localhost",
357+
port=8080,
357358
headers={
358359
"accept-encoding": "gzip",
359360
"Content-Type": "application/json",
@@ -371,8 +372,9 @@ async def test_custom_user_agent():
371372
headers.pop("X-Amzn-Trace-Id", None)
372373
assert headers == {
373374
"Accept-Encoding": "gzip",
375+
"Connection": "keep-alive",
374376
"Content-Type": "application/json",
375-
"Host": "httpbin.org",
377+
"Host": "localhost:8080",
376378
"User-Agent": "custom-agent/1.2.3",
377379
}
378380

@@ -385,7 +387,7 @@ def test_repr():
385387
@pytest.mark.asyncio
386388
async def test_head():
387389
node = AiohttpHttpNode(
388-
NodeConfig(scheme="https", host="httpbin.org", port=443, http_compress=True)
390+
NodeConfig(scheme="http", host="localhost", port=8080, http_compress=True)
389391
)
390392
resp, data = await node.perform_request("HEAD", "/anything")
391393

tests/node/test_http_httpx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def test_ssl_assert_fingerprint(httpbin_cert_fingerprint):
150150
HttpxAsyncHttpNode(
151151
NodeConfig(
152152
scheme="https",
153-
host="httpbin.org",
154-
port=443,
153+
host="localhost",
154+
port=9200,
155155
ssl_assert_fingerprint=httpbin_cert_fingerprint,
156156
)
157157
)

tests/node/test_urllib3_chain_certs.py

Lines changed: 6 additions & 6 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
)
@@ -62,8 +62,8 @@ def test_assert_fingerprint_in_cert_chain(node_cls, ssl_assert_fingerprint):
6262
node = node_cls(
6363
NodeConfig(
6464
"https",
65-
"httpbin.org",
66-
443,
65+
"localhost",
66+
9200,
6767
ssl_assert_fingerprint=ssl_assert_fingerprint,
6868
)
6969
)
@@ -79,8 +79,8 @@ def test_assert_fingerprint_in_cert_chain_failure(node_cls):
7979
node = node_cls(
8080
NodeConfig(
8181
"https",
82-
"httpbin.org",
83-
443,
82+
"localhost",
83+
9200,
8484
ssl_assert_fingerprint="0" * 64,
8585
)
8686
)

0 commit comments

Comments
 (0)