Skip to content

Commit a5282ed

Browse files
committed
mesh-1507: ssl adaptor should only be mounted for https:// connections
1 parent 386972b commit a5282ed

4 files changed

Lines changed: 106 additions & 2 deletions

File tree

mesh_client/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ def __init__(
284284
if verify is False:
285285
self._session.verify = False
286286

287-
self._session.mount(self._url, SSLContextAdapter(cert, verify, check_hostname, hostname_checks_common_name))
287+
if self._url.lower().startswith("https://"):
288+
self._session.mount(self._url, SSLContextAdapter(cert, verify, check_hostname, hostname_checks_common_name))
289+
288290
self._session.headers = {
289291
"User-Agent": (
290292
f"mesh_client;{__version__};N/A;{platform.processor() or platform.machine()};"

poetry.lock

Lines changed: 91 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ coverage = "^7.2.7"
4949
pytest = "^7.4.0"
5050
importlib-metadata = {version = ">=4.11.4", python = "<3.12"}
5151
#importlib-resources = {version = "*", python = "<3.9"}
52+
pytest-httpserver = {version = "^1.0.8", python = ">=3.8,<4.0"}
5253

5354
[tool.poetry.group.local.dependencies]
5455
ipython = {version = "^8.14.0", python = ">=3.9,<4.0"}
@@ -117,6 +118,7 @@ deps =
117118
requests>=2.26.0
118119
mock
119120
pytest
121+
pytest-httpserver
120122
commands =
121123
python -m pytest
122124

tests/mesh_sandbox_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import io
22
import os.path
3+
import sys
34
from typing import List, cast
45
from uuid import uuid4
56

67
import pytest
78
import requests
9+
from pytest_httpserver import HTTPServer
810
from requests import HTTPError
911

1012
from mesh_client import CombineStreams, MeshClient, MeshError
@@ -279,3 +281,11 @@ def test_endpoint_lookup(alice: MeshClient, bob: MeshClient):
279281
def test_error_handling(alice: MeshClient, bob: MeshClient):
280282
with pytest.raises(MeshError):
281283
alice.send_message(bob_mailbox, b"")
284+
285+
286+
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
287+
def test_mesh_client_with_http_server(httpserver: HTTPServer):
288+
httpserver.expect_request("/messageexchange/_ping").respond_with_json({}, status=200)
289+
290+
with MeshClient(httpserver.url_for(""), bob_mailbox, bob_password, max_chunk_size=5, verify=False) as client:
291+
client.ping()

0 commit comments

Comments
 (0)