GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mesh-client/tests/ssl_context_adapter_tests.py at develop · NHSDigital/mesh-client

Expand file tree

/

ssl_context_adapter_tests.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
65 lines (47 loc) · 1.94 KB
/

ssl_context_adapter_tests.py

Copy path

File metadata and controls

65 lines (47 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import annotations
from unittest.mock import Mock
import pytest
import mesh_client
class SSLContextStub:
def __init__(self) -> None:
self.load_cert_chain = Mock()
self.load_verify_locations = Mock()
self.minimum_version = None
self.check_hostname = None
self.verify_mode = None
self.hostname_checks_common_name = None
@pytest.mark.parametrize(
("certs", "loads_cert_chain_called"),
[
(("client.crt", "client.key"), True),
(None, False),
(["client.crt", "client.key"], True),
],
)
def test_create_ssl_context_loads_cert_chain(
monkeypatch, certs: tuple[str, str] | list[str] | None, loads_cert_chain_called: bool
):
dummy_context = SSLContextStub()
monkeypatch.setattr(mesh_client, "create_urllib3_context", lambda: dummy_context)
adapter = mesh_client.SSLContextAdapter(cert=certs, verify=None) # type: ignore[arg-type]
dummy_context.load_cert_chain.reset_mock()
context = adapter.create_ssl_context()
assert context is dummy_context
if loads_cert_chain_called:
assert certs is not None
dummy_context.load_cert_chain.assert_called_with(*certs)
else:
dummy_context.load_cert_chain.assert_not_called()
@pytest.mark.parametrize("verify", [True, False, "/path/to/ca.pem", b"/path/to/ca.pem", None])
def test_create_ssl_context_loads_verify_locations_when_verify_is_provided(
monkeypatch, verify: bool | str | bytes | None
):
dummy_context = SSLContextStub()
monkeypatch.setattr(mesh_client, "create_urllib3_context", lambda: dummy_context)
adapter = mesh_client.SSLContextAdapter(cert=None, verify=verify) # type: ignore[arg-type]
context = adapter.create_ssl_context()
assert context is dummy_context
if type(verify) in (str, bytes):
dummy_context.load_verify_locations.assert_called_with(verify)
else:
dummy_context.load_verify_locations.assert_not_called()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.