Skip to content

Commit 5c020b8

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

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ 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
)
@@ -308,22 +308,22 @@ async def test_ssl_assert_fingerprint(httpbin_cert_fingerprint):
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 == {"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
)
@@ -342,7 +342,7 @@ async def test_custom_headers():
342342
assert headers == {
343343
"Accept-Encoding": "gzip",
344344
"Content-Type": "application/x-ndjson",
345-
"Host": "httpbin.org",
345+
"Host": "localhost:8080",
346346
"User-Agent": "custom-agent/1.2.3",
347347
}
348348

@@ -351,9 +351,9 @@ async def test_custom_headers():
351351
async def test_custom_user_agent():
352352
node = AiohttpHttpNode(
353353
NodeConfig(
354-
scheme="https",
355-
host="httpbin.org",
356-
port=443,
354+
scheme="http",
355+
host="localhost",
356+
port=8080,
357357
headers={
358358
"accept-encoding": "gzip",
359359
"Content-Type": "application/json",
@@ -372,7 +372,7 @@ async def test_custom_user_agent():
372372
assert headers == {
373373
"Accept-Encoding": "gzip",
374374
"Content-Type": "application/json",
375-
"Host": "httpbin.org",
375+
"Host": "localhost:8080",
376376
"User-Agent": "custom-agent/1.2.3",
377377
}
378378

@@ -385,7 +385,7 @@ def test_repr():
385385
@pytest.mark.asyncio
386386
async def test_head():
387387
node = AiohttpHttpNode(
388-
NodeConfig(scheme="https", host="httpbin.org", port=443, http_compress=True)
388+
NodeConfig(scheme="http", host="localhost", port=8080, http_compress=True)
389389
)
390390
resp, data = await node.perform_request("HEAD", "/anything")
391391

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)