Skip to content

Commit

Permalink
Fix minimum and maximum version setting
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Mar 31, 2023
1 parent dd4f845 commit 23c3697
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ urllib3
trustme
requests
flaky
httpx
12 changes: 8 additions & 4 deletions src/truststore/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,19 @@ def maximum_version(self) -> ssl.TLSVersion:

@maximum_version.setter
def maximum_version(self, value: ssl.TLSVersion) -> None:
self._ctx.maximum_version = value
_original_super_SSLContext.maximum_version.__set__( # type: ignore[attr-defined]
self._ctx, value
)

@property
def minimum_version(self) -> ssl.TLSVersion:
return self._ctx.minimum_version

@minimum_version.setter
def minimum_version(self, value: ssl.TLSVersion) -> None:
self._ctx.minimum_version = value
_original_super_SSLContext.minimum_version.__set__( # type: ignore[attr-defined]
self._ctx, value
)

@property
def options(self) -> ssl.Options:
Expand All @@ -248,8 +252,8 @@ def protocol(self) -> ssl._SSLMethod:
return self._ctx.protocol

@property
def security_level(self) -> int:
return self._ctx.security_level # type: ignore[attr-defined,no-any-return]
def security_level(self) -> int: # type: ignore[override]
return self._ctx.security_level

@property
def verify_flags(self) -> ssl.VerifyFlags:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_inject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import ssl

import httpx
import pytest
import requests
import urllib3
Expand Down Expand Up @@ -106,3 +107,23 @@ def test_requests():

thread = asyncio.to_thread(test_requests)
await thread


@pytest.mark.asyncio
@pytest.mark.usefixtures("inject_truststore")
async def test_sync_httpx_works_with_inject(server: Server) -> None:
def test_httpx():
client = httpx.Client()
resp = client.request("GET", server.base_url)
assert resp.status_code == 200

thread = asyncio.to_thread(test_httpx)
await thread


@pytest.mark.asyncio
@pytest.mark.usefixtures("inject_truststore")
async def test_async_httpx_works_with_inject(server: Server) -> None:
client = httpx.AsyncClient()
resp = await client.request("GET", server.base_url)
assert resp.status_code == 200

0 comments on commit 23c3697

Please sign in to comment.