Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87e1a06

Browse files
committed
Python: fluent api tests
1 parent 186db7f commit 87e1a06

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import socket
2+
from OpenSSL import SSL
3+
4+
def test_fluent():
5+
hostname = 'www.python.org'
6+
context = SSL.Context(SSL.SSLv23_METHOD)
7+
8+
conn = SSL.Connection(context, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
9+
r = conn.connect((hostname, 443))
10+
print(conn.get_protocol_version_name())
11+
12+
13+
def test_fluent_no_TLSv1():
14+
hostname = 'www.python.org'
15+
context = SSL.Context(SSL.SSLv23_METHOD)
16+
context.set_options(SSL.OP_NO_TLSv1)
17+
18+
conn = SSL.Connection(context, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
19+
r = conn.connect((hostname, 443))
20+
print(conn.get_protocol_version_name())
21+
22+
23+
def test_fluent_safe():
24+
hostname = 'www.python.org'
25+
context = SSL.Context(SSL.SSLv23_METHOD)
26+
context.set_options(SSL.OP_NO_TLSv1)
27+
context.set_options(SSL.OP_NO_TLSv1_1)
28+
29+
conn = SSL.Connection(context, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
30+
r = conn.connect((hostname, 443))
31+
print(r, conn.get_protocol_version_name())
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import socket
2+
import ssl
3+
4+
def test_fluent_tls():
5+
hostname = 'www.python.org'
6+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
7+
8+
with socket.create_connection((hostname, 443)) as sock:
9+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
10+
print(ssock.version())
11+
12+
13+
def test_fluent_tls_no_TLSv1():
14+
hostname = 'www.python.org'
15+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
16+
context.options |= ssl.OP_NO_TLSv1
17+
18+
with socket.create_connection((hostname, 443)) as sock:
19+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
20+
print(ssock.version())
21+
22+
def test_fluent_tls_safe():
23+
hostname = 'www.python.org'
24+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
25+
context.options |= ssl.OP_NO_TLSv1
26+
context.options |= ssl.OP_NO_TLSv1_1
27+
28+
with socket.create_connection((hostname, 443)) as sock:
29+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
30+
print(ssock.version())
31+
32+
def test_fluent_ssl():
33+
hostname = 'www.python.org'
34+
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
35+
36+
with socket.create_connection((hostname, 443)) as sock:
37+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
38+
print(ssock.version())
39+
40+
41+
def test_fluent_ssl_no_TLSv1():
42+
hostname = 'www.python.org'
43+
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
44+
context.options |= ssl.OP_NO_TLSv1
45+
46+
with socket.create_connection((hostname, 443)) as sock:
47+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
48+
print(ssock.version())
49+
50+
def test_fluent_ssl_safe():
51+
hostname = 'www.python.org'
52+
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
53+
context.options |= ssl.OP_NO_TLSv1
54+
context.options |= ssl.OP_NO_TLSv1_1
55+
56+
with socket.create_connection((hostname, 443)) as sock:
57+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
58+
print(ssock.version())
59+
60+
def test_fluent_ssl_safe_combined():
61+
hostname = 'www.python.org'
62+
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
63+
context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1
64+
65+
with socket.create_connection((hostname, 443)) as sock:
66+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
67+
print(ssock.version())
68+
69+
# From Python 3.7
70+
# see https://docs.python.org/3/library/ssl.html#ssl.SSLContext.minimum_version
71+
def test_fluent_ssl_unsafe_version():
72+
hostname = 'www.python.org'
73+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
74+
context.minimum_version = ssl.TLSVersion.TLSv1_1
75+
76+
with socket.create_connection((hostname, 443)) as sock:
77+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
78+
print(ssock.version())
79+
80+
def test_fluent_ssl_safe_version():
81+
hostname = 'www.python.org'
82+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
83+
context.minimum_version = ssl.TLSVersion.TLSv1_3
84+
85+
with socket.create_connection((hostname, 443)) as sock:
86+
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
87+
print(ssock.version())

0 commit comments

Comments
 (0)