body
stringlengths 26
98.2k
| body_hash
int64 -9,222,864,604,528,158,000
9,221,803,474B
| docstring
stringlengths 1
16.8k
| path
stringlengths 5
230
| name
stringlengths 1
96
| repository_name
stringlengths 7
89
| lang
stringclasses 1
value | body_without_docstring
stringlengths 20
98.2k
|
---|---|---|---|---|---|---|---|
def test_old_callback_forgotten(self):
'\n If `Context.set_tlsext_servername_callback` is used to specify\n a new callback, the one it replaces is dereferenced.\n '
def callback(connection):
pass
def replacement(connection):
pass
context = Context(TLSv1_METHOD)
context.set_tlsext_servername_callback(callback)
tracker = ref(callback)
del callback
context.set_tlsext_servername_callback(replacement)
collect()
collect()
callback = tracker()
if (callback is not None):
referrers = get_referrers(callback)
if (len(referrers) > 1):
pytest.fail(('Some references remain: %r' % (referrers,))) | 2,692,158,595,643,120,600 | If `Context.set_tlsext_servername_callback` is used to specify
a new callback, the one it replaces is dereferenced. | tests/test_ssl.py | test_old_callback_forgotten | dholth/pyopenssl | python | def test_old_callback_forgotten(self):
'\n If `Context.set_tlsext_servername_callback` is used to specify\n a new callback, the one it replaces is dereferenced.\n '
def callback(connection):
pass
def replacement(connection):
pass
context = Context(TLSv1_METHOD)
context.set_tlsext_servername_callback(callback)
tracker = ref(callback)
del callback
context.set_tlsext_servername_callback(replacement)
collect()
collect()
callback = tracker()
if (callback is not None):
referrers = get_referrers(callback)
if (len(referrers) > 1):
pytest.fail(('Some references remain: %r' % (referrers,))) |
def test_no_servername(self):
'\n When a client specifies no server name, the callback passed to\n `Context.set_tlsext_servername_callback` is invoked and the\n result of `Connection.get_servername` is `None`.\n '
args = []
def servername(conn):
args.append((conn, conn.get_servername()))
context = Context(TLSv1_METHOD)
context.set_tlsext_servername_callback(servername)
del servername
collect()
context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(context, None)
server.set_accept_state()
client = Connection(Context(TLSv1_METHOD), None)
client.set_connect_state()
interact_in_memory(server, client)
assert (args == [(server, None)]) | 2,583,131,076,150,456,300 | When a client specifies no server name, the callback passed to
`Context.set_tlsext_servername_callback` is invoked and the
result of `Connection.get_servername` is `None`. | tests/test_ssl.py | test_no_servername | dholth/pyopenssl | python | def test_no_servername(self):
'\n When a client specifies no server name, the callback passed to\n `Context.set_tlsext_servername_callback` is invoked and the\n result of `Connection.get_servername` is `None`.\n '
args = []
def servername(conn):
args.append((conn, conn.get_servername()))
context = Context(TLSv1_METHOD)
context.set_tlsext_servername_callback(servername)
del servername
collect()
context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(context, None)
server.set_accept_state()
client = Connection(Context(TLSv1_METHOD), None)
client.set_connect_state()
interact_in_memory(server, client)
assert (args == [(server, None)]) |
def test_servername(self):
'\n When a client specifies a server name in its hello message, the\n callback passed to `Contexts.set_tlsext_servername_callback` is\n invoked and the result of `Connection.get_servername` is that\n server name.\n '
args = []
def servername(conn):
args.append((conn, conn.get_servername()))
context = Context(TLSv1_METHOD)
context.set_tlsext_servername_callback(servername)
context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(context, None)
server.set_accept_state()
client = Connection(Context(TLSv1_METHOD), None)
client.set_connect_state()
client.set_tlsext_host_name(b'foo1.example.com')
interact_in_memory(server, client)
assert (args == [(server, b'foo1.example.com')]) | -8,298,663,778,135,569,000 | When a client specifies a server name in its hello message, the
callback passed to `Contexts.set_tlsext_servername_callback` is
invoked and the result of `Connection.get_servername` is that
server name. | tests/test_ssl.py | test_servername | dholth/pyopenssl | python | def test_servername(self):
'\n When a client specifies a server name in its hello message, the\n callback passed to `Contexts.set_tlsext_servername_callback` is\n invoked and the result of `Connection.get_servername` is that\n server name.\n '
args = []
def servername(conn):
args.append((conn, conn.get_servername()))
context = Context(TLSv1_METHOD)
context.set_tlsext_servername_callback(servername)
context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(context, None)
server.set_accept_state()
client = Connection(Context(TLSv1_METHOD), None)
client.set_connect_state()
client.set_tlsext_host_name(b'foo1.example.com')
interact_in_memory(server, client)
assert (args == [(server, b'foo1.example.com')]) |
def test_npn_success(self):
'\n Tests that clients and servers that agree on the negotiated next\n protocol can correct establish a connection, and that the agreed\n protocol is reported by the connections.\n '
advertise_args = []
select_args = []
def advertise(conn):
advertise_args.append((conn,))
return [b'http/1.1', b'spdy/2']
def select(conn, options):
select_args.append((conn, options))
return b'spdy/2'
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
interact_in_memory(server, client)
assert (advertise_args == [(server,)])
assert (select_args == [(client, [b'http/1.1', b'spdy/2'])])
assert (server.get_next_proto_negotiated() == b'spdy/2')
assert (client.get_next_proto_negotiated() == b'spdy/2') | -4,643,417,706,840,057,000 | Tests that clients and servers that agree on the negotiated next
protocol can correct establish a connection, and that the agreed
protocol is reported by the connections. | tests/test_ssl.py | test_npn_success | dholth/pyopenssl | python | def test_npn_success(self):
'\n Tests that clients and servers that agree on the negotiated next\n protocol can correct establish a connection, and that the agreed\n protocol is reported by the connections.\n '
advertise_args = []
select_args = []
def advertise(conn):
advertise_args.append((conn,))
return [b'http/1.1', b'spdy/2']
def select(conn, options):
select_args.append((conn, options))
return b'spdy/2'
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
interact_in_memory(server, client)
assert (advertise_args == [(server,)])
assert (select_args == [(client, [b'http/1.1', b'spdy/2'])])
assert (server.get_next_proto_negotiated() == b'spdy/2')
assert (client.get_next_proto_negotiated() == b'spdy/2') |
def test_npn_client_fail(self):
'\n Tests that when clients and servers cannot agree on what protocol\n to use next that the TLS connection does not get established.\n '
advertise_args = []
select_args = []
def advertise(conn):
advertise_args.append((conn,))
return [b'http/1.1', b'spdy/2']
def select(conn, options):
select_args.append((conn, options))
return b''
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
with pytest.raises(Error):
interact_in_memory(server, client)
assert (advertise_args == [(server,)])
assert (select_args == [(client, [b'http/1.1', b'spdy/2'])]) | -7,486,636,102,291,540,000 | Tests that when clients and servers cannot agree on what protocol
to use next that the TLS connection does not get established. | tests/test_ssl.py | test_npn_client_fail | dholth/pyopenssl | python | def test_npn_client_fail(self):
'\n Tests that when clients and servers cannot agree on what protocol\n to use next that the TLS connection does not get established.\n '
advertise_args = []
select_args = []
def advertise(conn):
advertise_args.append((conn,))
return [b'http/1.1', b'spdy/2']
def select(conn, options):
select_args.append((conn, options))
return b
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
with pytest.raises(Error):
interact_in_memory(server, client)
assert (advertise_args == [(server,)])
assert (select_args == [(client, [b'http/1.1', b'spdy/2'])]) |
def test_npn_select_error(self):
'\n Test that we can handle exceptions in the select callback. If\n select fails it should be fatal to the connection.\n '
advertise_args = []
def advertise(conn):
advertise_args.append((conn,))
return [b'http/1.1', b'spdy/2']
def select(conn, options):
raise TypeError
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
with pytest.raises(TypeError):
interact_in_memory(server, client)
assert (advertise_args == [(server,)]) | -1,544,551,102,780,992,300 | Test that we can handle exceptions in the select callback. If
select fails it should be fatal to the connection. | tests/test_ssl.py | test_npn_select_error | dholth/pyopenssl | python | def test_npn_select_error(self):
'\n Test that we can handle exceptions in the select callback. If\n select fails it should be fatal to the connection.\n '
advertise_args = []
def advertise(conn):
advertise_args.append((conn,))
return [b'http/1.1', b'spdy/2']
def select(conn, options):
raise TypeError
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
with pytest.raises(TypeError):
interact_in_memory(server, client)
assert (advertise_args == [(server,)]) |
def test_npn_advertise_error(self):
'\n Test that we can handle exceptions in the advertise callback. If\n advertise fails no NPN is advertised to the client.\n '
select_args = []
def advertise(conn):
raise TypeError
def select(conn, options):
'\n Assert later that no args are actually appended.\n '
select_args.append((conn, options))
return b''
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
with pytest.raises(TypeError):
interact_in_memory(server, client)
assert (select_args == []) | 3,555,250,091,784,589,000 | Test that we can handle exceptions in the advertise callback. If
advertise fails no NPN is advertised to the client. | tests/test_ssl.py | test_npn_advertise_error | dholth/pyopenssl | python | def test_npn_advertise_error(self):
'\n Test that we can handle exceptions in the advertise callback. If\n advertise fails no NPN is advertised to the client.\n '
select_args = []
def advertise(conn):
raise TypeError
def select(conn, options):
'\n Assert later that no args are actually appended.\n '
select_args.append((conn, options))
return b
server_context = Context(TLSv1_METHOD)
server_context.set_npn_advertise_callback(advertise)
client_context = Context(TLSv1_METHOD)
client_context.set_npn_select_callback(select)
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_context, None)
server.set_accept_state()
client = Connection(client_context, None)
client.set_connect_state()
with pytest.raises(TypeError):
interact_in_memory(server, client)
assert (select_args == []) |
def test_construction(self):
'\n :py:class:`Session` can be constructed with no arguments, creating\n a new instance of that type.\n '
new_session = Session()
assert isinstance(new_session, Session) | 6,984,236,910,717,907,000 | :py:class:`Session` can be constructed with no arguments, creating
a new instance of that type. | tests/test_ssl.py | test_construction | dholth/pyopenssl | python | def test_construction(self):
'\n :py:class:`Session` can be constructed with no arguments, creating\n a new instance of that type.\n '
new_session = Session()
assert isinstance(new_session, Session) |
def test_type(self):
'\n `Connection` can be used to create instances of that type.\n '
ctx = Context(TLSv1_METHOD)
assert is_consistent_type(Connection, 'Connection', ctx, None) | 652,797,790,383,701,100 | `Connection` can be used to create instances of that type. | tests/test_ssl.py | test_type | dholth/pyopenssl | python | def test_type(self):
'\n \n '
ctx = Context(TLSv1_METHOD)
assert is_consistent_type(Connection, 'Connection', ctx, None) |
@pytest.mark.parametrize('bad_context', [object(), 'context', None, 1])
def test_wrong_args(self, bad_context):
'\n `Connection.__init__` raises `TypeError` if called with a non-`Context`\n instance argument.\n '
with pytest.raises(TypeError):
Connection(bad_context) | 5,691,032,112,888,004,000 | `Connection.__init__` raises `TypeError` if called with a non-`Context`
instance argument. | tests/test_ssl.py | test_wrong_args | dholth/pyopenssl | python | @pytest.mark.parametrize('bad_context', [object(), 'context', None, 1])
def test_wrong_args(self, bad_context):
'\n `Connection.__init__` raises `TypeError` if called with a non-`Context`\n instance argument.\n '
with pytest.raises(TypeError):
Connection(bad_context) |
def test_get_context(self):
'\n `Connection.get_context` returns the `Context` instance used to\n construct the `Connection` instance.\n '
context = Context(TLSv1_METHOD)
connection = Connection(context, None)
assert (connection.get_context() is context) | 4,736,040,770,102,418,000 | `Connection.get_context` returns the `Context` instance used to
construct the `Connection` instance. | tests/test_ssl.py | test_get_context | dholth/pyopenssl | python | def test_get_context(self):
'\n `Connection.get_context` returns the `Context` instance used to\n construct the `Connection` instance.\n '
context = Context(TLSv1_METHOD)
connection = Connection(context, None)
assert (connection.get_context() is context) |
def test_set_context_wrong_args(self):
'\n `Connection.set_context` raises `TypeError` if called with a\n non-`Context` instance argument.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
with pytest.raises(TypeError):
connection.set_context(object())
with pytest.raises(TypeError):
connection.set_context('hello')
with pytest.raises(TypeError):
connection.set_context(1)
assert (ctx is connection.get_context()) | 6,770,888,983,827,130,000 | `Connection.set_context` raises `TypeError` if called with a
non-`Context` instance argument. | tests/test_ssl.py | test_set_context_wrong_args | dholth/pyopenssl | python | def test_set_context_wrong_args(self):
'\n `Connection.set_context` raises `TypeError` if called with a\n non-`Context` instance argument.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
with pytest.raises(TypeError):
connection.set_context(object())
with pytest.raises(TypeError):
connection.set_context('hello')
with pytest.raises(TypeError):
connection.set_context(1)
assert (ctx is connection.get_context()) |
def test_set_context(self):
'\n `Connection.set_context` specifies a new `Context` instance to be\n used for the connection.\n '
original = Context(SSLv23_METHOD)
replacement = Context(TLSv1_METHOD)
connection = Connection(original, None)
connection.set_context(replacement)
assert (replacement is connection.get_context())
del original, replacement
collect() | 5,856,765,389,990,803,000 | `Connection.set_context` specifies a new `Context` instance to be
used for the connection. | tests/test_ssl.py | test_set_context | dholth/pyopenssl | python | def test_set_context(self):
'\n `Connection.set_context` specifies a new `Context` instance to be\n used for the connection.\n '
original = Context(SSLv23_METHOD)
replacement = Context(TLSv1_METHOD)
connection = Connection(original, None)
connection.set_context(replacement)
assert (replacement is connection.get_context())
del original, replacement
collect() |
def test_set_tlsext_host_name_wrong_args(self):
'\n If `Connection.set_tlsext_host_name` is called with a non-byte string\n argument or a byte string with an embedded NUL, `TypeError` is raised.\n '
conn = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
conn.set_tlsext_host_name(object())
with pytest.raises(TypeError):
conn.set_tlsext_host_name(b'with\x00null')
if PY3:
with pytest.raises(TypeError):
conn.set_tlsext_host_name(b'example.com'.decode('ascii')) | -3,670,204,330,675,529,000 | If `Connection.set_tlsext_host_name` is called with a non-byte string
argument or a byte string with an embedded NUL, `TypeError` is raised. | tests/test_ssl.py | test_set_tlsext_host_name_wrong_args | dholth/pyopenssl | python | def test_set_tlsext_host_name_wrong_args(self):
'\n If `Connection.set_tlsext_host_name` is called with a non-byte string\n argument or a byte string with an embedded NUL, `TypeError` is raised.\n '
conn = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
conn.set_tlsext_host_name(object())
with pytest.raises(TypeError):
conn.set_tlsext_host_name(b'with\x00null')
if PY3:
with pytest.raises(TypeError):
conn.set_tlsext_host_name(b'example.com'.decode('ascii')) |
def test_pending(self):
'\n `Connection.pending` returns the number of bytes available for\n immediate read.\n '
connection = Connection(Context(TLSv1_METHOD), None)
assert (connection.pending() == 0) | 93,891,541,854,131,150 | `Connection.pending` returns the number of bytes available for
immediate read. | tests/test_ssl.py | test_pending | dholth/pyopenssl | python | def test_pending(self):
'\n `Connection.pending` returns the number of bytes available for\n immediate read.\n '
connection = Connection(Context(TLSv1_METHOD), None)
assert (connection.pending() == 0) |
def test_peek(self):
'\n `Connection.recv` peeks into the connection if `socket.MSG_PEEK` is\n passed.\n '
(server, client) = loopback()
server.send(b'xy')
assert (client.recv(2, MSG_PEEK) == b'xy')
assert (client.recv(2, MSG_PEEK) == b'xy')
assert (client.recv(2) == b'xy') | 8,617,720,627,427,954,000 | `Connection.recv` peeks into the connection if `socket.MSG_PEEK` is
passed. | tests/test_ssl.py | test_peek | dholth/pyopenssl | python | def test_peek(self):
'\n `Connection.recv` peeks into the connection if `socket.MSG_PEEK` is\n passed.\n '
(server, client) = loopback()
server.send(b'xy')
assert (client.recv(2, MSG_PEEK) == b'xy')
assert (client.recv(2, MSG_PEEK) == b'xy')
assert (client.recv(2) == b'xy') |
def test_connect_wrong_args(self):
'\n `Connection.connect` raises `TypeError` if called with a non-address\n argument.\n '
connection = Connection(Context(TLSv1_METHOD), socket_any_family())
with pytest.raises(TypeError):
connection.connect(None) | -2,210,274,935,018,570,000 | `Connection.connect` raises `TypeError` if called with a non-address
argument. | tests/test_ssl.py | test_connect_wrong_args | dholth/pyopenssl | python | def test_connect_wrong_args(self):
'\n `Connection.connect` raises `TypeError` if called with a non-address\n argument.\n '
connection = Connection(Context(TLSv1_METHOD), socket_any_family())
with pytest.raises(TypeError):
connection.connect(None) |
def test_connect_refused(self):
'\n `Connection.connect` raises `socket.error` if the underlying socket\n connect method raises it.\n '
client = socket_any_family()
context = Context(TLSv1_METHOD)
clientSSL = Connection(context, client)
try:
clientSSL.connect((loopback_address(client), 1))
except error as e:
exc = e
assert (exc.args[0] == ECONNREFUSED) | 5,576,465,362,620,610,000 | `Connection.connect` raises `socket.error` if the underlying socket
connect method raises it. | tests/test_ssl.py | test_connect_refused | dholth/pyopenssl | python | def test_connect_refused(self):
'\n `Connection.connect` raises `socket.error` if the underlying socket\n connect method raises it.\n '
client = socket_any_family()
context = Context(TLSv1_METHOD)
clientSSL = Connection(context, client)
try:
clientSSL.connect((loopback_address(client), 1))
except error as e:
exc = e
assert (exc.args[0] == ECONNREFUSED) |
def test_connect(self):
'\n `Connection.connect` establishes a connection to the specified address.\n '
port = socket_any_family()
port.bind(('', 0))
port.listen(3)
clientSSL = Connection(Context(TLSv1_METHOD), socket(port.family))
clientSSL.connect((loopback_address(port), port.getsockname()[1])) | -425,141,833,919,417,700 | `Connection.connect` establishes a connection to the specified address. | tests/test_ssl.py | test_connect | dholth/pyopenssl | python | def test_connect(self):
'\n \n '
port = socket_any_family()
port.bind((, 0))
port.listen(3)
clientSSL = Connection(Context(TLSv1_METHOD), socket(port.family))
clientSSL.connect((loopback_address(port), port.getsockname()[1])) |
@pytest.mark.skipif((platform == 'darwin'), reason='connect_ex sometimes causes a kernel panic on OS X 10.6.4')
def test_connect_ex(self):
'\n If there is a connection error, `Connection.connect_ex` returns the\n errno instead of raising an exception.\n '
port = socket_any_family()
port.bind(('', 0))
port.listen(3)
clientSSL = Connection(Context(TLSv1_METHOD), socket(port.family))
clientSSL.setblocking(False)
result = clientSSL.connect_ex(port.getsockname())
expected = (EINPROGRESS, EWOULDBLOCK)
assert (result in expected) | 5,249,352,153,172,888,000 | If there is a connection error, `Connection.connect_ex` returns the
errno instead of raising an exception. | tests/test_ssl.py | test_connect_ex | dholth/pyopenssl | python | @pytest.mark.skipif((platform == 'darwin'), reason='connect_ex sometimes causes a kernel panic on OS X 10.6.4')
def test_connect_ex(self):
'\n If there is a connection error, `Connection.connect_ex` returns the\n errno instead of raising an exception.\n '
port = socket_any_family()
port.bind((, 0))
port.listen(3)
clientSSL = Connection(Context(TLSv1_METHOD), socket(port.family))
clientSSL.setblocking(False)
result = clientSSL.connect_ex(port.getsockname())
expected = (EINPROGRESS, EWOULDBLOCK)
assert (result in expected) |
def test_accept(self):
'\n `Connection.accept` accepts a pending connection attempt and returns a\n tuple of a new `Connection` (the accepted client) and the address the\n connection originated from.\n '
ctx = Context(TLSv1_METHOD)
ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
port = socket_any_family()
portSSL = Connection(ctx, port)
portSSL.bind(('', 0))
portSSL.listen(3)
clientSSL = Connection(Context(TLSv1_METHOD), socket(port.family))
clientSSL.connect((loopback_address(port), portSSL.getsockname()[1]))
(serverSSL, address) = portSSL.accept()
assert isinstance(serverSSL, Connection)
assert (serverSSL.get_context() is ctx)
assert (address == clientSSL.getsockname()) | -620,361,693,262,021,600 | `Connection.accept` accepts a pending connection attempt and returns a
tuple of a new `Connection` (the accepted client) and the address the
connection originated from. | tests/test_ssl.py | test_accept | dholth/pyopenssl | python | def test_accept(self):
'\n `Connection.accept` accepts a pending connection attempt and returns a\n tuple of a new `Connection` (the accepted client) and the address the\n connection originated from.\n '
ctx = Context(TLSv1_METHOD)
ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
port = socket_any_family()
portSSL = Connection(ctx, port)
portSSL.bind((, 0))
portSSL.listen(3)
clientSSL = Connection(Context(TLSv1_METHOD), socket(port.family))
clientSSL.connect((loopback_address(port), portSSL.getsockname()[1]))
(serverSSL, address) = portSSL.accept()
assert isinstance(serverSSL, Connection)
assert (serverSSL.get_context() is ctx)
assert (address == clientSSL.getsockname()) |
def test_shutdown_wrong_args(self):
'\n `Connection.set_shutdown` raises `TypeError` if called with arguments\n other than integers.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
connection.set_shutdown(None) | -8,616,250,389,986,990,000 | `Connection.set_shutdown` raises `TypeError` if called with arguments
other than integers. | tests/test_ssl.py | test_shutdown_wrong_args | dholth/pyopenssl | python | def test_shutdown_wrong_args(self):
'\n `Connection.set_shutdown` raises `TypeError` if called with arguments\n other than integers.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
connection.set_shutdown(None) |
def test_shutdown(self):
'\n `Connection.shutdown` performs an SSL-level connection shutdown.\n '
(server, client) = loopback()
assert (not server.shutdown())
assert (server.get_shutdown() == SENT_SHUTDOWN)
with pytest.raises(ZeroReturnError):
client.recv(1024)
assert (client.get_shutdown() == RECEIVED_SHUTDOWN)
client.shutdown()
assert (client.get_shutdown() == (SENT_SHUTDOWN | RECEIVED_SHUTDOWN))
with pytest.raises(ZeroReturnError):
server.recv(1024)
assert (server.get_shutdown() == (SENT_SHUTDOWN | RECEIVED_SHUTDOWN)) | 1,399,940,264,286,866,200 | `Connection.shutdown` performs an SSL-level connection shutdown. | tests/test_ssl.py | test_shutdown | dholth/pyopenssl | python | def test_shutdown(self):
'\n \n '
(server, client) = loopback()
assert (not server.shutdown())
assert (server.get_shutdown() == SENT_SHUTDOWN)
with pytest.raises(ZeroReturnError):
client.recv(1024)
assert (client.get_shutdown() == RECEIVED_SHUTDOWN)
client.shutdown()
assert (client.get_shutdown() == (SENT_SHUTDOWN | RECEIVED_SHUTDOWN))
with pytest.raises(ZeroReturnError):
server.recv(1024)
assert (server.get_shutdown() == (SENT_SHUTDOWN | RECEIVED_SHUTDOWN)) |
def test_shutdown_closed(self):
'\n If the underlying socket is closed, `Connection.shutdown` propagates\n the write error from the low level write call.\n '
(server, client) = loopback()
server.sock_shutdown(2)
with pytest.raises(SysCallError) as exc:
server.shutdown()
if (platform == 'win32'):
assert (exc.value.args[0] == ESHUTDOWN)
else:
assert (exc.value.args[0] == EPIPE) | -2,498,414,803,692,511,700 | If the underlying socket is closed, `Connection.shutdown` propagates
the write error from the low level write call. | tests/test_ssl.py | test_shutdown_closed | dholth/pyopenssl | python | def test_shutdown_closed(self):
'\n If the underlying socket is closed, `Connection.shutdown` propagates\n the write error from the low level write call.\n '
(server, client) = loopback()
server.sock_shutdown(2)
with pytest.raises(SysCallError) as exc:
server.shutdown()
if (platform == 'win32'):
assert (exc.value.args[0] == ESHUTDOWN)
else:
assert (exc.value.args[0] == EPIPE) |
def test_shutdown_truncated(self):
'\n If the underlying connection is truncated, `Connection.shutdown`\n raises an `Error`.\n '
server_ctx = Context(TLSv1_METHOD)
client_ctx = Context(TLSv1_METHOD)
server_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_ctx, None)
client = Connection(client_ctx, None)
handshake_in_memory(client, server)
assert (not server.shutdown())
with pytest.raises(WantReadError):
server.shutdown()
server.bio_shutdown()
with pytest.raises(Error):
server.shutdown() | 2,475,407,596,507,121,000 | If the underlying connection is truncated, `Connection.shutdown`
raises an `Error`. | tests/test_ssl.py | test_shutdown_truncated | dholth/pyopenssl | python | def test_shutdown_truncated(self):
'\n If the underlying connection is truncated, `Connection.shutdown`\n raises an `Error`.\n '
server_ctx = Context(TLSv1_METHOD)
client_ctx = Context(TLSv1_METHOD)
server_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(server_ctx, None)
client = Connection(client_ctx, None)
handshake_in_memory(client, server)
assert (not server.shutdown())
with pytest.raises(WantReadError):
server.shutdown()
server.bio_shutdown()
with pytest.raises(Error):
server.shutdown() |
def test_set_shutdown(self):
'\n `Connection.set_shutdown` sets the state of the SSL connection\n shutdown process.\n '
connection = Connection(Context(TLSv1_METHOD), socket_any_family())
connection.set_shutdown(RECEIVED_SHUTDOWN)
assert (connection.get_shutdown() == RECEIVED_SHUTDOWN) | -2,691,461,206,403,454,500 | `Connection.set_shutdown` sets the state of the SSL connection
shutdown process. | tests/test_ssl.py | test_set_shutdown | dholth/pyopenssl | python | def test_set_shutdown(self):
'\n `Connection.set_shutdown` sets the state of the SSL connection\n shutdown process.\n '
connection = Connection(Context(TLSv1_METHOD), socket_any_family())
connection.set_shutdown(RECEIVED_SHUTDOWN)
assert (connection.get_shutdown() == RECEIVED_SHUTDOWN) |
def test_state_string(self):
'\n `Connection.state_string` verbosely describes the current state of\n the `Connection`.\n '
(server, client) = socket_pair()
server = loopback_server_factory(server)
client = loopback_client_factory(client)
assert (server.get_state_string() in [b'before/accept initialization', b'before SSL initialization'])
assert (client.get_state_string() in [b'before/connect initialization', b'before SSL initialization']) | 8,238,737,700,891,792,000 | `Connection.state_string` verbosely describes the current state of
the `Connection`. | tests/test_ssl.py | test_state_string | dholth/pyopenssl | python | def test_state_string(self):
'\n `Connection.state_string` verbosely describes the current state of\n the `Connection`.\n '
(server, client) = socket_pair()
server = loopback_server_factory(server)
client = loopback_client_factory(client)
assert (server.get_state_string() in [b'before/accept initialization', b'before SSL initialization'])
assert (client.get_state_string() in [b'before/connect initialization', b'before SSL initialization']) |
def test_app_data(self):
'\n Any object can be set as app data by passing it to\n `Connection.set_app_data` and later retrieved with\n `Connection.get_app_data`.\n '
conn = Connection(Context(TLSv1_METHOD), None)
assert (None is conn.get_app_data())
app_data = object()
conn.set_app_data(app_data)
assert (conn.get_app_data() is app_data) | 1,996,729,472,457,138,700 | Any object can be set as app data by passing it to
`Connection.set_app_data` and later retrieved with
`Connection.get_app_data`. | tests/test_ssl.py | test_app_data | dholth/pyopenssl | python | def test_app_data(self):
'\n Any object can be set as app data by passing it to\n `Connection.set_app_data` and later retrieved with\n `Connection.get_app_data`.\n '
conn = Connection(Context(TLSv1_METHOD), None)
assert (None is conn.get_app_data())
app_data = object()
conn.set_app_data(app_data)
assert (conn.get_app_data() is app_data) |
def test_makefile(self):
'\n `Connection.makefile` is not implemented and calling that\n method raises `NotImplementedError`.\n '
conn = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(NotImplementedError):
conn.makefile() | 2,058,243,275,561,620,500 | `Connection.makefile` is not implemented and calling that
method raises `NotImplementedError`. | tests/test_ssl.py | test_makefile | dholth/pyopenssl | python | def test_makefile(self):
'\n `Connection.makefile` is not implemented and calling that\n method raises `NotImplementedError`.\n '
conn = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(NotImplementedError):
conn.makefile() |
def test_get_certificate(self):
'\n `Connection.get_certificate` returns the local certificate.\n '
chain = _create_certificate_chain()
[(cakey, cacert), (ikey, icert), (skey, scert)] = chain
context = Context(TLSv1_METHOD)
context.use_certificate(scert)
client = Connection(context, None)
cert = client.get_certificate()
assert (cert is not None)
assert ('Server Certificate' == cert.get_subject().CN) | -6,192,889,625,921,918,000 | `Connection.get_certificate` returns the local certificate. | tests/test_ssl.py | test_get_certificate | dholth/pyopenssl | python | def test_get_certificate(self):
'\n \n '
chain = _create_certificate_chain()
[(cakey, cacert), (ikey, icert), (skey, scert)] = chain
context = Context(TLSv1_METHOD)
context.use_certificate(scert)
client = Connection(context, None)
cert = client.get_certificate()
assert (cert is not None)
assert ('Server Certificate' == cert.get_subject().CN) |
def test_get_certificate_none(self):
'\n `Connection.get_certificate` returns the local certificate.\n\n If there is no certificate, it returns None.\n '
context = Context(TLSv1_METHOD)
client = Connection(context, None)
cert = client.get_certificate()
assert (cert is None) | 1,166,728,942,482,762,800 | `Connection.get_certificate` returns the local certificate.
If there is no certificate, it returns None. | tests/test_ssl.py | test_get_certificate_none | dholth/pyopenssl | python | def test_get_certificate_none(self):
'\n `Connection.get_certificate` returns the local certificate.\n\n If there is no certificate, it returns None.\n '
context = Context(TLSv1_METHOD)
client = Connection(context, None)
cert = client.get_certificate()
assert (cert is None) |
def test_get_peer_cert_chain(self):
'\n `Connection.get_peer_cert_chain` returns a list of certificates\n which the connected server returned for the certification verification.\n '
chain = _create_certificate_chain()
[(cakey, cacert), (ikey, icert), (skey, scert)] = chain
serverContext = Context(TLSv1_METHOD)
serverContext.use_privatekey(skey)
serverContext.use_certificate(scert)
serverContext.add_extra_chain_cert(icert)
serverContext.add_extra_chain_cert(cacert)
server = Connection(serverContext, None)
server.set_accept_state()
clientContext = Context(TLSv1_METHOD)
clientContext.set_verify(VERIFY_NONE, verify_cb)
client = Connection(clientContext, None)
client.set_connect_state()
interact_in_memory(client, server)
chain = client.get_peer_cert_chain()
assert (len(chain) == 3)
assert ('Server Certificate' == chain[0].get_subject().CN)
assert ('Intermediate Certificate' == chain[1].get_subject().CN)
assert ('Authority Certificate' == chain[2].get_subject().CN) | 7,845,105,189,419,761,000 | `Connection.get_peer_cert_chain` returns a list of certificates
which the connected server returned for the certification verification. | tests/test_ssl.py | test_get_peer_cert_chain | dholth/pyopenssl | python | def test_get_peer_cert_chain(self):
'\n `Connection.get_peer_cert_chain` returns a list of certificates\n which the connected server returned for the certification verification.\n '
chain = _create_certificate_chain()
[(cakey, cacert), (ikey, icert), (skey, scert)] = chain
serverContext = Context(TLSv1_METHOD)
serverContext.use_privatekey(skey)
serverContext.use_certificate(scert)
serverContext.add_extra_chain_cert(icert)
serverContext.add_extra_chain_cert(cacert)
server = Connection(serverContext, None)
server.set_accept_state()
clientContext = Context(TLSv1_METHOD)
clientContext.set_verify(VERIFY_NONE, verify_cb)
client = Connection(clientContext, None)
client.set_connect_state()
interact_in_memory(client, server)
chain = client.get_peer_cert_chain()
assert (len(chain) == 3)
assert ('Server Certificate' == chain[0].get_subject().CN)
assert ('Intermediate Certificate' == chain[1].get_subject().CN)
assert ('Authority Certificate' == chain[2].get_subject().CN) |
def test_get_peer_cert_chain_none(self):
'\n `Connection.get_peer_cert_chain` returns `None` if the peer sends\n no certificate chain.\n '
ctx = Context(TLSv1_METHOD)
ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(ctx, None)
server.set_accept_state()
client = Connection(Context(TLSv1_METHOD), None)
client.set_connect_state()
interact_in_memory(client, server)
assert (None is server.get_peer_cert_chain()) | -5,859,669,756,524,772,000 | `Connection.get_peer_cert_chain` returns `None` if the peer sends
no certificate chain. | tests/test_ssl.py | test_get_peer_cert_chain_none | dholth/pyopenssl | python | def test_get_peer_cert_chain_none(self):
'\n `Connection.get_peer_cert_chain` returns `None` if the peer sends\n no certificate chain.\n '
ctx = Context(TLSv1_METHOD)
ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server = Connection(ctx, None)
server.set_accept_state()
client = Connection(Context(TLSv1_METHOD), None)
client.set_connect_state()
interact_in_memory(client, server)
assert (None is server.get_peer_cert_chain()) |
def test_get_session_unconnected(self):
'\n `Connection.get_session` returns `None` when used with an object\n which has not been connected.\n '
ctx = Context(TLSv1_METHOD)
server = Connection(ctx, None)
session = server.get_session()
assert (None is session) | 5,349,677,433,687,950,000 | `Connection.get_session` returns `None` when used with an object
which has not been connected. | tests/test_ssl.py | test_get_session_unconnected | dholth/pyopenssl | python | def test_get_session_unconnected(self):
'\n `Connection.get_session` returns `None` when used with an object\n which has not been connected.\n '
ctx = Context(TLSv1_METHOD)
server = Connection(ctx, None)
session = server.get_session()
assert (None is session) |
def test_server_get_session(self):
'\n On the server side of a connection, `Connection.get_session` returns a\n `Session` instance representing the SSL session for that connection.\n '
(server, client) = loopback()
session = server.get_session()
assert isinstance(session, Session) | 8,833,901,226,784,040,000 | On the server side of a connection, `Connection.get_session` returns a
`Session` instance representing the SSL session for that connection. | tests/test_ssl.py | test_server_get_session | dholth/pyopenssl | python | def test_server_get_session(self):
'\n On the server side of a connection, `Connection.get_session` returns a\n `Session` instance representing the SSL session for that connection.\n '
(server, client) = loopback()
session = server.get_session()
assert isinstance(session, Session) |
def test_client_get_session(self):
'\n On the client side of a connection, `Connection.get_session`\n returns a `Session` instance representing the SSL session for\n that connection.\n '
(server, client) = loopback()
session = client.get_session()
assert isinstance(session, Session) | 2,301,864,345,458,671,600 | On the client side of a connection, `Connection.get_session`
returns a `Session` instance representing the SSL session for
that connection. | tests/test_ssl.py | test_client_get_session | dholth/pyopenssl | python | def test_client_get_session(self):
'\n On the client side of a connection, `Connection.get_session`\n returns a `Session` instance representing the SSL session for\n that connection.\n '
(server, client) = loopback()
session = client.get_session()
assert isinstance(session, Session) |
def test_set_session_wrong_args(self):
'\n `Connection.set_session` raises `TypeError` if called with an object\n that is not an instance of `Session`.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
with pytest.raises(TypeError):
connection.set_session(123)
with pytest.raises(TypeError):
connection.set_session('hello')
with pytest.raises(TypeError):
connection.set_session(object()) | -7,422,918,937,271,925,000 | `Connection.set_session` raises `TypeError` if called with an object
that is not an instance of `Session`. | tests/test_ssl.py | test_set_session_wrong_args | dholth/pyopenssl | python | def test_set_session_wrong_args(self):
'\n `Connection.set_session` raises `TypeError` if called with an object\n that is not an instance of `Session`.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
with pytest.raises(TypeError):
connection.set_session(123)
with pytest.raises(TypeError):
connection.set_session('hello')
with pytest.raises(TypeError):
connection.set_session(object()) |
def test_client_set_session(self):
'\n `Connection.set_session`, when used prior to a connection being\n established, accepts a `Session` instance and causes an attempt to\n re-use the session it represents when the SSL handshake is performed.\n '
key = load_privatekey(FILETYPE_PEM, server_key_pem)
cert = load_certificate(FILETYPE_PEM, server_cert_pem)
ctx = Context(TLSv1_2_METHOD)
ctx.use_privatekey(key)
ctx.use_certificate(cert)
ctx.set_session_id('unity-test')
def makeServer(socket):
server = Connection(ctx, socket)
server.set_accept_state()
return server
(originalServer, originalClient) = loopback(server_factory=makeServer)
originalSession = originalClient.get_session()
def makeClient(socket):
client = loopback_client_factory(socket)
client.set_session(originalSession)
return client
(resumedServer, resumedClient) = loopback(server_factory=makeServer, client_factory=makeClient)
assert (originalServer.master_key() == resumedServer.master_key()) | -9,079,379,991,901,050,000 | `Connection.set_session`, when used prior to a connection being
established, accepts a `Session` instance and causes an attempt to
re-use the session it represents when the SSL handshake is performed. | tests/test_ssl.py | test_client_set_session | dholth/pyopenssl | python | def test_client_set_session(self):
'\n `Connection.set_session`, when used prior to a connection being\n established, accepts a `Session` instance and causes an attempt to\n re-use the session it represents when the SSL handshake is performed.\n '
key = load_privatekey(FILETYPE_PEM, server_key_pem)
cert = load_certificate(FILETYPE_PEM, server_cert_pem)
ctx = Context(TLSv1_2_METHOD)
ctx.use_privatekey(key)
ctx.use_certificate(cert)
ctx.set_session_id('unity-test')
def makeServer(socket):
server = Connection(ctx, socket)
server.set_accept_state()
return server
(originalServer, originalClient) = loopback(server_factory=makeServer)
originalSession = originalClient.get_session()
def makeClient(socket):
client = loopback_client_factory(socket)
client.set_session(originalSession)
return client
(resumedServer, resumedClient) = loopback(server_factory=makeServer, client_factory=makeClient)
assert (originalServer.master_key() == resumedServer.master_key()) |
def test_set_session_wrong_method(self):
'\n If `Connection.set_session` is passed a `Session` instance associated\n with a context using a different SSL method than the `Connection`\n is using, a `OpenSSL.SSL.Error` is raised.\n '
if (SSL_ST_INIT is None):
v1 = TLSv1_2_METHOD
v2 = TLSv1_METHOD
elif hasattr(_lib, 'SSLv3_method'):
v1 = TLSv1_METHOD
v2 = SSLv3_METHOD
else:
pytest.skip('Test requires either OpenSSL 1.1.0 or SSLv3')
key = load_privatekey(FILETYPE_PEM, server_key_pem)
cert = load_certificate(FILETYPE_PEM, server_cert_pem)
ctx = Context(v1)
ctx.use_privatekey(key)
ctx.use_certificate(cert)
ctx.set_session_id('unity-test')
def makeServer(socket):
server = Connection(ctx, socket)
server.set_accept_state()
return server
def makeOriginalClient(socket):
client = Connection(Context(v1), socket)
client.set_connect_state()
return client
(originalServer, originalClient) = loopback(server_factory=makeServer, client_factory=makeOriginalClient)
originalSession = originalClient.get_session()
def makeClient(socket):
client = Connection(Context(v2), socket)
client.set_connect_state()
client.set_session(originalSession)
return client
with pytest.raises(Error):
loopback(client_factory=makeClient, server_factory=makeServer) | 4,710,453,173,124,289,000 | If `Connection.set_session` is passed a `Session` instance associated
with a context using a different SSL method than the `Connection`
is using, a `OpenSSL.SSL.Error` is raised. | tests/test_ssl.py | test_set_session_wrong_method | dholth/pyopenssl | python | def test_set_session_wrong_method(self):
'\n If `Connection.set_session` is passed a `Session` instance associated\n with a context using a different SSL method than the `Connection`\n is using, a `OpenSSL.SSL.Error` is raised.\n '
if (SSL_ST_INIT is None):
v1 = TLSv1_2_METHOD
v2 = TLSv1_METHOD
elif hasattr(_lib, 'SSLv3_method'):
v1 = TLSv1_METHOD
v2 = SSLv3_METHOD
else:
pytest.skip('Test requires either OpenSSL 1.1.0 or SSLv3')
key = load_privatekey(FILETYPE_PEM, server_key_pem)
cert = load_certificate(FILETYPE_PEM, server_cert_pem)
ctx = Context(v1)
ctx.use_privatekey(key)
ctx.use_certificate(cert)
ctx.set_session_id('unity-test')
def makeServer(socket):
server = Connection(ctx, socket)
server.set_accept_state()
return server
def makeOriginalClient(socket):
client = Connection(Context(v1), socket)
client.set_connect_state()
return client
(originalServer, originalClient) = loopback(server_factory=makeServer, client_factory=makeOriginalClient)
originalSession = originalClient.get_session()
def makeClient(socket):
client = Connection(Context(v2), socket)
client.set_connect_state()
client.set_session(originalSession)
return client
with pytest.raises(Error):
loopback(client_factory=makeClient, server_factory=makeServer) |
def test_wantWriteError(self):
"\n `Connection` methods which generate output raise\n `OpenSSL.SSL.WantWriteError` if writing to the connection's BIO\n fail indicating a should-write state.\n "
(client_socket, server_socket) = socket_pair()
msg = b'x'
for i in range(((1024 * 1024) * 64)):
try:
client_socket.send(msg)
except error as e:
if (e.errno == EWOULDBLOCK):
break
raise
else:
pytest.fail('Failed to fill socket buffer, cannot test BIO want write')
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, client_socket)
conn.set_connect_state()
with pytest.raises(WantWriteError):
conn.do_handshake() | 7,334,885,429,630,164,000 | `Connection` methods which generate output raise
`OpenSSL.SSL.WantWriteError` if writing to the connection's BIO
fail indicating a should-write state. | tests/test_ssl.py | test_wantWriteError | dholth/pyopenssl | python | def test_wantWriteError(self):
"\n `Connection` methods which generate output raise\n `OpenSSL.SSL.WantWriteError` if writing to the connection's BIO\n fail indicating a should-write state.\n "
(client_socket, server_socket) = socket_pair()
msg = b'x'
for i in range(((1024 * 1024) * 64)):
try:
client_socket.send(msg)
except error as e:
if (e.errno == EWOULDBLOCK):
break
raise
else:
pytest.fail('Failed to fill socket buffer, cannot test BIO want write')
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, client_socket)
conn.set_connect_state()
with pytest.raises(WantWriteError):
conn.do_handshake() |
def test_get_finished_before_connect(self):
'\n `Connection.get_finished` returns `None` before TLS handshake\n is completed.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
assert (connection.get_finished() is None) | 9,126,092,443,534,511,000 | `Connection.get_finished` returns `None` before TLS handshake
is completed. | tests/test_ssl.py | test_get_finished_before_connect | dholth/pyopenssl | python | def test_get_finished_before_connect(self):
'\n `Connection.get_finished` returns `None` before TLS handshake\n is completed.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
assert (connection.get_finished() is None) |
def test_get_peer_finished_before_connect(self):
'\n `Connection.get_peer_finished` returns `None` before TLS handshake\n is completed.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
assert (connection.get_peer_finished() is None) | -3,366,000,095,011,393,000 | `Connection.get_peer_finished` returns `None` before TLS handshake
is completed. | tests/test_ssl.py | test_get_peer_finished_before_connect | dholth/pyopenssl | python | def test_get_peer_finished_before_connect(self):
'\n `Connection.get_peer_finished` returns `None` before TLS handshake\n is completed.\n '
ctx = Context(TLSv1_METHOD)
connection = Connection(ctx, None)
assert (connection.get_peer_finished() is None) |
def test_get_finished(self):
'\n `Connection.get_finished` method returns the TLS Finished message send\n from client, or server. Finished messages are send during\n TLS handshake.\n '
(server, client) = loopback()
assert (server.get_finished() is not None)
assert (len(server.get_finished()) > 0) | -1,208,120,950,504,959,200 | `Connection.get_finished` method returns the TLS Finished message send
from client, or server. Finished messages are send during
TLS handshake. | tests/test_ssl.py | test_get_finished | dholth/pyopenssl | python | def test_get_finished(self):
'\n `Connection.get_finished` method returns the TLS Finished message send\n from client, or server. Finished messages are send during\n TLS handshake.\n '
(server, client) = loopback()
assert (server.get_finished() is not None)
assert (len(server.get_finished()) > 0) |
def test_get_peer_finished(self):
'\n `Connection.get_peer_finished` method returns the TLS Finished\n message received from client, or server. Finished messages are send\n during TLS handshake.\n '
(server, client) = loopback()
assert (server.get_peer_finished() is not None)
assert (len(server.get_peer_finished()) > 0) | 268,347,012,016,209,660 | `Connection.get_peer_finished` method returns the TLS Finished
message received from client, or server. Finished messages are send
during TLS handshake. | tests/test_ssl.py | test_get_peer_finished | dholth/pyopenssl | python | def test_get_peer_finished(self):
'\n `Connection.get_peer_finished` method returns the TLS Finished\n message received from client, or server. Finished messages are send\n during TLS handshake.\n '
(server, client) = loopback()
assert (server.get_peer_finished() is not None)
assert (len(server.get_peer_finished()) > 0) |
def test_tls_finished_message_symmetry(self):
'\n The TLS Finished message send by server must be the TLS Finished\n message received by client.\n\n The TLS Finished message send by client must be the TLS Finished\n message received by server.\n '
(server, client) = loopback()
assert (server.get_finished() == client.get_peer_finished())
assert (client.get_finished() == server.get_peer_finished()) | -2,992,717,976,540,916,000 | The TLS Finished message send by server must be the TLS Finished
message received by client.
The TLS Finished message send by client must be the TLS Finished
message received by server. | tests/test_ssl.py | test_tls_finished_message_symmetry | dholth/pyopenssl | python | def test_tls_finished_message_symmetry(self):
'\n The TLS Finished message send by server must be the TLS Finished\n message received by client.\n\n The TLS Finished message send by client must be the TLS Finished\n message received by server.\n '
(server, client) = loopback()
assert (server.get_finished() == client.get_peer_finished())
assert (client.get_finished() == server.get_peer_finished()) |
def test_get_cipher_name_before_connect(self):
'\n `Connection.get_cipher_name` returns `None` if no connection\n has been established.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
assert (conn.get_cipher_name() is None) | -5,613,082,056,877,053,000 | `Connection.get_cipher_name` returns `None` if no connection
has been established. | tests/test_ssl.py | test_get_cipher_name_before_connect | dholth/pyopenssl | python | def test_get_cipher_name_before_connect(self):
'\n `Connection.get_cipher_name` returns `None` if no connection\n has been established.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
assert (conn.get_cipher_name() is None) |
def test_get_cipher_name(self):
'\n `Connection.get_cipher_name` returns a `unicode` string giving the\n name of the currently used cipher.\n '
(server, client) = loopback()
(server_cipher_name, client_cipher_name) = (server.get_cipher_name(), client.get_cipher_name())
assert isinstance(server_cipher_name, text_type)
assert isinstance(client_cipher_name, text_type)
assert (server_cipher_name == client_cipher_name) | 4,028,798,763,717,018,000 | `Connection.get_cipher_name` returns a `unicode` string giving the
name of the currently used cipher. | tests/test_ssl.py | test_get_cipher_name | dholth/pyopenssl | python | def test_get_cipher_name(self):
'\n `Connection.get_cipher_name` returns a `unicode` string giving the\n name of the currently used cipher.\n '
(server, client) = loopback()
(server_cipher_name, client_cipher_name) = (server.get_cipher_name(), client.get_cipher_name())
assert isinstance(server_cipher_name, text_type)
assert isinstance(client_cipher_name, text_type)
assert (server_cipher_name == client_cipher_name) |
def test_get_cipher_version_before_connect(self):
'\n `Connection.get_cipher_version` returns `None` if no connection\n has been established.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
assert (conn.get_cipher_version() is None) | -5,071,563,579,508,701,000 | `Connection.get_cipher_version` returns `None` if no connection
has been established. | tests/test_ssl.py | test_get_cipher_version_before_connect | dholth/pyopenssl | python | def test_get_cipher_version_before_connect(self):
'\n `Connection.get_cipher_version` returns `None` if no connection\n has been established.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
assert (conn.get_cipher_version() is None) |
def test_get_cipher_version(self):
'\n `Connection.get_cipher_version` returns a `unicode` string giving\n the protocol name of the currently used cipher.\n '
(server, client) = loopback()
(server_cipher_version, client_cipher_version) = (server.get_cipher_version(), client.get_cipher_version())
assert isinstance(server_cipher_version, text_type)
assert isinstance(client_cipher_version, text_type)
assert (server_cipher_version == client_cipher_version) | 212,863,978,780,620,200 | `Connection.get_cipher_version` returns a `unicode` string giving
the protocol name of the currently used cipher. | tests/test_ssl.py | test_get_cipher_version | dholth/pyopenssl | python | def test_get_cipher_version(self):
'\n `Connection.get_cipher_version` returns a `unicode` string giving\n the protocol name of the currently used cipher.\n '
(server, client) = loopback()
(server_cipher_version, client_cipher_version) = (server.get_cipher_version(), client.get_cipher_version())
assert isinstance(server_cipher_version, text_type)
assert isinstance(client_cipher_version, text_type)
assert (server_cipher_version == client_cipher_version) |
def test_get_cipher_bits_before_connect(self):
'\n `Connection.get_cipher_bits` returns `None` if no connection has\n been established.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
assert (conn.get_cipher_bits() is None) | -3,708,169,222,181,823,000 | `Connection.get_cipher_bits` returns `None` if no connection has
been established. | tests/test_ssl.py | test_get_cipher_bits_before_connect | dholth/pyopenssl | python | def test_get_cipher_bits_before_connect(self):
'\n `Connection.get_cipher_bits` returns `None` if no connection has\n been established.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
assert (conn.get_cipher_bits() is None) |
def test_get_cipher_bits(self):
'\n `Connection.get_cipher_bits` returns the number of secret bits\n of the currently used cipher.\n '
(server, client) = loopback()
(server_cipher_bits, client_cipher_bits) = (server.get_cipher_bits(), client.get_cipher_bits())
assert isinstance(server_cipher_bits, int)
assert isinstance(client_cipher_bits, int)
assert (server_cipher_bits == client_cipher_bits) | -1,826,871,895,235,974,700 | `Connection.get_cipher_bits` returns the number of secret bits
of the currently used cipher. | tests/test_ssl.py | test_get_cipher_bits | dholth/pyopenssl | python | def test_get_cipher_bits(self):
'\n `Connection.get_cipher_bits` returns the number of secret bits\n of the currently used cipher.\n '
(server, client) = loopback()
(server_cipher_bits, client_cipher_bits) = (server.get_cipher_bits(), client.get_cipher_bits())
assert isinstance(server_cipher_bits, int)
assert isinstance(client_cipher_bits, int)
assert (server_cipher_bits == client_cipher_bits) |
def test_get_protocol_version_name(self):
'\n `Connection.get_protocol_version_name()` returns a string giving the\n protocol version of the current connection.\n '
(server, client) = loopback()
client_protocol_version_name = client.get_protocol_version_name()
server_protocol_version_name = server.get_protocol_version_name()
assert isinstance(server_protocol_version_name, text_type)
assert isinstance(client_protocol_version_name, text_type)
assert (server_protocol_version_name == client_protocol_version_name) | -4,721,095,345,601,733,000 | `Connection.get_protocol_version_name()` returns a string giving the
protocol version of the current connection. | tests/test_ssl.py | test_get_protocol_version_name | dholth/pyopenssl | python | def test_get_protocol_version_name(self):
'\n `Connection.get_protocol_version_name()` returns a string giving the\n protocol version of the current connection.\n '
(server, client) = loopback()
client_protocol_version_name = client.get_protocol_version_name()
server_protocol_version_name = server.get_protocol_version_name()
assert isinstance(server_protocol_version_name, text_type)
assert isinstance(client_protocol_version_name, text_type)
assert (server_protocol_version_name == client_protocol_version_name) |
def test_get_protocol_version(self):
'\n `Connection.get_protocol_version()` returns an integer\n giving the protocol version of the current connection.\n '
(server, client) = loopback()
client_protocol_version = client.get_protocol_version()
server_protocol_version = server.get_protocol_version()
assert isinstance(server_protocol_version, int)
assert isinstance(client_protocol_version, int)
assert (server_protocol_version == client_protocol_version) | 5,131,787,040,925,947,000 | `Connection.get_protocol_version()` returns an integer
giving the protocol version of the current connection. | tests/test_ssl.py | test_get_protocol_version | dholth/pyopenssl | python | def test_get_protocol_version(self):
'\n `Connection.get_protocol_version()` returns an integer\n giving the protocol version of the current connection.\n '
(server, client) = loopback()
client_protocol_version = client.get_protocol_version()
server_protocol_version = server.get_protocol_version()
assert isinstance(server_protocol_version, int)
assert isinstance(client_protocol_version, int)
assert (server_protocol_version == client_protocol_version) |
def test_wantReadError(self):
'\n `Connection.bio_read` raises `OpenSSL.SSL.WantReadError` if there are\n no bytes available to be read from the BIO.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
with pytest.raises(WantReadError):
conn.bio_read(1024) | 6,247,504,886,640,660,000 | `Connection.bio_read` raises `OpenSSL.SSL.WantReadError` if there are
no bytes available to be read from the BIO. | tests/test_ssl.py | test_wantReadError | dholth/pyopenssl | python | def test_wantReadError(self):
'\n `Connection.bio_read` raises `OpenSSL.SSL.WantReadError` if there are\n no bytes available to be read from the BIO.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
with pytest.raises(WantReadError):
conn.bio_read(1024) |
@pytest.mark.parametrize('bufsize', [1.0, None, object(), 'bufsize'])
def test_bio_read_wrong_args(self, bufsize):
'\n `Connection.bio_read` raises `TypeError` if passed a non-integer\n argument.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
with pytest.raises(TypeError):
conn.bio_read(bufsize) | -4,335,652,884,345,420,000 | `Connection.bio_read` raises `TypeError` if passed a non-integer
argument. | tests/test_ssl.py | test_bio_read_wrong_args | dholth/pyopenssl | python | @pytest.mark.parametrize('bufsize', [1.0, None, object(), 'bufsize'])
def test_bio_read_wrong_args(self, bufsize):
'\n `Connection.bio_read` raises `TypeError` if passed a non-integer\n argument.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
with pytest.raises(TypeError):
conn.bio_read(bufsize) |
def test_buffer_size(self):
'\n `Connection.bio_read` accepts an integer giving the maximum number\n of bytes to read and return.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
conn.set_connect_state()
try:
conn.do_handshake()
except WantReadError:
pass
data = conn.bio_read(2)
assert (2 == len(data)) | 8,963,250,716,023,159,000 | `Connection.bio_read` accepts an integer giving the maximum number
of bytes to read and return. | tests/test_ssl.py | test_buffer_size | dholth/pyopenssl | python | def test_buffer_size(self):
'\n `Connection.bio_read` accepts an integer giving the maximum number\n of bytes to read and return.\n '
ctx = Context(TLSv1_METHOD)
conn = Connection(ctx, None)
conn.set_connect_state()
try:
conn.do_handshake()
except WantReadError:
pass
data = conn.bio_read(2)
assert (2 == len(data)) |
def test_result(self):
'\n `Connection.get_cipher_list` returns a list of `bytes` giving the\n names of the ciphers which might be used.\n '
connection = Connection(Context(TLSv1_METHOD), None)
ciphers = connection.get_cipher_list()
assert isinstance(ciphers, list)
for cipher in ciphers:
assert isinstance(cipher, str) | 532,025,072,530,525,800 | `Connection.get_cipher_list` returns a list of `bytes` giving the
names of the ciphers which might be used. | tests/test_ssl.py | test_result | dholth/pyopenssl | python | def test_result(self):
'\n `Connection.get_cipher_list` returns a list of `bytes` giving the\n names of the ciphers which might be used.\n '
connection = Connection(Context(TLSv1_METHOD), None)
ciphers = connection.get_cipher_list()
assert isinstance(ciphers, list)
for cipher in ciphers:
assert isinstance(cipher, str) |
def test_wrong_args(self):
'\n When called with arguments other than string argument for its first\n parameter, `Connection.send` raises `TypeError`.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
connection.send(object()) | -7,525,469,116,245,044,000 | When called with arguments other than string argument for its first
parameter, `Connection.send` raises `TypeError`. | tests/test_ssl.py | test_wrong_args | dholth/pyopenssl | python | def test_wrong_args(self):
'\n When called with arguments other than string argument for its first\n parameter, `Connection.send` raises `TypeError`.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
connection.send(object()) |
def test_short_bytes(self):
'\n When passed a short byte string, `Connection.send` transmits all of it\n and returns the number of bytes sent.\n '
(server, client) = loopback()
count = server.send(b'xy')
assert (count == 2)
assert (client.recv(2) == b'xy') | 1,048,956,083,346,390,000 | When passed a short byte string, `Connection.send` transmits all of it
and returns the number of bytes sent. | tests/test_ssl.py | test_short_bytes | dholth/pyopenssl | python | def test_short_bytes(self):
'\n When passed a short byte string, `Connection.send` transmits all of it\n and returns the number of bytes sent.\n '
(server, client) = loopback()
count = server.send(b'xy')
assert (count == 2)
assert (client.recv(2) == b'xy') |
def test_text(self):
'\n When passed a text, `Connection.send` transmits all of it and\n returns the number of bytes sent. It also raises a DeprecationWarning.\n '
(server, client) = loopback()
with pytest.warns(DeprecationWarning) as w:
simplefilter('always')
count = server.send(b'xy'.decode('ascii'))
assert ('{0} for buf is no longer accepted, use bytes'.format(WARNING_TYPE_EXPECTED) == str(w[(- 1)].message))
assert (count == 2)
assert (client.recv(2) == b'xy') | 2,554,236,675,302,025,700 | When passed a text, `Connection.send` transmits all of it and
returns the number of bytes sent. It also raises a DeprecationWarning. | tests/test_ssl.py | test_text | dholth/pyopenssl | python | def test_text(self):
'\n When passed a text, `Connection.send` transmits all of it and\n returns the number of bytes sent. It also raises a DeprecationWarning.\n '
(server, client) = loopback()
with pytest.warns(DeprecationWarning) as w:
simplefilter('always')
count = server.send(b'xy'.decode('ascii'))
assert ('{0} for buf is no longer accepted, use bytes'.format(WARNING_TYPE_EXPECTED) == str(w[(- 1)].message))
assert (count == 2)
assert (client.recv(2) == b'xy') |
def test_short_memoryview(self):
'\n When passed a memoryview onto a small number of bytes,\n `Connection.send` transmits all of them and returns the number\n of bytes sent.\n '
(server, client) = loopback()
count = server.send(memoryview(b'xy'))
assert (count == 2)
assert (client.recv(2) == b'xy') | -6,433,162,439,286,371,000 | When passed a memoryview onto a small number of bytes,
`Connection.send` transmits all of them and returns the number
of bytes sent. | tests/test_ssl.py | test_short_memoryview | dholth/pyopenssl | python | def test_short_memoryview(self):
'\n When passed a memoryview onto a small number of bytes,\n `Connection.send` transmits all of them and returns the number\n of bytes sent.\n '
(server, client) = loopback()
count = server.send(memoryview(b'xy'))
assert (count == 2)
assert (client.recv(2) == b'xy') |
@skip_if_py3
def test_short_buffer(self):
'\n When passed a buffer containing a small number of bytes,\n `Connection.send` transmits all of them and returns the number\n of bytes sent.\n '
(server, client) = loopback()
count = server.send(buffer(b'xy'))
assert (count == 2)
assert (client.recv(2) == b'xy') | 3,269,382,447,627,889,700 | When passed a buffer containing a small number of bytes,
`Connection.send` transmits all of them and returns the number
of bytes sent. | tests/test_ssl.py | test_short_buffer | dholth/pyopenssl | python | @skip_if_py3
def test_short_buffer(self):
'\n When passed a buffer containing a small number of bytes,\n `Connection.send` transmits all of them and returns the number\n of bytes sent.\n '
(server, client) = loopback()
count = server.send(buffer(b'xy'))
assert (count == 2)
assert (client.recv(2) == b'xy') |
@pytest.mark.skipif((sys.maxsize < (2 ** 31)), reason='sys.maxsize < 2**31 - test requires 64 bit')
def test_buf_too_large(self):
'\n When passed a buffer containing >= 2**31 bytes,\n `Connection.send` bails out as SSL_write only\n accepts an int for the buffer length.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(ValueError) as exc_info:
connection.send(VeryLarge())
exc_info.match('Cannot send more than .+ bytes at once') | -6,671,784,046,956,094,000 | When passed a buffer containing >= 2**31 bytes,
`Connection.send` bails out as SSL_write only
accepts an int for the buffer length. | tests/test_ssl.py | test_buf_too_large | dholth/pyopenssl | python | @pytest.mark.skipif((sys.maxsize < (2 ** 31)), reason='sys.maxsize < 2**31 - test requires 64 bit')
def test_buf_too_large(self):
'\n When passed a buffer containing >= 2**31 bytes,\n `Connection.send` bails out as SSL_write only\n accepts an int for the buffer length.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(ValueError) as exc_info:
connection.send(VeryLarge())
exc_info.match('Cannot send more than .+ bytes at once') |
def _no_length_test(self, factory):
'\n Assert that when the given buffer is passed to `Connection.recv_into`,\n whatever bytes are available to be received that fit into that buffer\n are written into that buffer.\n '
output_buffer = factory(5)
(server, client) = loopback()
server.send(b'xy')
assert (client.recv_into(output_buffer) == 2)
assert (output_buffer == bytearray(b'xy\x00\x00\x00')) | -224,536,659,506,178,500 | Assert that when the given buffer is passed to `Connection.recv_into`,
whatever bytes are available to be received that fit into that buffer
are written into that buffer. | tests/test_ssl.py | _no_length_test | dholth/pyopenssl | python | def _no_length_test(self, factory):
'\n Assert that when the given buffer is passed to `Connection.recv_into`,\n whatever bytes are available to be received that fit into that buffer\n are written into that buffer.\n '
output_buffer = factory(5)
(server, client) = loopback()
server.send(b'xy')
assert (client.recv_into(output_buffer) == 2)
assert (output_buffer == bytearray(b'xy\x00\x00\x00')) |
def test_bytearray_no_length(self):
'\n `Connection.recv_into` can be passed a `bytearray` instance and data\n in the receive buffer is written to it.\n '
self._no_length_test(bytearray) | -3,500,933,368,787,785,000 | `Connection.recv_into` can be passed a `bytearray` instance and data
in the receive buffer is written to it. | tests/test_ssl.py | test_bytearray_no_length | dholth/pyopenssl | python | def test_bytearray_no_length(self):
'\n `Connection.recv_into` can be passed a `bytearray` instance and data\n in the receive buffer is written to it.\n '
self._no_length_test(bytearray) |
def _respects_length_test(self, factory):
'\n Assert that when the given buffer is passed to `Connection.recv_into`\n along with a value for `nbytes` that is less than the size of that\n buffer, only `nbytes` bytes are written into the buffer.\n '
output_buffer = factory(10)
(server, client) = loopback()
server.send(b'abcdefghij')
assert (client.recv_into(output_buffer, 5) == 5)
assert (output_buffer == bytearray(b'abcde\x00\x00\x00\x00\x00')) | -1,207,612,694,800,051,700 | Assert that when the given buffer is passed to `Connection.recv_into`
along with a value for `nbytes` that is less than the size of that
buffer, only `nbytes` bytes are written into the buffer. | tests/test_ssl.py | _respects_length_test | dholth/pyopenssl | python | def _respects_length_test(self, factory):
'\n Assert that when the given buffer is passed to `Connection.recv_into`\n along with a value for `nbytes` that is less than the size of that\n buffer, only `nbytes` bytes are written into the buffer.\n '
output_buffer = factory(10)
(server, client) = loopback()
server.send(b'abcdefghij')
assert (client.recv_into(output_buffer, 5) == 5)
assert (output_buffer == bytearray(b'abcde\x00\x00\x00\x00\x00')) |
def test_bytearray_respects_length(self):
"\n When called with a `bytearray` instance, `Connection.recv_into`\n respects the `nbytes` parameter and doesn't copy in more than that\n number of bytes.\n "
self._respects_length_test(bytearray) | 3,426,672,612,098,142,000 | When called with a `bytearray` instance, `Connection.recv_into`
respects the `nbytes` parameter and doesn't copy in more than that
number of bytes. | tests/test_ssl.py | test_bytearray_respects_length | dholth/pyopenssl | python | def test_bytearray_respects_length(self):
"\n When called with a `bytearray` instance, `Connection.recv_into`\n respects the `nbytes` parameter and doesn't copy in more than that\n number of bytes.\n "
self._respects_length_test(bytearray) |
def _doesnt_overfill_test(self, factory):
'\n Assert that if there are more bytes available to be read from the\n receive buffer than would fit into the buffer passed to\n `Connection.recv_into`, only as many as fit are written into it.\n '
output_buffer = factory(5)
(server, client) = loopback()
server.send(b'abcdefghij')
assert (client.recv_into(output_buffer) == 5)
assert (output_buffer == bytearray(b'abcde'))
rest = client.recv(5)
assert (b'fghij' == rest) | 6,143,662,272,151,547,000 | Assert that if there are more bytes available to be read from the
receive buffer than would fit into the buffer passed to
`Connection.recv_into`, only as many as fit are written into it. | tests/test_ssl.py | _doesnt_overfill_test | dholth/pyopenssl | python | def _doesnt_overfill_test(self, factory):
'\n Assert that if there are more bytes available to be read from the\n receive buffer than would fit into the buffer passed to\n `Connection.recv_into`, only as many as fit are written into it.\n '
output_buffer = factory(5)
(server, client) = loopback()
server.send(b'abcdefghij')
assert (client.recv_into(output_buffer) == 5)
assert (output_buffer == bytearray(b'abcde'))
rest = client.recv(5)
assert (b'fghij' == rest) |
def test_bytearray_doesnt_overfill(self):
"\n When called with a `bytearray` instance, `Connection.recv_into`\n respects the size of the array and doesn't write more bytes into it\n than will fit.\n "
self._doesnt_overfill_test(bytearray) | -162,277,799,067,712,130 | When called with a `bytearray` instance, `Connection.recv_into`
respects the size of the array and doesn't write more bytes into it
than will fit. | tests/test_ssl.py | test_bytearray_doesnt_overfill | dholth/pyopenssl | python | def test_bytearray_doesnt_overfill(self):
"\n When called with a `bytearray` instance, `Connection.recv_into`\n respects the size of the array and doesn't write more bytes into it\n than will fit.\n "
self._doesnt_overfill_test(bytearray) |
def test_bytearray_really_doesnt_overfill(self):
"\n When called with a `bytearray` instance and an `nbytes` value that is\n too large, `Connection.recv_into` respects the size of the array and\n not the `nbytes` value and doesn't write more bytes into the buffer\n than will fit.\n "
self._doesnt_overfill_test(bytearray) | -436,622,637,745,667,600 | When called with a `bytearray` instance and an `nbytes` value that is
too large, `Connection.recv_into` respects the size of the array and
not the `nbytes` value and doesn't write more bytes into the buffer
than will fit. | tests/test_ssl.py | test_bytearray_really_doesnt_overfill | dholth/pyopenssl | python | def test_bytearray_really_doesnt_overfill(self):
"\n When called with a `bytearray` instance and an `nbytes` value that is\n too large, `Connection.recv_into` respects the size of the array and\n not the `nbytes` value and doesn't write more bytes into the buffer\n than will fit.\n "
self._doesnt_overfill_test(bytearray) |
def test_memoryview_no_length(self):
'\n `Connection.recv_into` can be passed a `memoryview` instance and data\n in the receive buffer is written to it.\n '
self._no_length_test(_make_memoryview) | 6,115,750,695,087,446,000 | `Connection.recv_into` can be passed a `memoryview` instance and data
in the receive buffer is written to it. | tests/test_ssl.py | test_memoryview_no_length | dholth/pyopenssl | python | def test_memoryview_no_length(self):
'\n `Connection.recv_into` can be passed a `memoryview` instance and data\n in the receive buffer is written to it.\n '
self._no_length_test(_make_memoryview) |
def test_memoryview_respects_length(self):
"\n When called with a `memoryview` instance, `Connection.recv_into`\n respects the ``nbytes`` parameter and doesn't copy more than that\n number of bytes in.\n "
self._respects_length_test(_make_memoryview) | -302,937,060,750,652,000 | When called with a `memoryview` instance, `Connection.recv_into`
respects the ``nbytes`` parameter and doesn't copy more than that
number of bytes in. | tests/test_ssl.py | test_memoryview_respects_length | dholth/pyopenssl | python | def test_memoryview_respects_length(self):
"\n When called with a `memoryview` instance, `Connection.recv_into`\n respects the ``nbytes`` parameter and doesn't copy more than that\n number of bytes in.\n "
self._respects_length_test(_make_memoryview) |
def test_memoryview_doesnt_overfill(self):
"\n When called with a `memoryview` instance, `Connection.recv_into`\n respects the size of the array and doesn't write more bytes into it\n than will fit.\n "
self._doesnt_overfill_test(_make_memoryview) | -2,332,977,822,862,550,500 | When called with a `memoryview` instance, `Connection.recv_into`
respects the size of the array and doesn't write more bytes into it
than will fit. | tests/test_ssl.py | test_memoryview_doesnt_overfill | dholth/pyopenssl | python | def test_memoryview_doesnt_overfill(self):
"\n When called with a `memoryview` instance, `Connection.recv_into`\n respects the size of the array and doesn't write more bytes into it\n than will fit.\n "
self._doesnt_overfill_test(_make_memoryview) |
def test_memoryview_really_doesnt_overfill(self):
"\n When called with a `memoryview` instance and an `nbytes` value that is\n too large, `Connection.recv_into` respects the size of the array and\n not the `nbytes` value and doesn't write more bytes into the buffer\n than will fit.\n "
self._doesnt_overfill_test(_make_memoryview) | 6,955,788,149,076,762,000 | When called with a `memoryview` instance and an `nbytes` value that is
too large, `Connection.recv_into` respects the size of the array and
not the `nbytes` value and doesn't write more bytes into the buffer
than will fit. | tests/test_ssl.py | test_memoryview_really_doesnt_overfill | dholth/pyopenssl | python | def test_memoryview_really_doesnt_overfill(self):
"\n When called with a `memoryview` instance and an `nbytes` value that is\n too large, `Connection.recv_into` respects the size of the array and\n not the `nbytes` value and doesn't write more bytes into the buffer\n than will fit.\n "
self._doesnt_overfill_test(_make_memoryview) |
def test_wrong_args(self):
'\n When called with arguments other than a string argument for its first\n parameter, `Connection.sendall` raises `TypeError`.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
connection.sendall(object()) | -3,915,140,041,331,592,700 | When called with arguments other than a string argument for its first
parameter, `Connection.sendall` raises `TypeError`. | tests/test_ssl.py | test_wrong_args | dholth/pyopenssl | python | def test_wrong_args(self):
'\n When called with arguments other than a string argument for its first\n parameter, `Connection.sendall` raises `TypeError`.\n '
connection = Connection(Context(TLSv1_METHOD), None)
with pytest.raises(TypeError):
connection.sendall(object()) |
def test_short(self):
'\n `Connection.sendall` transmits all of the bytes in the string\n passed to it.\n '
(server, client) = loopback()
server.sendall(b'x')
assert (client.recv(1) == b'x') | 5,969,463,928,237,653,000 | `Connection.sendall` transmits all of the bytes in the string
passed to it. | tests/test_ssl.py | test_short | dholth/pyopenssl | python | def test_short(self):
'\n `Connection.sendall` transmits all of the bytes in the string\n passed to it.\n '
(server, client) = loopback()
server.sendall(b'x')
assert (client.recv(1) == b'x') |
def test_text(self):
'\n `Connection.sendall` transmits all the content in the string passed\n to it, raising a DeprecationWarning in case of this being a text.\n '
(server, client) = loopback()
with pytest.warns(DeprecationWarning) as w:
simplefilter('always')
server.sendall(b'x'.decode('ascii'))
assert ('{0} for buf is no longer accepted, use bytes'.format(WARNING_TYPE_EXPECTED) == str(w[(- 1)].message))
assert (client.recv(1) == b'x') | 5,246,487,877,358,254,000 | `Connection.sendall` transmits all the content in the string passed
to it, raising a DeprecationWarning in case of this being a text. | tests/test_ssl.py | test_text | dholth/pyopenssl | python | def test_text(self):
'\n `Connection.sendall` transmits all the content in the string passed\n to it, raising a DeprecationWarning in case of this being a text.\n '
(server, client) = loopback()
with pytest.warns(DeprecationWarning) as w:
simplefilter('always')
server.sendall(b'x'.decode('ascii'))
assert ('{0} for buf is no longer accepted, use bytes'.format(WARNING_TYPE_EXPECTED) == str(w[(- 1)].message))
assert (client.recv(1) == b'x') |
def test_short_memoryview(self):
'\n When passed a memoryview onto a small number of bytes,\n `Connection.sendall` transmits all of them.\n '
(server, client) = loopback()
server.sendall(memoryview(b'x'))
assert (client.recv(1) == b'x') | 5,059,543,230,218,045,000 | When passed a memoryview onto a small number of bytes,
`Connection.sendall` transmits all of them. | tests/test_ssl.py | test_short_memoryview | dholth/pyopenssl | python | def test_short_memoryview(self):
'\n When passed a memoryview onto a small number of bytes,\n `Connection.sendall` transmits all of them.\n '
(server, client) = loopback()
server.sendall(memoryview(b'x'))
assert (client.recv(1) == b'x') |
@skip_if_py3
def test_short_buffers(self):
'\n When passed a buffer containing a small number of bytes,\n `Connection.sendall` transmits all of them.\n '
(server, client) = loopback()
server.sendall(buffer(b'x'))
assert (client.recv(1) == b'x') | -6,450,031,320,519,207,000 | When passed a buffer containing a small number of bytes,
`Connection.sendall` transmits all of them. | tests/test_ssl.py | test_short_buffers | dholth/pyopenssl | python | @skip_if_py3
def test_short_buffers(self):
'\n When passed a buffer containing a small number of bytes,\n `Connection.sendall` transmits all of them.\n '
(server, client) = loopback()
server.sendall(buffer(b'x'))
assert (client.recv(1) == b'x') |
def test_long(self):
'\n `Connection.sendall` transmits all the bytes in the string passed to it\n even if this requires multiple calls of an underlying write function.\n '
(server, client) = loopback()
message = ((b'x' * ((1024 * 32) - 1)) + b'y')
server.sendall(message)
accum = []
received = 0
while (received < len(message)):
data = client.recv(1024)
accum.append(data)
received += len(data)
assert (message == b''.join(accum)) | -1,216,064,153,939,120,400 | `Connection.sendall` transmits all the bytes in the string passed to it
even if this requires multiple calls of an underlying write function. | tests/test_ssl.py | test_long | dholth/pyopenssl | python | def test_long(self):
'\n `Connection.sendall` transmits all the bytes in the string passed to it\n even if this requires multiple calls of an underlying write function.\n '
(server, client) = loopback()
message = ((b'x' * ((1024 * 32) - 1)) + b'y')
server.sendall(message)
accum = []
received = 0
while (received < len(message)):
data = client.recv(1024)
accum.append(data)
received += len(data)
assert (message == b.join(accum)) |
def test_closed(self):
'\n If the underlying socket is closed, `Connection.sendall` propagates the\n write error from the low level write call.\n '
(server, client) = loopback()
server.sock_shutdown(2)
with pytest.raises(SysCallError) as err:
server.sendall(b'hello, world')
if (platform == 'win32'):
assert (err.value.args[0] == ESHUTDOWN)
else:
assert (err.value.args[0] == EPIPE) | 2,250,889,179,383,182,000 | If the underlying socket is closed, `Connection.sendall` propagates the
write error from the low level write call. | tests/test_ssl.py | test_closed | dholth/pyopenssl | python | def test_closed(self):
'\n If the underlying socket is closed, `Connection.sendall` propagates the\n write error from the low level write call.\n '
(server, client) = loopback()
server.sock_shutdown(2)
with pytest.raises(SysCallError) as err:
server.sendall(b'hello, world')
if (platform == 'win32'):
assert (err.value.args[0] == ESHUTDOWN)
else:
assert (err.value.args[0] == EPIPE) |
def test_total_renegotiations(self):
'\n `Connection.total_renegotiations` returns `0` before any renegotiations\n have happened.\n '
connection = Connection(Context(TLSv1_METHOD), None)
assert (connection.total_renegotiations() == 0) | -2,837,111,824,623,432,000 | `Connection.total_renegotiations` returns `0` before any renegotiations
have happened. | tests/test_ssl.py | test_total_renegotiations | dholth/pyopenssl | python | def test_total_renegotiations(self):
'\n `Connection.total_renegotiations` returns `0` before any renegotiations\n have happened.\n '
connection = Connection(Context(TLSv1_METHOD), None)
assert (connection.total_renegotiations() == 0) |
def test_renegotiate(self):
'\n Go through a complete renegotiation cycle.\n '
(server, client) = loopback((lambda s: loopback_server_factory(s, TLSv1_2_METHOD)), (lambda s: loopback_client_factory(s, TLSv1_2_METHOD)))
server.send(b'hello world')
assert (b'hello world' == client.recv(len(b'hello world')))
assert (0 == server.total_renegotiations())
assert (False is server.renegotiate_pending())
assert (True is server.renegotiate())
assert (True is server.renegotiate_pending())
server.setblocking(False)
client.setblocking(False)
client.do_handshake()
server.do_handshake()
assert (1 == server.total_renegotiations())
while (False is server.renegotiate_pending()):
pass | -560,146,216,608,416,830 | Go through a complete renegotiation cycle. | tests/test_ssl.py | test_renegotiate | dholth/pyopenssl | python | def test_renegotiate(self):
'\n \n '
(server, client) = loopback((lambda s: loopback_server_factory(s, TLSv1_2_METHOD)), (lambda s: loopback_client_factory(s, TLSv1_2_METHOD)))
server.send(b'hello world')
assert (b'hello world' == client.recv(len(b'hello world')))
assert (0 == server.total_renegotiations())
assert (False is server.renegotiate_pending())
assert (True is server.renegotiate())
assert (True is server.renegotiate_pending())
server.setblocking(False)
client.setblocking(False)
client.do_handshake()
server.do_handshake()
assert (1 == server.total_renegotiations())
while (False is server.renegotiate_pending()):
pass |
def test_type(self):
'\n `Error` is an exception type.\n '
assert issubclass(Error, Exception)
assert (Error.__name__ == 'Error') | 7,928,066,544,800,496,000 | `Error` is an exception type. | tests/test_ssl.py | test_type | dholth/pyopenssl | python | def test_type(self):
'\n \n '
assert issubclass(Error, Exception)
assert (Error.__name__ == 'Error') |
@pytest.mark.skipif((OP_NO_QUERY_MTU is None), reason='OP_NO_QUERY_MTU unavailable - OpenSSL version may be too old')
def test_op_no_query_mtu(self):
'\n The value of `OpenSSL.SSL.OP_NO_QUERY_MTU` is 0x1000, the value\n of `SSL_OP_NO_QUERY_MTU` defined by `openssl/ssl.h`.\n '
assert (OP_NO_QUERY_MTU == 4096) | -6,302,920,363,295,085,000 | The value of `OpenSSL.SSL.OP_NO_QUERY_MTU` is 0x1000, the value
of `SSL_OP_NO_QUERY_MTU` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_op_no_query_mtu | dholth/pyopenssl | python | @pytest.mark.skipif((OP_NO_QUERY_MTU is None), reason='OP_NO_QUERY_MTU unavailable - OpenSSL version may be too old')
def test_op_no_query_mtu(self):
'\n The value of `OpenSSL.SSL.OP_NO_QUERY_MTU` is 0x1000, the value\n of `SSL_OP_NO_QUERY_MTU` defined by `openssl/ssl.h`.\n '
assert (OP_NO_QUERY_MTU == 4096) |
@pytest.mark.skipif((OP_COOKIE_EXCHANGE is None), reason='OP_COOKIE_EXCHANGE unavailable - OpenSSL version may be too old')
def test_op_cookie_exchange(self):
'\n The value of `OpenSSL.SSL.OP_COOKIE_EXCHANGE` is 0x2000, the\n value of `SSL_OP_COOKIE_EXCHANGE` defined by `openssl/ssl.h`.\n '
assert (OP_COOKIE_EXCHANGE == 8192) | 8,995,466,665,441,163,000 | The value of `OpenSSL.SSL.OP_COOKIE_EXCHANGE` is 0x2000, the
value of `SSL_OP_COOKIE_EXCHANGE` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_op_cookie_exchange | dholth/pyopenssl | python | @pytest.mark.skipif((OP_COOKIE_EXCHANGE is None), reason='OP_COOKIE_EXCHANGE unavailable - OpenSSL version may be too old')
def test_op_cookie_exchange(self):
'\n The value of `OpenSSL.SSL.OP_COOKIE_EXCHANGE` is 0x2000, the\n value of `SSL_OP_COOKIE_EXCHANGE` defined by `openssl/ssl.h`.\n '
assert (OP_COOKIE_EXCHANGE == 8192) |
@pytest.mark.skipif((OP_NO_TICKET is None), reason='OP_NO_TICKET unavailable - OpenSSL version may be too old')
def test_op_no_ticket(self):
'\n The value of `OpenSSL.SSL.OP_NO_TICKET` is 0x4000, the value of\n `SSL_OP_NO_TICKET` defined by `openssl/ssl.h`.\n '
assert (OP_NO_TICKET == 16384) | 8,687,460,180,422,385,000 | The value of `OpenSSL.SSL.OP_NO_TICKET` is 0x4000, the value of
`SSL_OP_NO_TICKET` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_op_no_ticket | dholth/pyopenssl | python | @pytest.mark.skipif((OP_NO_TICKET is None), reason='OP_NO_TICKET unavailable - OpenSSL version may be too old')
def test_op_no_ticket(self):
'\n The value of `OpenSSL.SSL.OP_NO_TICKET` is 0x4000, the value of\n `SSL_OP_NO_TICKET` defined by `openssl/ssl.h`.\n '
assert (OP_NO_TICKET == 16384) |
@pytest.mark.skipif((OP_NO_COMPRESSION is None), reason='OP_NO_COMPRESSION unavailable - OpenSSL version may be too old')
def test_op_no_compression(self):
'\n The value of `OpenSSL.SSL.OP_NO_COMPRESSION` is 0x20000, the\n value of `SSL_OP_NO_COMPRESSION` defined by `openssl/ssl.h`.\n '
assert (OP_NO_COMPRESSION == 131072) | -308,995,493,175,777,100 | The value of `OpenSSL.SSL.OP_NO_COMPRESSION` is 0x20000, the
value of `SSL_OP_NO_COMPRESSION` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_op_no_compression | dholth/pyopenssl | python | @pytest.mark.skipif((OP_NO_COMPRESSION is None), reason='OP_NO_COMPRESSION unavailable - OpenSSL version may be too old')
def test_op_no_compression(self):
'\n The value of `OpenSSL.SSL.OP_NO_COMPRESSION` is 0x20000, the\n value of `SSL_OP_NO_COMPRESSION` defined by `openssl/ssl.h`.\n '
assert (OP_NO_COMPRESSION == 131072) |
def test_sess_cache_off(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_OFF` 0x0, the value of\n `SSL_SESS_CACHE_OFF` defined by `openssl/ssl.h`.\n '
assert (0 == SESS_CACHE_OFF) | -1,087,820,163,610,769,400 | The value of `OpenSSL.SSL.SESS_CACHE_OFF` 0x0, the value of
`SSL_SESS_CACHE_OFF` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_off | dholth/pyopenssl | python | def test_sess_cache_off(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_OFF` 0x0, the value of\n `SSL_SESS_CACHE_OFF` defined by `openssl/ssl.h`.\n '
assert (0 == SESS_CACHE_OFF) |
def test_sess_cache_client(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_CLIENT` 0x1, the value of\n `SSL_SESS_CACHE_CLIENT` defined by `openssl/ssl.h`.\n '
assert (1 == SESS_CACHE_CLIENT) | -8,833,357,520,814,420,000 | The value of `OpenSSL.SSL.SESS_CACHE_CLIENT` 0x1, the value of
`SSL_SESS_CACHE_CLIENT` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_client | dholth/pyopenssl | python | def test_sess_cache_client(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_CLIENT` 0x1, the value of\n `SSL_SESS_CACHE_CLIENT` defined by `openssl/ssl.h`.\n '
assert (1 == SESS_CACHE_CLIENT) |
def test_sess_cache_server(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_SERVER` 0x2, the value of\n `SSL_SESS_CACHE_SERVER` defined by `openssl/ssl.h`.\n '
assert (2 == SESS_CACHE_SERVER) | -8,384,895,091,945,677,000 | The value of `OpenSSL.SSL.SESS_CACHE_SERVER` 0x2, the value of
`SSL_SESS_CACHE_SERVER` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_server | dholth/pyopenssl | python | def test_sess_cache_server(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_SERVER` 0x2, the value of\n `SSL_SESS_CACHE_SERVER` defined by `openssl/ssl.h`.\n '
assert (2 == SESS_CACHE_SERVER) |
def test_sess_cache_both(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_BOTH` 0x3, the value of\n `SSL_SESS_CACHE_BOTH` defined by `openssl/ssl.h`.\n '
assert (3 == SESS_CACHE_BOTH) | 6,080,152,063,674,549,000 | The value of `OpenSSL.SSL.SESS_CACHE_BOTH` 0x3, the value of
`SSL_SESS_CACHE_BOTH` defined by `openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_both | dholth/pyopenssl | python | def test_sess_cache_both(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_BOTH` 0x3, the value of\n `SSL_SESS_CACHE_BOTH` defined by `openssl/ssl.h`.\n '
assert (3 == SESS_CACHE_BOTH) |
def test_sess_cache_no_auto_clear(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_AUTO_CLEAR` 0x80, the\n value of `SSL_SESS_CACHE_NO_AUTO_CLEAR` defined by\n `openssl/ssl.h`.\n '
assert (128 == SESS_CACHE_NO_AUTO_CLEAR) | -3,615,064,133,708,108,300 | The value of `OpenSSL.SSL.SESS_CACHE_NO_AUTO_CLEAR` 0x80, the
value of `SSL_SESS_CACHE_NO_AUTO_CLEAR` defined by
`openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_no_auto_clear | dholth/pyopenssl | python | def test_sess_cache_no_auto_clear(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_AUTO_CLEAR` 0x80, the\n value of `SSL_SESS_CACHE_NO_AUTO_CLEAR` defined by\n `openssl/ssl.h`.\n '
assert (128 == SESS_CACHE_NO_AUTO_CLEAR) |
def test_sess_cache_no_internal_lookup(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_LOOKUP` 0x100,\n the value of `SSL_SESS_CACHE_NO_INTERNAL_LOOKUP` defined by\n `openssl/ssl.h`.\n '
assert (256 == SESS_CACHE_NO_INTERNAL_LOOKUP) | 2,842,705,627,547,642,400 | The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_LOOKUP` 0x100,
the value of `SSL_SESS_CACHE_NO_INTERNAL_LOOKUP` defined by
`openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_no_internal_lookup | dholth/pyopenssl | python | def test_sess_cache_no_internal_lookup(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_LOOKUP` 0x100,\n the value of `SSL_SESS_CACHE_NO_INTERNAL_LOOKUP` defined by\n `openssl/ssl.h`.\n '
assert (256 == SESS_CACHE_NO_INTERNAL_LOOKUP) |
def test_sess_cache_no_internal_store(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_STORE` 0x200,\n the value of `SSL_SESS_CACHE_NO_INTERNAL_STORE` defined by\n `openssl/ssl.h`.\n '
assert (512 == SESS_CACHE_NO_INTERNAL_STORE) | -771,979,832,315,061,400 | The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_STORE` 0x200,
the value of `SSL_SESS_CACHE_NO_INTERNAL_STORE` defined by
`openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_no_internal_store | dholth/pyopenssl | python | def test_sess_cache_no_internal_store(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL_STORE` 0x200,\n the value of `SSL_SESS_CACHE_NO_INTERNAL_STORE` defined by\n `openssl/ssl.h`.\n '
assert (512 == SESS_CACHE_NO_INTERNAL_STORE) |
def test_sess_cache_no_internal(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL` 0x300, the\n value of `SSL_SESS_CACHE_NO_INTERNAL` defined by\n `openssl/ssl.h`.\n '
assert (768 == SESS_CACHE_NO_INTERNAL) | 6,954,541,248,848,563,000 | The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL` 0x300, the
value of `SSL_SESS_CACHE_NO_INTERNAL` defined by
`openssl/ssl.h`. | tests/test_ssl.py | test_sess_cache_no_internal | dholth/pyopenssl | python | def test_sess_cache_no_internal(self):
'\n The value of `OpenSSL.SSL.SESS_CACHE_NO_INTERNAL` 0x300, the\n value of `SSL_SESS_CACHE_NO_INTERNAL` defined by\n `openssl/ssl.h`.\n '
assert (768 == SESS_CACHE_NO_INTERNAL) |
def _server(self, sock):
'\n Create a new server-side SSL `Connection` object wrapped around `sock`.\n '
server_ctx = Context(TLSv1_METHOD)
server_ctx.set_options(((OP_NO_SSLv2 | OP_NO_SSLv3) | OP_SINGLE_DH_USE))
server_ctx.set_verify(((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT) | VERIFY_CLIENT_ONCE), verify_cb)
server_store = server_ctx.get_cert_store()
server_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server_ctx.check_privatekey()
server_store.add_cert(load_certificate(FILETYPE_PEM, root_cert_pem))
server_conn = Connection(server_ctx, sock)
server_conn.set_accept_state()
return server_conn | 2,840,477,701,098,929,700 | Create a new server-side SSL `Connection` object wrapped around `sock`. | tests/test_ssl.py | _server | dholth/pyopenssl | python | def _server(self, sock):
'\n \n '
server_ctx = Context(TLSv1_METHOD)
server_ctx.set_options(((OP_NO_SSLv2 | OP_NO_SSLv3) | OP_SINGLE_DH_USE))
server_ctx.set_verify(((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT) | VERIFY_CLIENT_ONCE), verify_cb)
server_store = server_ctx.get_cert_store()
server_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
server_ctx.check_privatekey()
server_store.add_cert(load_certificate(FILETYPE_PEM, root_cert_pem))
server_conn = Connection(server_ctx, sock)
server_conn.set_accept_state()
return server_conn |
def _client(self, sock):
'\n Create a new client-side SSL `Connection` object wrapped around `sock`.\n '
client_ctx = Context(TLSv1_METHOD)
client_ctx.set_options(((OP_NO_SSLv2 | OP_NO_SSLv3) | OP_SINGLE_DH_USE))
client_ctx.set_verify(((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT) | VERIFY_CLIENT_ONCE), verify_cb)
client_store = client_ctx.get_cert_store()
client_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, client_key_pem))
client_ctx.use_certificate(load_certificate(FILETYPE_PEM, client_cert_pem))
client_ctx.check_privatekey()
client_store.add_cert(load_certificate(FILETYPE_PEM, root_cert_pem))
client_conn = Connection(client_ctx, sock)
client_conn.set_connect_state()
return client_conn | 790,893,991,454,912,400 | Create a new client-side SSL `Connection` object wrapped around `sock`. | tests/test_ssl.py | _client | dholth/pyopenssl | python | def _client(self, sock):
'\n \n '
client_ctx = Context(TLSv1_METHOD)
client_ctx.set_options(((OP_NO_SSLv2 | OP_NO_SSLv3) | OP_SINGLE_DH_USE))
client_ctx.set_verify(((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT) | VERIFY_CLIENT_ONCE), verify_cb)
client_store = client_ctx.get_cert_store()
client_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, client_key_pem))
client_ctx.use_certificate(load_certificate(FILETYPE_PEM, client_cert_pem))
client_ctx.check_privatekey()
client_store.add_cert(load_certificate(FILETYPE_PEM, root_cert_pem))
client_conn = Connection(client_ctx, sock)
client_conn.set_connect_state()
return client_conn |
def test_memory_connect(self):
'\n Two `Connection`s which use memory BIOs can be manually connected by\n reading from the output of each and writing those bytes to the input of\n the other and in this way establish a connection and exchange\n application-level bytes with each other.\n '
server_conn = self._server(None)
client_conn = self._client(None)
assert (server_conn.master_key() is None)
assert (server_conn.client_random() is None)
assert (server_conn.server_random() is None)
assert (interact_in_memory(client_conn, server_conn) is None)
assert (server_conn.master_key() is not None)
assert (server_conn.client_random() is not None)
assert (server_conn.server_random() is not None)
assert (server_conn.client_random() == client_conn.client_random())
assert (server_conn.server_random() == client_conn.server_random())
assert (server_conn.client_random() != server_conn.server_random())
assert (client_conn.client_random() != client_conn.server_random())
cekm = client_conn.export_keying_material(b'LABEL', 32)
sekm = server_conn.export_keying_material(b'LABEL', 32)
assert (cekm is not None)
assert (sekm is not None)
assert (cekm == sekm)
assert (len(sekm) == 32)
cekmc = client_conn.export_keying_material(b'LABEL', 32, b'CONTEXT')
sekmc = server_conn.export_keying_material(b'LABEL', 32, b'CONTEXT')
assert (cekmc is not None)
assert (sekmc is not None)
assert (cekmc == sekmc)
assert (cekmc != cekm)
assert (sekmc != sekm)
cekmt = client_conn.export_keying_material(b'test', 32, b'CONTEXT')
sekmt = server_conn.export_keying_material(b'test', 32, b'CONTEXT')
assert (cekmc != cekmt)
assert (sekmc != sekmt)
important_message = b'One if by land, two if by sea.'
server_conn.write(important_message)
assert (interact_in_memory(client_conn, server_conn) == (client_conn, important_message))
client_conn.write(important_message[::(- 1)])
assert (interact_in_memory(client_conn, server_conn) == (server_conn, important_message[::(- 1)])) | -2,525,644,384,649,953,000 | Two `Connection`s which use memory BIOs can be manually connected by
reading from the output of each and writing those bytes to the input of
the other and in this way establish a connection and exchange
application-level bytes with each other. | tests/test_ssl.py | test_memory_connect | dholth/pyopenssl | python | def test_memory_connect(self):
'\n Two `Connection`s which use memory BIOs can be manually connected by\n reading from the output of each and writing those bytes to the input of\n the other and in this way establish a connection and exchange\n application-level bytes with each other.\n '
server_conn = self._server(None)
client_conn = self._client(None)
assert (server_conn.master_key() is None)
assert (server_conn.client_random() is None)
assert (server_conn.server_random() is None)
assert (interact_in_memory(client_conn, server_conn) is None)
assert (server_conn.master_key() is not None)
assert (server_conn.client_random() is not None)
assert (server_conn.server_random() is not None)
assert (server_conn.client_random() == client_conn.client_random())
assert (server_conn.server_random() == client_conn.server_random())
assert (server_conn.client_random() != server_conn.server_random())
assert (client_conn.client_random() != client_conn.server_random())
cekm = client_conn.export_keying_material(b'LABEL', 32)
sekm = server_conn.export_keying_material(b'LABEL', 32)
assert (cekm is not None)
assert (sekm is not None)
assert (cekm == sekm)
assert (len(sekm) == 32)
cekmc = client_conn.export_keying_material(b'LABEL', 32, b'CONTEXT')
sekmc = server_conn.export_keying_material(b'LABEL', 32, b'CONTEXT')
assert (cekmc is not None)
assert (sekmc is not None)
assert (cekmc == sekmc)
assert (cekmc != cekm)
assert (sekmc != sekm)
cekmt = client_conn.export_keying_material(b'test', 32, b'CONTEXT')
sekmt = server_conn.export_keying_material(b'test', 32, b'CONTEXT')
assert (cekmc != cekmt)
assert (sekmc != sekmt)
important_message = b'One if by land, two if by sea.'
server_conn.write(important_message)
assert (interact_in_memory(client_conn, server_conn) == (client_conn, important_message))
client_conn.write(important_message[::(- 1)])
assert (interact_in_memory(client_conn, server_conn) == (server_conn, important_message[::(- 1)])) |
def test_socket_connect(self):
"\n Just like `test_memory_connect` but with an actual socket.\n\n This is primarily to rule out the memory BIO code as the source of any\n problems encountered while passing data over a `Connection` (if\n this test fails, there must be a problem outside the memory BIO code,\n as no memory BIO is involved here). Even though this isn't a memory\n BIO test, it's convenient to have it here.\n "
(server_conn, client_conn) = loopback()
important_message = b"Help me Obi Wan Kenobi, you're my only hope."
client_conn.send(important_message)
msg = server_conn.recv(1024)
assert (msg == important_message)
important_message = important_message[::(- 1)]
server_conn.send(important_message)
msg = client_conn.recv(1024)
assert (msg == important_message) | -4,749,119,240,591,340,000 | Just like `test_memory_connect` but with an actual socket.
This is primarily to rule out the memory BIO code as the source of any
problems encountered while passing data over a `Connection` (if
this test fails, there must be a problem outside the memory BIO code,
as no memory BIO is involved here). Even though this isn't a memory
BIO test, it's convenient to have it here. | tests/test_ssl.py | test_socket_connect | dholth/pyopenssl | python | def test_socket_connect(self):
"\n Just like `test_memory_connect` but with an actual socket.\n\n This is primarily to rule out the memory BIO code as the source of any\n problems encountered while passing data over a `Connection` (if\n this test fails, there must be a problem outside the memory BIO code,\n as no memory BIO is involved here). Even though this isn't a memory\n BIO test, it's convenient to have it here.\n "
(server_conn, client_conn) = loopback()
important_message = b"Help me Obi Wan Kenobi, you're my only hope."
client_conn.send(important_message)
msg = server_conn.recv(1024)
assert (msg == important_message)
important_message = important_message[::(- 1)]
server_conn.send(important_message)
msg = client_conn.recv(1024)
assert (msg == important_message) |
Subsets and Splits