-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SSLContext methods and properties
- Loading branch information
1 parent
b6db4be
commit 1df4895
Showing
2 changed files
with
169 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import ssl | ||
|
||
import pytest | ||
import urllib3 | ||
from urllib3.exceptions import InsecureRequestWarning | ||
|
||
import truststore | ||
|
||
|
||
def test_minimum_maximum_version(): | ||
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
ctx.maximum_version = ssl.TLSVersion.TLSv1_2 | ||
with urllib3.PoolManager(ssl_context=ctx) as http: | ||
|
||
resp = http.request("GET", "https://howsmyssl.com/a/check") | ||
data = json.loads(resp.data) | ||
assert data["tls_version"] == "TLS 1.2" | ||
|
||
assert ctx.minimum_version in ( | ||
ssl.TLSVersion.TLSv1_2, | ||
ssl.TLSVersion.MINIMUM_SUPPORTED, | ||
) | ||
assert ctx.maximum_version == ssl.TLSVersion.TLSv1_2 | ||
|
||
|
||
def test_disable_verification(): | ||
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
ctx.check_hostname = False | ||
ctx.verify_mode = ssl.CERT_NONE | ||
|
||
with urllib3.PoolManager(ssl_context=ctx) as http, pytest.warns( | ||
InsecureRequestWarning | ||
) as w: | ||
http.request("GET", "https://expired.badssl.com/") | ||
assert len(w) == 1 |