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 binarize(img): ' Take an RGB image and binarize it.\n\n :param img: cv2 image\n :return:\n ' gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) (ret, bin) = cv2.threshold(gray, 1, 255, cv2.THRESH_BINARY) return bin
-7,442,233,205,365,753,000
Take an RGB image and binarize it. :param img: cv2 image :return:
GT_generator/gt_image.py
binarize
alix-tz/GT_generator
python
def binarize(img): ' Take an RGB image and binarize it.\n\n :param img: cv2 image\n :return:\n ' gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) (ret, bin) = cv2.threshold(gray, 1, 255, cv2.THRESH_BINARY) return bin
def makecoloredlayer(img, mask, color=(0, 255, 0)): ' Create an image based on provided mask, dimensions and color (default is red)\n\n :param mask: binary mask defining the zone needing color, the rest will be black\n :param img: numpy.array used for dimensions\n :param color: 3 dimension tuple (B,G,R)\n :return:\n ' coloredlayer = np.zeros(img.shape, dtype='uint8') cv2.rectangle(coloredlayer, (0, 0), (img.shape[1], img.shape[0]), color, (- 1)) maskedlayer = cv2.bitwise_or(img, coloredlayer, mask=mask) return maskedlayer
-9,010,662,008,818,187,000
Create an image based on provided mask, dimensions and color (default is red) :param mask: binary mask defining the zone needing color, the rest will be black :param img: numpy.array used for dimensions :param color: 3 dimension tuple (B,G,R) :return:
GT_generator/gt_image.py
makecoloredlayer
alix-tz/GT_generator
python
def makecoloredlayer(img, mask, color=(0, 255, 0)): ' Create an image based on provided mask, dimensions and color (default is red)\n\n :param mask: binary mask defining the zone needing color, the rest will be black\n :param img: numpy.array used for dimensions\n :param color: 3 dimension tuple (B,G,R)\n :return:\n ' coloredlayer = np.zeros(img.shape, dtype='uint8') cv2.rectangle(coloredlayer, (0, 0), (img.shape[1], img.shape[0]), color, (- 1)) maskedlayer = cv2.bitwise_or(img, coloredlayer, mask=mask) return maskedlayer
def makemarkedmask(maskA, maskB): ' create a new mask based on existing image and coming mask\n\n :param maskA: binary image\n :param maskB: binary image\n :return: binary image\n ' inter = cv2.bitwise_xor(maskA, maskB) inter = cv2.bitwise_and(inter, maskB) inter = cv2.bitwise_xor(inter, maskB) markedmask = cv2.bitwise_not(inter) return markedmask
-2,665,615,627,785,033,000
create a new mask based on existing image and coming mask :param maskA: binary image :param maskB: binary image :return: binary image
GT_generator/gt_image.py
makemarkedmask
alix-tz/GT_generator
python
def makemarkedmask(maskA, maskB): ' create a new mask based on existing image and coming mask\n\n :param maskA: binary image\n :param maskB: binary image\n :return: binary image\n ' inter = cv2.bitwise_xor(maskA, maskB) inter = cv2.bitwise_and(inter, maskB) inter = cv2.bitwise_xor(inter, maskB) markedmask = cv2.bitwise_not(inter) return markedmask
def applymark(img, mask): ' Apply a mask to an image to keep only active cells.\n\n :return: image\n ' img = cv2.bitwise_and(img, img, mask=mask) return img
4,738,481,243,198,023,000
Apply a mask to an image to keep only active cells. :return: image
GT_generator/gt_image.py
applymark
alix-tz/GT_generator
python
def applymark(img, mask): ' Apply a mask to an image to keep only active cells.\n\n :return: image\n ' img = cv2.bitwise_and(img, img, mask=mask) return img
def makeannotatedimage(masks, colors): ' Combine layers and create an image combining several annotations\n\n :param masks: list of images used as masks\n :param colors: list of colors\n :return:\n ' if (len(masks) != len(colors)): print('Error: annotation and colors do not match.') return False elif (len(masks) == 0): print('Error: no mask to combine.') return False else: combo = np.zeros(masks[0].shape, dtype='uint8') i = 0 bins = [] for mask in masks: bin = binarize(mask) bins.append(bin) firstmask = bins[:1] combo = makecoloredlayer(combo, firstmask[0], colors[i]) if (len(bins) > 1): other_masks = bins[1:] for mask in other_masks: i += 1 newmask = binarize(combo) markedout = makemarkedmask(newmask, mask) combo = applymark(combo, markedout) newlayer = makecoloredlayer(combo, mask, colors[i]) combo = cv2.bitwise_or(combo, newlayer) return combo
7,783,298,976,672,876,000
Combine layers and create an image combining several annotations :param masks: list of images used as masks :param colors: list of colors :return:
GT_generator/gt_image.py
makeannotatedimage
alix-tz/GT_generator
python
def makeannotatedimage(masks, colors): ' Combine layers and create an image combining several annotations\n\n :param masks: list of images used as masks\n :param colors: list of colors\n :return:\n ' if (len(masks) != len(colors)): print('Error: annotation and colors do not match.') return False elif (len(masks) == 0): print('Error: no mask to combine.') return False else: combo = np.zeros(masks[0].shape, dtype='uint8') i = 0 bins = [] for mask in masks: bin = binarize(mask) bins.append(bin) firstmask = bins[:1] combo = makecoloredlayer(combo, firstmask[0], colors[i]) if (len(bins) > 1): other_masks = bins[1:] for mask in other_masks: i += 1 newmask = binarize(combo) markedout = makemarkedmask(newmask, mask) combo = applymark(combo, markedout) newlayer = makecoloredlayer(combo, mask, colors[i]) combo = cv2.bitwise_or(combo, newlayer) return combo
def join_bytes_or_unicode(prefix, suffix): '\n Join two path components of either ``bytes`` or ``unicode``.\n\n The return type is the same as the type of ``prefix``.\n ' if (type(prefix) == type(suffix)): return join(prefix, suffix) if isinstance(prefix, text_type): return join(prefix, suffix.decode(getfilesystemencoding())) else: return join(prefix, suffix.encode(getfilesystemencoding()))
-2,964,976,854,970,880,000
Join two path components of either ``bytes`` or ``unicode``. The return type is the same as the type of ``prefix``.
tests/test_ssl.py
join_bytes_or_unicode
dholth/pyopenssl
python
def join_bytes_or_unicode(prefix, suffix): '\n Join two path components of either ``bytes`` or ``unicode``.\n\n The return type is the same as the type of ``prefix``.\n ' if (type(prefix) == type(suffix)): return join(prefix, suffix) if isinstance(prefix, text_type): return join(prefix, suffix.decode(getfilesystemencoding())) else: return join(prefix, suffix.encode(getfilesystemencoding()))
def socket_pair(): '\n Establish and return a pair of network sockets connected to each other.\n ' port = socket_any_family() port.bind(('', 0)) port.listen(1) client = socket(port.family) client.setblocking(False) client.connect_ex((loopback_address(port), port.getsockname()[1])) client.setblocking(True) server = port.accept()[0] server.send(b'x') assert (client.recv(1024) == b'x') client.send(b'y') assert (server.recv(1024) == b'y') server.setblocking(False) client.setblocking(False) return (server, client)
-6,490,838,347,183,275,000
Establish and return a pair of network sockets connected to each other.
tests/test_ssl.py
socket_pair
dholth/pyopenssl
python
def socket_pair(): '\n \n ' port = socket_any_family() port.bind((, 0)) port.listen(1) client = socket(port.family) client.setblocking(False) client.connect_ex((loopback_address(port), port.getsockname()[1])) client.setblocking(True) server = port.accept()[0] server.send(b'x') assert (client.recv(1024) == b'x') client.send(b'y') assert (server.recv(1024) == b'y') server.setblocking(False) client.setblocking(False) return (server, client)
def _create_certificate_chain(): '\n Construct and return a chain of certificates.\n\n 1. A new self-signed certificate authority certificate (cacert)\n 2. A new intermediate certificate signed by cacert (icert)\n 3. A new server certificate signed by icert (scert)\n ' caext = X509Extension(b'basicConstraints', False, b'CA:true') cakey = PKey() cakey.generate_key(TYPE_RSA, 1024) cacert = X509() cacert.get_subject().commonName = 'Authority Certificate' cacert.set_issuer(cacert.get_subject()) cacert.set_pubkey(cakey) cacert.set_notBefore(b'20000101000000Z') cacert.set_notAfter(b'20200101000000Z') cacert.add_extensions([caext]) cacert.set_serial_number(0) cacert.sign(cakey, 'sha1') ikey = PKey() ikey.generate_key(TYPE_RSA, 1024) icert = X509() icert.get_subject().commonName = 'Intermediate Certificate' icert.set_issuer(cacert.get_subject()) icert.set_pubkey(ikey) icert.set_notBefore(b'20000101000000Z') icert.set_notAfter(b'20200101000000Z') icert.add_extensions([caext]) icert.set_serial_number(0) icert.sign(cakey, 'sha1') skey = PKey() skey.generate_key(TYPE_RSA, 1024) scert = X509() scert.get_subject().commonName = 'Server Certificate' scert.set_issuer(icert.get_subject()) scert.set_pubkey(skey) scert.set_notBefore(b'20000101000000Z') scert.set_notAfter(b'20200101000000Z') scert.add_extensions([X509Extension(b'basicConstraints', True, b'CA:false')]) scert.set_serial_number(0) scert.sign(ikey, 'sha1') return [(cakey, cacert), (ikey, icert), (skey, scert)]
4,211,838,082,420,568,000
Construct and return a chain of certificates. 1. A new self-signed certificate authority certificate (cacert) 2. A new intermediate certificate signed by cacert (icert) 3. A new server certificate signed by icert (scert)
tests/test_ssl.py
_create_certificate_chain
dholth/pyopenssl
python
def _create_certificate_chain(): '\n Construct and return a chain of certificates.\n\n 1. A new self-signed certificate authority certificate (cacert)\n 2. A new intermediate certificate signed by cacert (icert)\n 3. A new server certificate signed by icert (scert)\n ' caext = X509Extension(b'basicConstraints', False, b'CA:true') cakey = PKey() cakey.generate_key(TYPE_RSA, 1024) cacert = X509() cacert.get_subject().commonName = 'Authority Certificate' cacert.set_issuer(cacert.get_subject()) cacert.set_pubkey(cakey) cacert.set_notBefore(b'20000101000000Z') cacert.set_notAfter(b'20200101000000Z') cacert.add_extensions([caext]) cacert.set_serial_number(0) cacert.sign(cakey, 'sha1') ikey = PKey() ikey.generate_key(TYPE_RSA, 1024) icert = X509() icert.get_subject().commonName = 'Intermediate Certificate' icert.set_issuer(cacert.get_subject()) icert.set_pubkey(ikey) icert.set_notBefore(b'20000101000000Z') icert.set_notAfter(b'20200101000000Z') icert.add_extensions([caext]) icert.set_serial_number(0) icert.sign(cakey, 'sha1') skey = PKey() skey.generate_key(TYPE_RSA, 1024) scert = X509() scert.get_subject().commonName = 'Server Certificate' scert.set_issuer(icert.get_subject()) scert.set_pubkey(skey) scert.set_notBefore(b'20000101000000Z') scert.set_notAfter(b'20200101000000Z') scert.add_extensions([X509Extension(b'basicConstraints', True, b'CA:false')]) scert.set_serial_number(0) scert.sign(ikey, 'sha1') return [(cakey, cacert), (ikey, icert), (skey, scert)]
def loopback(server_factory=None, client_factory=None): '\n Create a connected socket pair and force two connected SSL sockets\n to talk to each other via memory BIOs.\n ' if (server_factory is None): server_factory = loopback_server_factory if (client_factory is None): client_factory = loopback_client_factory (server, client) = socket_pair() server = server_factory(server) client = client_factory(client) handshake(client, server) server.setblocking(True) client.setblocking(True) return (server, client)
-3,875,786,728,351,069,000
Create a connected socket pair and force two connected SSL sockets to talk to each other via memory BIOs.
tests/test_ssl.py
loopback
dholth/pyopenssl
python
def loopback(server_factory=None, client_factory=None): '\n Create a connected socket pair and force two connected SSL sockets\n to talk to each other via memory BIOs.\n ' if (server_factory is None): server_factory = loopback_server_factory if (client_factory is None): client_factory = loopback_client_factory (server, client) = socket_pair() server = server_factory(server) client = client_factory(client) handshake(client, server) server.setblocking(True) client.setblocking(True) return (server, client)
def interact_in_memory(client_conn, server_conn): '\n Try to read application bytes from each of the two `Connection` objects.\n Copy bytes back and forth between their send/receive buffers for as long\n as there is anything to copy. When there is nothing more to copy,\n return `None`. If one of them actually manages to deliver some application\n bytes, return a two-tuple of the connection from which the bytes were read\n and the bytes themselves.\n ' wrote = True while wrote: wrote = False for (read, write) in [(client_conn, server_conn), (server_conn, client_conn)]: try: data = read.recv((2 ** 16)) except WantReadError: pass else: return (read, data) while True: try: dirty = read.bio_read(4096) except WantReadError: break else: wrote = True write.bio_write(dirty)
-4,085,364,818,757,487,600
Try to read application bytes from each of the two `Connection` objects. Copy bytes back and forth between their send/receive buffers for as long as there is anything to copy. When there is nothing more to copy, return `None`. If one of them actually manages to deliver some application bytes, return a two-tuple of the connection from which the bytes were read and the bytes themselves.
tests/test_ssl.py
interact_in_memory
dholth/pyopenssl
python
def interact_in_memory(client_conn, server_conn): '\n Try to read application bytes from each of the two `Connection` objects.\n Copy bytes back and forth between their send/receive buffers for as long\n as there is anything to copy. When there is nothing more to copy,\n return `None`. If one of them actually manages to deliver some application\n bytes, return a two-tuple of the connection from which the bytes were read\n and the bytes themselves.\n ' wrote = True while wrote: wrote = False for (read, write) in [(client_conn, server_conn), (server_conn, client_conn)]: try: data = read.recv((2 ** 16)) except WantReadError: pass else: return (read, data) while True: try: dirty = read.bio_read(4096) except WantReadError: break else: wrote = True write.bio_write(dirty)
def handshake_in_memory(client_conn, server_conn): '\n Perform the TLS handshake between two `Connection` instances connected to\n each other via memory BIOs.\n ' client_conn.set_connect_state() server_conn.set_accept_state() for conn in [client_conn, server_conn]: try: conn.do_handshake() except WantReadError: pass interact_in_memory(client_conn, server_conn)
6,219,530,167,451,642,000
Perform the TLS handshake between two `Connection` instances connected to each other via memory BIOs.
tests/test_ssl.py
handshake_in_memory
dholth/pyopenssl
python
def handshake_in_memory(client_conn, server_conn): '\n Perform the TLS handshake between two `Connection` instances connected to\n each other via memory BIOs.\n ' client_conn.set_connect_state() server_conn.set_accept_state() for conn in [client_conn, server_conn]: try: conn.do_handshake() except WantReadError: pass interact_in_memory(client_conn, server_conn)
@pytest.fixture def ca_file(tmpdir): '\n Create a valid PEM file with CA certificates and return the path.\n ' key = rsa.generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend()) public_key = key.public_key() builder = x509.CertificateBuilder() builder = builder.subject_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u'pyopenssl.org')])) builder = builder.issuer_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u'pyopenssl.org')])) one_day = datetime.timedelta(1, 0, 0) builder = builder.not_valid_before((datetime.datetime.today() - one_day)) builder = builder.not_valid_after((datetime.datetime.today() + one_day)) builder = builder.serial_number(int(uuid.uuid4())) builder = builder.public_key(public_key) builder = builder.add_extension(x509.BasicConstraints(ca=True, path_length=None), critical=True) certificate = builder.sign(private_key=key, algorithm=hashes.SHA256(), backend=default_backend()) ca_file = tmpdir.join('test.pem') ca_file.write_binary(certificate.public_bytes(encoding=serialization.Encoding.PEM)) return str(ca_file).encode('ascii')
-2,851,605,010,620,332,500
Create a valid PEM file with CA certificates and return the path.
tests/test_ssl.py
ca_file
dholth/pyopenssl
python
@pytest.fixture def ca_file(tmpdir): '\n \n ' key = rsa.generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend()) public_key = key.public_key() builder = x509.CertificateBuilder() builder = builder.subject_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u'pyopenssl.org')])) builder = builder.issuer_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u'pyopenssl.org')])) one_day = datetime.timedelta(1, 0, 0) builder = builder.not_valid_before((datetime.datetime.today() - one_day)) builder = builder.not_valid_after((datetime.datetime.today() + one_day)) builder = builder.serial_number(int(uuid.uuid4())) builder = builder.public_key(public_key) builder = builder.add_extension(x509.BasicConstraints(ca=True, path_length=None), critical=True) certificate = builder.sign(private_key=key, algorithm=hashes.SHA256(), backend=default_backend()) ca_file = tmpdir.join('test.pem') ca_file.write_binary(certificate.public_bytes(encoding=serialization.Encoding.PEM)) return str(ca_file).encode('ascii')
@pytest.fixture def context(): '\n A simple TLS 1.0 context.\n ' return Context(TLSv1_METHOD)
5,323,618,888,641,054,000
A simple TLS 1.0 context.
tests/test_ssl.py
context
dholth/pyopenssl
python
@pytest.fixture def context(): '\n \n ' return Context(TLSv1_METHOD)
def _make_memoryview(size): '\n Create a new ``memoryview`` wrapped around a ``bytearray`` of the given\n size.\n ' return memoryview(bytearray(size))
6,526,838,121,991,538,000
Create a new ``memoryview`` wrapped around a ``bytearray`` of the given size.
tests/test_ssl.py
_make_memoryview
dholth/pyopenssl
python
def _make_memoryview(size): '\n Create a new ``memoryview`` wrapped around a ``bytearray`` of the given\n size.\n ' return memoryview(bytearray(size))
def test_OPENSSL_VERSION_NUMBER(self): '\n `OPENSSL_VERSION_NUMBER` is an integer with status in the low byte and\n the patch, fix, minor, and major versions in the nibbles above that.\n ' assert isinstance(OPENSSL_VERSION_NUMBER, int)
6,447,467,600,144,989,000
`OPENSSL_VERSION_NUMBER` is an integer with status in the low byte and the patch, fix, minor, and major versions in the nibbles above that.
tests/test_ssl.py
test_OPENSSL_VERSION_NUMBER
dholth/pyopenssl
python
def test_OPENSSL_VERSION_NUMBER(self): '\n `OPENSSL_VERSION_NUMBER` is an integer with status in the low byte and\n the patch, fix, minor, and major versions in the nibbles above that.\n ' assert isinstance(OPENSSL_VERSION_NUMBER, int)
def test_SSLeay_version(self): '\n `SSLeay_version` takes a version type indicator and returns one of a\n number of version strings based on that indicator.\n ' versions = {} for t in [SSLEAY_VERSION, SSLEAY_CFLAGS, SSLEAY_BUILT_ON, SSLEAY_PLATFORM, SSLEAY_DIR]: version = SSLeay_version(t) versions[version] = t assert isinstance(version, bytes) assert (len(versions) == 5)
-5,407,183,400,880,610,000
`SSLeay_version` takes a version type indicator and returns one of a number of version strings based on that indicator.
tests/test_ssl.py
test_SSLeay_version
dholth/pyopenssl
python
def test_SSLeay_version(self): '\n `SSLeay_version` takes a version type indicator and returns one of a\n number of version strings based on that indicator.\n ' versions = {} for t in [SSLEAY_VERSION, SSLEAY_CFLAGS, SSLEAY_BUILT_ON, SSLEAY_PLATFORM, SSLEAY_DIR]: version = SSLeay_version(t) versions[version] = t assert isinstance(version, bytes) assert (len(versions) == 5)
@pytest.mark.parametrize('cipher_string', [b'hello world:AES128-SHA', u'hello world:AES128-SHA']) def test_set_cipher_list(self, context, cipher_string): '\n `Context.set_cipher_list` accepts both byte and unicode strings\n for naming the ciphers which connections created with the context\n object will be able to choose from.\n ' context.set_cipher_list(cipher_string) conn = Connection(context, None) assert ('AES128-SHA' in conn.get_cipher_list())
5,056,850,136,505,171,000
`Context.set_cipher_list` accepts both byte and unicode strings for naming the ciphers which connections created with the context object will be able to choose from.
tests/test_ssl.py
test_set_cipher_list
dholth/pyopenssl
python
@pytest.mark.parametrize('cipher_string', [b'hello world:AES128-SHA', u'hello world:AES128-SHA']) def test_set_cipher_list(self, context, cipher_string): '\n `Context.set_cipher_list` accepts both byte and unicode strings\n for naming the ciphers which connections created with the context\n object will be able to choose from.\n ' context.set_cipher_list(cipher_string) conn = Connection(context, None) assert ('AES128-SHA' in conn.get_cipher_list())
def test_set_cipher_list_wrong_type(self, context): '\n `Context.set_cipher_list` raises `TypeError` when passed a non-string\n argument.\n ' with pytest.raises(TypeError): context.set_cipher_list(object())
-2,832,276,529,608,422,400
`Context.set_cipher_list` raises `TypeError` when passed a non-string argument.
tests/test_ssl.py
test_set_cipher_list_wrong_type
dholth/pyopenssl
python
def test_set_cipher_list_wrong_type(self, context): '\n `Context.set_cipher_list` raises `TypeError` when passed a non-string\n argument.\n ' with pytest.raises(TypeError): context.set_cipher_list(object())
def test_set_cipher_list_no_cipher_match(self, context): '\n `Context.set_cipher_list` raises `OpenSSL.SSL.Error` with a\n `"no cipher match"` reason string regardless of the TLS\n version.\n ' with pytest.raises(Error) as excinfo: context.set_cipher_list(b'imaginary-cipher') assert (excinfo.value.args == ([('SSL routines', 'SSL_CTX_set_cipher_list', 'no cipher match')],))
2,197,153,329,428,147,500
`Context.set_cipher_list` raises `OpenSSL.SSL.Error` with a `"no cipher match"` reason string regardless of the TLS version.
tests/test_ssl.py
test_set_cipher_list_no_cipher_match
dholth/pyopenssl
python
def test_set_cipher_list_no_cipher_match(self, context): '\n `Context.set_cipher_list` raises `OpenSSL.SSL.Error` with a\n `"no cipher match"` reason string regardless of the TLS\n version.\n ' with pytest.raises(Error) as excinfo: context.set_cipher_list(b'imaginary-cipher') assert (excinfo.value.args == ([('SSL routines', 'SSL_CTX_set_cipher_list', 'no cipher match')],))
def test_load_client_ca(self, context, ca_file): '\n `Context.load_client_ca` works as far as we can tell.\n ' context.load_client_ca(ca_file)
4,429,629,883,396,955,000
`Context.load_client_ca` works as far as we can tell.
tests/test_ssl.py
test_load_client_ca
dholth/pyopenssl
python
def test_load_client_ca(self, context, ca_file): '\n \n ' context.load_client_ca(ca_file)
def test_load_client_ca_invalid(self, context, tmpdir): '\n `Context.load_client_ca` raises an Error if the ca file is invalid.\n ' ca_file = tmpdir.join('test.pem') ca_file.write('') with pytest.raises(Error) as e: context.load_client_ca(str(ca_file).encode('ascii')) assert ('PEM routines' == e.value.args[0][0][0])
4,778,808,382,047,518,000
`Context.load_client_ca` raises an Error if the ca file is invalid.
tests/test_ssl.py
test_load_client_ca_invalid
dholth/pyopenssl
python
def test_load_client_ca_invalid(self, context, tmpdir): '\n \n ' ca_file = tmpdir.join('test.pem') ca_file.write() with pytest.raises(Error) as e: context.load_client_ca(str(ca_file).encode('ascii')) assert ('PEM routines' == e.value.args[0][0][0])
def test_load_client_ca_unicode(self, context, ca_file): '\n Passing the path as unicode raises a warning but works.\n ' pytest.deprecated_call(context.load_client_ca, ca_file.decode('ascii'))
-3,293,621,833,271,425,000
Passing the path as unicode raises a warning but works.
tests/test_ssl.py
test_load_client_ca_unicode
dholth/pyopenssl
python
def test_load_client_ca_unicode(self, context, ca_file): '\n \n ' pytest.deprecated_call(context.load_client_ca, ca_file.decode('ascii'))
def test_set_session_id(self, context): '\n `Context.set_session_id` works as far as we can tell.\n ' context.set_session_id(b'abc')
-4,135,581,903,286,941,000
`Context.set_session_id` works as far as we can tell.
tests/test_ssl.py
test_set_session_id
dholth/pyopenssl
python
def test_set_session_id(self, context): '\n \n ' context.set_session_id(b'abc')
def test_set_session_id_fail(self, context): '\n `Context.set_session_id` errors are propagated.\n ' with pytest.raises(Error) as e: context.set_session_id((b'abc' * 1000)) assert ([('SSL routines', 'SSL_CTX_set_session_id_context', 'ssl session id context too long')] == e.value.args[0])
8,692,005,860,328,724,000
`Context.set_session_id` errors are propagated.
tests/test_ssl.py
test_set_session_id_fail
dholth/pyopenssl
python
def test_set_session_id_fail(self, context): '\n \n ' with pytest.raises(Error) as e: context.set_session_id((b'abc' * 1000)) assert ([('SSL routines', 'SSL_CTX_set_session_id_context', 'ssl session id context too long')] == e.value.args[0])
def test_set_session_id_unicode(self, context): '\n `Context.set_session_id` raises a warning if a unicode string is\n passed.\n ' pytest.deprecated_call(context.set_session_id, u'abc')
-7,268,381,549,871,578,000
`Context.set_session_id` raises a warning if a unicode string is passed.
tests/test_ssl.py
test_set_session_id_unicode
dholth/pyopenssl
python
def test_set_session_id_unicode(self, context): '\n `Context.set_session_id` raises a warning if a unicode string is\n passed.\n ' pytest.deprecated_call(context.set_session_id, u'abc')
def test_method(self): '\n `Context` can be instantiated with one of `SSLv2_METHOD`,\n `SSLv3_METHOD`, `SSLv23_METHOD`, `TLSv1_METHOD`, `TLSv1_1_METHOD`,\n or `TLSv1_2_METHOD`.\n ' methods = [SSLv23_METHOD, TLSv1_METHOD] for meth in methods: Context(meth) maybe = [SSLv2_METHOD, SSLv3_METHOD, TLSv1_1_METHOD, TLSv1_2_METHOD] for meth in maybe: try: Context(meth) except (Error, ValueError): pass with pytest.raises(TypeError): Context('') with pytest.raises(ValueError): Context(10)
-762,603,195,658,717,300
`Context` can be instantiated with one of `SSLv2_METHOD`, `SSLv3_METHOD`, `SSLv23_METHOD`, `TLSv1_METHOD`, `TLSv1_1_METHOD`, or `TLSv1_2_METHOD`.
tests/test_ssl.py
test_method
dholth/pyopenssl
python
def test_method(self): '\n `Context` can be instantiated with one of `SSLv2_METHOD`,\n `SSLv3_METHOD`, `SSLv23_METHOD`, `TLSv1_METHOD`, `TLSv1_1_METHOD`,\n or `TLSv1_2_METHOD`.\n ' methods = [SSLv23_METHOD, TLSv1_METHOD] for meth in methods: Context(meth) maybe = [SSLv2_METHOD, SSLv3_METHOD, TLSv1_1_METHOD, TLSv1_2_METHOD] for meth in maybe: try: Context(meth) except (Error, ValueError): pass with pytest.raises(TypeError): Context() with pytest.raises(ValueError): Context(10)
def test_type(self): '\n `Context` can be used to create instances of that type.\n ' assert is_consistent_type(Context, 'Context', TLSv1_METHOD)
2,389,945,528,136,128,000
`Context` can be used to create instances of that type.
tests/test_ssl.py
test_type
dholth/pyopenssl
python
def test_type(self): '\n \n ' assert is_consistent_type(Context, 'Context', TLSv1_METHOD)
def test_use_privatekey(self): '\n `Context.use_privatekey` takes an `OpenSSL.crypto.PKey` instance.\n ' key = PKey() key.generate_key(TYPE_RSA, 512) ctx = Context(TLSv1_METHOD) ctx.use_privatekey(key) with pytest.raises(TypeError): ctx.use_privatekey('')
4,413,087,658,727,397,400
`Context.use_privatekey` takes an `OpenSSL.crypto.PKey` instance.
tests/test_ssl.py
test_use_privatekey
dholth/pyopenssl
python
def test_use_privatekey(self): '\n \n ' key = PKey() key.generate_key(TYPE_RSA, 512) ctx = Context(TLSv1_METHOD) ctx.use_privatekey(key) with pytest.raises(TypeError): ctx.use_privatekey()
def test_use_privatekey_file_missing(self, tmpfile): '\n `Context.use_privatekey_file` raises `OpenSSL.SSL.Error` when passed\n the name of a file which does not exist.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(Error): ctx.use_privatekey_file(tmpfile)
7,686,511,387,980,235,000
`Context.use_privatekey_file` raises `OpenSSL.SSL.Error` when passed the name of a file which does not exist.
tests/test_ssl.py
test_use_privatekey_file_missing
dholth/pyopenssl
python
def test_use_privatekey_file_missing(self, tmpfile): '\n `Context.use_privatekey_file` raises `OpenSSL.SSL.Error` when passed\n the name of a file which does not exist.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(Error): ctx.use_privatekey_file(tmpfile)
def _use_privatekey_file_test(self, pemfile, filetype): '\n Verify that calling ``Context.use_privatekey_file`` with the given\n arguments does not raise an exception.\n ' key = PKey() key.generate_key(TYPE_RSA, 512) with open(pemfile, 'wt') as pem: pem.write(dump_privatekey(FILETYPE_PEM, key).decode('ascii')) ctx = Context(TLSv1_METHOD) ctx.use_privatekey_file(pemfile, filetype)
-5,224,084,218,596,112,000
Verify that calling ``Context.use_privatekey_file`` with the given arguments does not raise an exception.
tests/test_ssl.py
_use_privatekey_file_test
dholth/pyopenssl
python
def _use_privatekey_file_test(self, pemfile, filetype): '\n Verify that calling ``Context.use_privatekey_file`` with the given\n arguments does not raise an exception.\n ' key = PKey() key.generate_key(TYPE_RSA, 512) with open(pemfile, 'wt') as pem: pem.write(dump_privatekey(FILETYPE_PEM, key).decode('ascii')) ctx = Context(TLSv1_METHOD) ctx.use_privatekey_file(pemfile, filetype)
@pytest.mark.parametrize('filetype', [object(), '', None, 1.0]) def test_wrong_privatekey_file_wrong_args(self, tmpfile, filetype): '\n `Context.use_privatekey_file` raises `TypeError` when called with\n a `filetype` which is not a valid file encoding.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(TypeError): ctx.use_privatekey_file(tmpfile, filetype)
-7,947,947,947,093,113,000
`Context.use_privatekey_file` raises `TypeError` when called with a `filetype` which is not a valid file encoding.
tests/test_ssl.py
test_wrong_privatekey_file_wrong_args
dholth/pyopenssl
python
@pytest.mark.parametrize('filetype', [object(), , None, 1.0]) def test_wrong_privatekey_file_wrong_args(self, tmpfile, filetype): '\n `Context.use_privatekey_file` raises `TypeError` when called with\n a `filetype` which is not a valid file encoding.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(TypeError): ctx.use_privatekey_file(tmpfile, filetype)
def test_use_privatekey_file_bytes(self, tmpfile): '\n A private key can be specified from a file by passing a ``bytes``\n instance giving the file name to ``Context.use_privatekey_file``.\n ' self._use_privatekey_file_test((tmpfile + NON_ASCII.encode(getfilesystemencoding())), FILETYPE_PEM)
8,040,275,944,748,485,000
A private key can be specified from a file by passing a ``bytes`` instance giving the file name to ``Context.use_privatekey_file``.
tests/test_ssl.py
test_use_privatekey_file_bytes
dholth/pyopenssl
python
def test_use_privatekey_file_bytes(self, tmpfile): '\n A private key can be specified from a file by passing a ``bytes``\n instance giving the file name to ``Context.use_privatekey_file``.\n ' self._use_privatekey_file_test((tmpfile + NON_ASCII.encode(getfilesystemencoding())), FILETYPE_PEM)
def test_use_privatekey_file_unicode(self, tmpfile): '\n A private key can be specified from a file by passing a ``unicode``\n instance giving the file name to ``Context.use_privatekey_file``.\n ' self._use_privatekey_file_test((tmpfile.decode(getfilesystemencoding()) + NON_ASCII), FILETYPE_PEM)
-6,078,741,914,969,915,000
A private key can be specified from a file by passing a ``unicode`` instance giving the file name to ``Context.use_privatekey_file``.
tests/test_ssl.py
test_use_privatekey_file_unicode
dholth/pyopenssl
python
def test_use_privatekey_file_unicode(self, tmpfile): '\n A private key can be specified from a file by passing a ``unicode``\n instance giving the file name to ``Context.use_privatekey_file``.\n ' self._use_privatekey_file_test((tmpfile.decode(getfilesystemencoding()) + NON_ASCII), FILETYPE_PEM)
def test_use_certificate_wrong_args(self): '\n `Context.use_certificate_wrong_args` raises `TypeError` when not passed\n exactly one `OpenSSL.crypto.X509` instance as an argument.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(TypeError): ctx.use_certificate('hello, world')
1,552,488,331,632,553,700
`Context.use_certificate_wrong_args` raises `TypeError` when not passed exactly one `OpenSSL.crypto.X509` instance as an argument.
tests/test_ssl.py
test_use_certificate_wrong_args
dholth/pyopenssl
python
def test_use_certificate_wrong_args(self): '\n `Context.use_certificate_wrong_args` raises `TypeError` when not passed\n exactly one `OpenSSL.crypto.X509` instance as an argument.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(TypeError): ctx.use_certificate('hello, world')
def test_use_certificate_uninitialized(self): '\n `Context.use_certificate` raises `OpenSSL.SSL.Error` when passed a\n `OpenSSL.crypto.X509` instance which has not been initialized\n (ie, which does not actually have any certificate data).\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(Error): ctx.use_certificate(X509())
9,123,769,684,629,414,000
`Context.use_certificate` raises `OpenSSL.SSL.Error` when passed a `OpenSSL.crypto.X509` instance which has not been initialized (ie, which does not actually have any certificate data).
tests/test_ssl.py
test_use_certificate_uninitialized
dholth/pyopenssl
python
def test_use_certificate_uninitialized(self): '\n `Context.use_certificate` raises `OpenSSL.SSL.Error` when passed a\n `OpenSSL.crypto.X509` instance which has not been initialized\n (ie, which does not actually have any certificate data).\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(Error): ctx.use_certificate(X509())
def test_use_certificate(self): '\n `Context.use_certificate` sets the certificate which will be\n used to identify connections created using the context.\n ' ctx = Context(TLSv1_METHOD) ctx.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM))
-4,644,153,754,773,890,000
`Context.use_certificate` sets the certificate which will be used to identify connections created using the context.
tests/test_ssl.py
test_use_certificate
dholth/pyopenssl
python
def test_use_certificate(self): '\n `Context.use_certificate` sets the certificate which will be\n used to identify connections created using the context.\n ' ctx = Context(TLSv1_METHOD) ctx.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM))
def test_use_certificate_file_wrong_args(self): '\n `Context.use_certificate_file` raises `TypeError` if the first\n argument is not a byte string or the second argument is not an integer.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(TypeError): ctx.use_certificate_file(object(), FILETYPE_PEM) with pytest.raises(TypeError): ctx.use_certificate_file(b'somefile', object()) with pytest.raises(TypeError): ctx.use_certificate_file(object(), FILETYPE_PEM)
2,614,508,622,063,213,000
`Context.use_certificate_file` raises `TypeError` if the first argument is not a byte string or the second argument is not an integer.
tests/test_ssl.py
test_use_certificate_file_wrong_args
dholth/pyopenssl
python
def test_use_certificate_file_wrong_args(self): '\n `Context.use_certificate_file` raises `TypeError` if the first\n argument is not a byte string or the second argument is not an integer.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(TypeError): ctx.use_certificate_file(object(), FILETYPE_PEM) with pytest.raises(TypeError): ctx.use_certificate_file(b'somefile', object()) with pytest.raises(TypeError): ctx.use_certificate_file(object(), FILETYPE_PEM)
def test_use_certificate_file_missing(self, tmpfile): '\n `Context.use_certificate_file` raises `OpenSSL.SSL.Error` if passed\n the name of a file which does not exist.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(Error): ctx.use_certificate_file(tmpfile)
3,554,422,916,819,344,000
`Context.use_certificate_file` raises `OpenSSL.SSL.Error` if passed the name of a file which does not exist.
tests/test_ssl.py
test_use_certificate_file_missing
dholth/pyopenssl
python
def test_use_certificate_file_missing(self, tmpfile): '\n `Context.use_certificate_file` raises `OpenSSL.SSL.Error` if passed\n the name of a file which does not exist.\n ' ctx = Context(TLSv1_METHOD) with pytest.raises(Error): ctx.use_certificate_file(tmpfile)
def _use_certificate_file_test(self, certificate_file): "\n Verify that calling ``Context.use_certificate_file`` with the given\n filename doesn't raise an exception.\n " with open(certificate_file, 'wb') as pem_file: pem_file.write(cleartextCertificatePEM) ctx = Context(TLSv1_METHOD) ctx.use_certificate_file(certificate_file)
1,345,640,362,837,311,000
Verify that calling ``Context.use_certificate_file`` with the given filename doesn't raise an exception.
tests/test_ssl.py
_use_certificate_file_test
dholth/pyopenssl
python
def _use_certificate_file_test(self, certificate_file): "\n Verify that calling ``Context.use_certificate_file`` with the given\n filename doesn't raise an exception.\n " with open(certificate_file, 'wb') as pem_file: pem_file.write(cleartextCertificatePEM) ctx = Context(TLSv1_METHOD) ctx.use_certificate_file(certificate_file)
def test_use_certificate_file_bytes(self, tmpfile): '\n `Context.use_certificate_file` sets the certificate (given as a\n `bytes` filename) which will be used to identify connections created\n using the context.\n ' filename = (tmpfile + NON_ASCII.encode(getfilesystemencoding())) self._use_certificate_file_test(filename)
8,179,352,861,917,950,000
`Context.use_certificate_file` sets the certificate (given as a `bytes` filename) which will be used to identify connections created using the context.
tests/test_ssl.py
test_use_certificate_file_bytes
dholth/pyopenssl
python
def test_use_certificate_file_bytes(self, tmpfile): '\n `Context.use_certificate_file` sets the certificate (given as a\n `bytes` filename) which will be used to identify connections created\n using the context.\n ' filename = (tmpfile + NON_ASCII.encode(getfilesystemencoding())) self._use_certificate_file_test(filename)
def test_use_certificate_file_unicode(self, tmpfile): '\n `Context.use_certificate_file` sets the certificate (given as a\n `bytes` filename) which will be used to identify connections created\n using the context.\n ' filename = (tmpfile.decode(getfilesystemencoding()) + NON_ASCII) self._use_certificate_file_test(filename)
1,032,322,822,054,261,800
`Context.use_certificate_file` sets the certificate (given as a `bytes` filename) which will be used to identify connections created using the context.
tests/test_ssl.py
test_use_certificate_file_unicode
dholth/pyopenssl
python
def test_use_certificate_file_unicode(self, tmpfile): '\n `Context.use_certificate_file` sets the certificate (given as a\n `bytes` filename) which will be used to identify connections created\n using the context.\n ' filename = (tmpfile.decode(getfilesystemencoding()) + NON_ASCII) self._use_certificate_file_test(filename)
def test_check_privatekey_valid(self): '\n `Context.check_privatekey` returns `None` if the `Context` instance\n has been configured to use a matched key and certificate pair.\n ' key = load_privatekey(FILETYPE_PEM, client_key_pem) cert = load_certificate(FILETYPE_PEM, client_cert_pem) context = Context(TLSv1_METHOD) context.use_privatekey(key) context.use_certificate(cert) assert (None is context.check_privatekey())
-8,546,845,383,698,951,000
`Context.check_privatekey` returns `None` if the `Context` instance has been configured to use a matched key and certificate pair.
tests/test_ssl.py
test_check_privatekey_valid
dholth/pyopenssl
python
def test_check_privatekey_valid(self): '\n `Context.check_privatekey` returns `None` if the `Context` instance\n has been configured to use a matched key and certificate pair.\n ' key = load_privatekey(FILETYPE_PEM, client_key_pem) cert = load_certificate(FILETYPE_PEM, client_cert_pem) context = Context(TLSv1_METHOD) context.use_privatekey(key) context.use_certificate(cert) assert (None is context.check_privatekey())
def test_check_privatekey_invalid(self): "\n `Context.check_privatekey` raises `Error` if the `Context` instance\n has been configured to use a key and certificate pair which don't\n relate to each other.\n " key = load_privatekey(FILETYPE_PEM, client_key_pem) cert = load_certificate(FILETYPE_PEM, server_cert_pem) context = Context(TLSv1_METHOD) context.use_privatekey(key) context.use_certificate(cert) with pytest.raises(Error): context.check_privatekey()
-6,533,540,895,717,894,000
`Context.check_privatekey` raises `Error` if the `Context` instance has been configured to use a key and certificate pair which don't relate to each other.
tests/test_ssl.py
test_check_privatekey_invalid
dholth/pyopenssl
python
def test_check_privatekey_invalid(self): "\n `Context.check_privatekey` raises `Error` if the `Context` instance\n has been configured to use a key and certificate pair which don't\n relate to each other.\n " key = load_privatekey(FILETYPE_PEM, client_key_pem) cert = load_certificate(FILETYPE_PEM, server_cert_pem) context = Context(TLSv1_METHOD) context.use_privatekey(key) context.use_certificate(cert) with pytest.raises(Error): context.check_privatekey()
def test_app_data(self): '\n `Context.set_app_data` stores an object for later retrieval\n using `Context.get_app_data`.\n ' app_data = object() context = Context(TLSv1_METHOD) context.set_app_data(app_data) assert (context.get_app_data() is app_data)
918,373,632,516,615,300
`Context.set_app_data` stores an object for later retrieval using `Context.get_app_data`.
tests/test_ssl.py
test_app_data
dholth/pyopenssl
python
def test_app_data(self): '\n `Context.set_app_data` stores an object for later retrieval\n using `Context.get_app_data`.\n ' app_data = object() context = Context(TLSv1_METHOD) context.set_app_data(app_data) assert (context.get_app_data() is app_data)
def test_set_options_wrong_args(self): '\n `Context.set_options` raises `TypeError` if called with\n a non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_options(None)
8,221,373,677,602,664,000
`Context.set_options` raises `TypeError` if called with a non-`int` argument.
tests/test_ssl.py
test_set_options_wrong_args
dholth/pyopenssl
python
def test_set_options_wrong_args(self): '\n `Context.set_options` raises `TypeError` if called with\n a non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_options(None)
def test_set_options(self): '\n `Context.set_options` returns the new options value.\n ' context = Context(TLSv1_METHOD) options = context.set_options(OP_NO_SSLv2) assert ((options & OP_NO_SSLv2) == OP_NO_SSLv2)
2,930,613,241,838,944,000
`Context.set_options` returns the new options value.
tests/test_ssl.py
test_set_options
dholth/pyopenssl
python
def test_set_options(self): '\n \n ' context = Context(TLSv1_METHOD) options = context.set_options(OP_NO_SSLv2) assert ((options & OP_NO_SSLv2) == OP_NO_SSLv2)
def test_set_mode_wrong_args(self): '\n `Context.set_mode` raises `TypeError` if called with\n a non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_mode(None)
6,845,116,333,278,275,000
`Context.set_mode` raises `TypeError` if called with a non-`int` argument.
tests/test_ssl.py
test_set_mode_wrong_args
dholth/pyopenssl
python
def test_set_mode_wrong_args(self): '\n `Context.set_mode` raises `TypeError` if called with\n a non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_mode(None)
def test_set_mode(self): '\n `Context.set_mode` accepts a mode bitvector and returns the\n newly set mode.\n ' context = Context(TLSv1_METHOD) assert (MODE_RELEASE_BUFFERS & context.set_mode(MODE_RELEASE_BUFFERS))
8,786,266,703,210,461,000
`Context.set_mode` accepts a mode bitvector and returns the newly set mode.
tests/test_ssl.py
test_set_mode
dholth/pyopenssl
python
def test_set_mode(self): '\n `Context.set_mode` accepts a mode bitvector and returns the\n newly set mode.\n ' context = Context(TLSv1_METHOD) assert (MODE_RELEASE_BUFFERS & context.set_mode(MODE_RELEASE_BUFFERS))
def test_set_timeout_wrong_args(self): '\n `Context.set_timeout` raises `TypeError` if called with\n a non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_timeout(None)
-6,365,149,923,549,140,000
`Context.set_timeout` raises `TypeError` if called with a non-`int` argument.
tests/test_ssl.py
test_set_timeout_wrong_args
dholth/pyopenssl
python
def test_set_timeout_wrong_args(self): '\n `Context.set_timeout` raises `TypeError` if called with\n a non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_timeout(None)
def test_timeout(self): '\n `Context.set_timeout` sets the session timeout for all connections\n created using the context object. `Context.get_timeout` retrieves\n this value.\n ' context = Context(TLSv1_METHOD) context.set_timeout(1234) assert (context.get_timeout() == 1234)
4,496,753,818,467,810,000
`Context.set_timeout` sets the session timeout for all connections created using the context object. `Context.get_timeout` retrieves this value.
tests/test_ssl.py
test_timeout
dholth/pyopenssl
python
def test_timeout(self): '\n `Context.set_timeout` sets the session timeout for all connections\n created using the context object. `Context.get_timeout` retrieves\n this value.\n ' context = Context(TLSv1_METHOD) context.set_timeout(1234) assert (context.get_timeout() == 1234)
def test_set_verify_depth_wrong_args(self): '\n `Context.set_verify_depth` raises `TypeError` if called with a\n non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_verify_depth(None)
3,364,662,358,626,962,000
`Context.set_verify_depth` raises `TypeError` if called with a non-`int` argument.
tests/test_ssl.py
test_set_verify_depth_wrong_args
dholth/pyopenssl
python
def test_set_verify_depth_wrong_args(self): '\n `Context.set_verify_depth` raises `TypeError` if called with a\n non-`int` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_verify_depth(None)
def test_verify_depth(self): '\n `Context.set_verify_depth` sets the number of certificates in\n a chain to follow before giving up. The value can be retrieved with\n `Context.get_verify_depth`.\n ' context = Context(TLSv1_METHOD) context.set_verify_depth(11) assert (context.get_verify_depth() == 11)
-117,435,167,838,129,890
`Context.set_verify_depth` sets the number of certificates in a chain to follow before giving up. The value can be retrieved with `Context.get_verify_depth`.
tests/test_ssl.py
test_verify_depth
dholth/pyopenssl
python
def test_verify_depth(self): '\n `Context.set_verify_depth` sets the number of certificates in\n a chain to follow before giving up. The value can be retrieved with\n `Context.get_verify_depth`.\n ' context = Context(TLSv1_METHOD) context.set_verify_depth(11) assert (context.get_verify_depth() == 11)
def _write_encrypted_pem(self, passphrase, tmpfile): '\n Write a new private key out to a new file, encrypted using the given\n passphrase. Return the path to the new file.\n ' key = PKey() key.generate_key(TYPE_RSA, 512) pem = dump_privatekey(FILETYPE_PEM, key, 'blowfish', passphrase) with open(tmpfile, 'w') as fObj: fObj.write(pem.decode('ascii')) return tmpfile
2,605,068,826,527,080,000
Write a new private key out to a new file, encrypted using the given passphrase. Return the path to the new file.
tests/test_ssl.py
_write_encrypted_pem
dholth/pyopenssl
python
def _write_encrypted_pem(self, passphrase, tmpfile): '\n Write a new private key out to a new file, encrypted using the given\n passphrase. Return the path to the new file.\n ' key = PKey() key.generate_key(TYPE_RSA, 512) pem = dump_privatekey(FILETYPE_PEM, key, 'blowfish', passphrase) with open(tmpfile, 'w') as fObj: fObj.write(pem.decode('ascii')) return tmpfile
def test_set_passwd_cb_wrong_args(self): '\n `Context.set_passwd_cb` raises `TypeError` if called with a\n non-callable first argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_passwd_cb(None)
4,184,945,237,863,431,700
`Context.set_passwd_cb` raises `TypeError` if called with a non-callable first argument.
tests/test_ssl.py
test_set_passwd_cb_wrong_args
dholth/pyopenssl
python
def test_set_passwd_cb_wrong_args(self): '\n `Context.set_passwd_cb` raises `TypeError` if called with a\n non-callable first argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_passwd_cb(None)
def test_set_passwd_cb(self, tmpfile): '\n `Context.set_passwd_cb` accepts a callable which will be invoked when\n a private key is loaded from an encrypted PEM.\n ' passphrase = b'foobar' pemFile = self._write_encrypted_pem(passphrase, tmpfile) calledWith = [] def passphraseCallback(maxlen, verify, extra): calledWith.append((maxlen, verify, extra)) return passphrase context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) context.use_privatekey_file(pemFile) assert (len(calledWith) == 1) assert isinstance(calledWith[0][0], int) assert isinstance(calledWith[0][1], int) assert (calledWith[0][2] is None)
428,751,254,240,725,700
`Context.set_passwd_cb` accepts a callable which will be invoked when a private key is loaded from an encrypted PEM.
tests/test_ssl.py
test_set_passwd_cb
dholth/pyopenssl
python
def test_set_passwd_cb(self, tmpfile): '\n `Context.set_passwd_cb` accepts a callable which will be invoked when\n a private key is loaded from an encrypted PEM.\n ' passphrase = b'foobar' pemFile = self._write_encrypted_pem(passphrase, tmpfile) calledWith = [] def passphraseCallback(maxlen, verify, extra): calledWith.append((maxlen, verify, extra)) return passphrase context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) context.use_privatekey_file(pemFile) assert (len(calledWith) == 1) assert isinstance(calledWith[0][0], int) assert isinstance(calledWith[0][1], int) assert (calledWith[0][2] is None)
def test_passwd_callback_exception(self, tmpfile): '\n `Context.use_privatekey_file` propagates any exception raised\n by the passphrase callback.\n ' pemFile = self._write_encrypted_pem(b'monkeys are nice', tmpfile) def passphraseCallback(maxlen, verify, extra): raise RuntimeError('Sorry, I am a fail.') context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) with pytest.raises(RuntimeError): context.use_privatekey_file(pemFile)
6,575,019,216,700,996,000
`Context.use_privatekey_file` propagates any exception raised by the passphrase callback.
tests/test_ssl.py
test_passwd_callback_exception
dholth/pyopenssl
python
def test_passwd_callback_exception(self, tmpfile): '\n `Context.use_privatekey_file` propagates any exception raised\n by the passphrase callback.\n ' pemFile = self._write_encrypted_pem(b'monkeys are nice', tmpfile) def passphraseCallback(maxlen, verify, extra): raise RuntimeError('Sorry, I am a fail.') context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) with pytest.raises(RuntimeError): context.use_privatekey_file(pemFile)
def test_passwd_callback_false(self, tmpfile): '\n `Context.use_privatekey_file` raises `OpenSSL.SSL.Error` if the\n passphrase callback returns a false value.\n ' pemFile = self._write_encrypted_pem(b'monkeys are nice', tmpfile) def passphraseCallback(maxlen, verify, extra): return b'' context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) with pytest.raises(Error): context.use_privatekey_file(pemFile)
-3,169,492,183,423,473,700
`Context.use_privatekey_file` raises `OpenSSL.SSL.Error` if the passphrase callback returns a false value.
tests/test_ssl.py
test_passwd_callback_false
dholth/pyopenssl
python
def test_passwd_callback_false(self, tmpfile): '\n `Context.use_privatekey_file` raises `OpenSSL.SSL.Error` if the\n passphrase callback returns a false value.\n ' pemFile = self._write_encrypted_pem(b'monkeys are nice', tmpfile) def passphraseCallback(maxlen, verify, extra): return b context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) with pytest.raises(Error): context.use_privatekey_file(pemFile)
def test_passwd_callback_non_string(self, tmpfile): '\n `Context.use_privatekey_file` raises `OpenSSL.SSL.Error` if the\n passphrase callback returns a true non-string value.\n ' pemFile = self._write_encrypted_pem(b'monkeys are nice', tmpfile) def passphraseCallback(maxlen, verify, extra): return 10 context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) with pytest.raises(ValueError): context.use_privatekey_file(pemFile)
7,552,318,558,258,498,000
`Context.use_privatekey_file` raises `OpenSSL.SSL.Error` if the passphrase callback returns a true non-string value.
tests/test_ssl.py
test_passwd_callback_non_string
dholth/pyopenssl
python
def test_passwd_callback_non_string(self, tmpfile): '\n `Context.use_privatekey_file` raises `OpenSSL.SSL.Error` if the\n passphrase callback returns a true non-string value.\n ' pemFile = self._write_encrypted_pem(b'monkeys are nice', tmpfile) def passphraseCallback(maxlen, verify, extra): return 10 context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) with pytest.raises(ValueError): context.use_privatekey_file(pemFile)
def test_passwd_callback_too_long(self, tmpfile): '\n If the passphrase returned by the passphrase callback returns a string\n longer than the indicated maximum length, it is truncated.\n ' passphrase = (b'x' * 1024) pemFile = self._write_encrypted_pem(passphrase, tmpfile) def passphraseCallback(maxlen, verify, extra): assert (maxlen == 1024) return (passphrase + b'y') context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) context.use_privatekey_file(pemFile)
8,390,858,930,258,623,000
If the passphrase returned by the passphrase callback returns a string longer than the indicated maximum length, it is truncated.
tests/test_ssl.py
test_passwd_callback_too_long
dholth/pyopenssl
python
def test_passwd_callback_too_long(self, tmpfile): '\n If the passphrase returned by the passphrase callback returns a string\n longer than the indicated maximum length, it is truncated.\n ' passphrase = (b'x' * 1024) pemFile = self._write_encrypted_pem(passphrase, tmpfile) def passphraseCallback(maxlen, verify, extra): assert (maxlen == 1024) return (passphrase + b'y') context = Context(TLSv1_METHOD) context.set_passwd_cb(passphraseCallback) context.use_privatekey_file(pemFile)
def test_set_info_callback(self): '\n `Context.set_info_callback` accepts a callable which will be\n invoked when certain information about an SSL connection is available.\n ' (server, client) = socket_pair() clientSSL = Connection(Context(TLSv1_METHOD), client) clientSSL.set_connect_state() called = [] def info(conn, where, ret): called.append((conn, where, ret)) context = Context(TLSv1_METHOD) context.set_info_callback(info) context.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) context.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverSSL = Connection(context, server) serverSSL.set_accept_state() handshake(clientSSL, serverSSL) notConnections = [conn for (conn, where, ret) in called if (not isinstance(conn, Connection))] assert ([] == notConnections), 'Some info callback arguments were not Connection instances.'
-1,624,127,154,000,247,600
`Context.set_info_callback` accepts a callable which will be invoked when certain information about an SSL connection is available.
tests/test_ssl.py
test_set_info_callback
dholth/pyopenssl
python
def test_set_info_callback(self): '\n `Context.set_info_callback` accepts a callable which will be\n invoked when certain information about an SSL connection is available.\n ' (server, client) = socket_pair() clientSSL = Connection(Context(TLSv1_METHOD), client) clientSSL.set_connect_state() called = [] def info(conn, where, ret): called.append((conn, where, ret)) context = Context(TLSv1_METHOD) context.set_info_callback(info) context.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) context.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverSSL = Connection(context, server) serverSSL.set_accept_state() handshake(clientSSL, serverSSL) notConnections = [conn for (conn, where, ret) in called if (not isinstance(conn, Connection))] assert ([] == notConnections), 'Some info callback arguments were not Connection instances.'
def _load_verify_locations_test(self, *args): '\n Create a client context which will verify the peer certificate and call\n its `load_verify_locations` method with the given arguments.\n Then connect it to a server and ensure that the handshake succeeds.\n ' (server, client) = socket_pair() clientContext = Context(TLSv1_METHOD) clientContext.load_verify_locations(*args) clientContext.set_verify(VERIFY_PEER, (lambda conn, cert, errno, depth, preverify_ok: preverify_ok)) clientSSL = Connection(clientContext, client) clientSSL.set_connect_state() serverContext = Context(TLSv1_METHOD) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverSSL = Connection(serverContext, server) serverSSL.set_accept_state() handshake(clientSSL, serverSSL) cert = clientSSL.get_peer_certificate() assert (cert.get_subject().CN == 'Testing Root CA')
8,106,486,977,570,990,000
Create a client context which will verify the peer certificate and call its `load_verify_locations` method with the given arguments. Then connect it to a server and ensure that the handshake succeeds.
tests/test_ssl.py
_load_verify_locations_test
dholth/pyopenssl
python
def _load_verify_locations_test(self, *args): '\n Create a client context which will verify the peer certificate and call\n its `load_verify_locations` method with the given arguments.\n Then connect it to a server and ensure that the handshake succeeds.\n ' (server, client) = socket_pair() clientContext = Context(TLSv1_METHOD) clientContext.load_verify_locations(*args) clientContext.set_verify(VERIFY_PEER, (lambda conn, cert, errno, depth, preverify_ok: preverify_ok)) clientSSL = Connection(clientContext, client) clientSSL.set_connect_state() serverContext = Context(TLSv1_METHOD) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverSSL = Connection(serverContext, server) serverSSL.set_accept_state() handshake(clientSSL, serverSSL) cert = clientSSL.get_peer_certificate() assert (cert.get_subject().CN == 'Testing Root CA')
def _load_verify_cafile(self, cafile): '\n Verify that if path to a file containing a certificate is passed to\n `Context.load_verify_locations` for the ``cafile`` parameter, that\n certificate is used as a trust root for the purposes of verifying\n connections created using that `Context`.\n ' with open(cafile, 'w') as fObj: fObj.write(cleartextCertificatePEM.decode('ascii')) self._load_verify_locations_test(cafile)
7,611,278,190,374,224,000
Verify that if path to a file containing a certificate is passed to `Context.load_verify_locations` for the ``cafile`` parameter, that certificate is used as a trust root for the purposes of verifying connections created using that `Context`.
tests/test_ssl.py
_load_verify_cafile
dholth/pyopenssl
python
def _load_verify_cafile(self, cafile): '\n Verify that if path to a file containing a certificate is passed to\n `Context.load_verify_locations` for the ``cafile`` parameter, that\n certificate is used as a trust root for the purposes of verifying\n connections created using that `Context`.\n ' with open(cafile, 'w') as fObj: fObj.write(cleartextCertificatePEM.decode('ascii')) self._load_verify_locations_test(cafile)
def test_load_verify_bytes_cafile(self, tmpfile): '\n `Context.load_verify_locations` accepts a file name as a `bytes`\n instance and uses the certificates within for verification purposes.\n ' cafile = (tmpfile + NON_ASCII.encode(getfilesystemencoding())) self._load_verify_cafile(cafile)
-5,838,643,166,151,545,000
`Context.load_verify_locations` accepts a file name as a `bytes` instance and uses the certificates within for verification purposes.
tests/test_ssl.py
test_load_verify_bytes_cafile
dholth/pyopenssl
python
def test_load_verify_bytes_cafile(self, tmpfile): '\n `Context.load_verify_locations` accepts a file name as a `bytes`\n instance and uses the certificates within for verification purposes.\n ' cafile = (tmpfile + NON_ASCII.encode(getfilesystemencoding())) self._load_verify_cafile(cafile)
def test_load_verify_unicode_cafile(self, tmpfile): '\n `Context.load_verify_locations` accepts a file name as a `unicode`\n instance and uses the certificates within for verification purposes.\n ' self._load_verify_cafile((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
-3,865,764,253,149,244,000
`Context.load_verify_locations` accepts a file name as a `unicode` instance and uses the certificates within for verification purposes.
tests/test_ssl.py
test_load_verify_unicode_cafile
dholth/pyopenssl
python
def test_load_verify_unicode_cafile(self, tmpfile): '\n `Context.load_verify_locations` accepts a file name as a `unicode`\n instance and uses the certificates within for verification purposes.\n ' self._load_verify_cafile((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
def test_load_verify_invalid_file(self, tmpfile): '\n `Context.load_verify_locations` raises `Error` when passed a\n non-existent cafile.\n ' clientContext = Context(TLSv1_METHOD) with pytest.raises(Error): clientContext.load_verify_locations(tmpfile)
1,632,863,128,893,833,200
`Context.load_verify_locations` raises `Error` when passed a non-existent cafile.
tests/test_ssl.py
test_load_verify_invalid_file
dholth/pyopenssl
python
def test_load_verify_invalid_file(self, tmpfile): '\n `Context.load_verify_locations` raises `Error` when passed a\n non-existent cafile.\n ' clientContext = Context(TLSv1_METHOD) with pytest.raises(Error): clientContext.load_verify_locations(tmpfile)
def _load_verify_directory_locations_capath(self, capath): '\n Verify that if path to a directory containing certificate files is\n passed to ``Context.load_verify_locations`` for the ``capath``\n parameter, those certificates are used as trust roots for the purposes\n of verifying connections created using that ``Context``.\n ' makedirs(capath) for name in [b'c7adac82.0', b'c3705638.0']: cafile = join_bytes_or_unicode(capath, name) with open(cafile, 'w') as fObj: fObj.write(cleartextCertificatePEM.decode('ascii')) self._load_verify_locations_test(None, capath)
-9,146,979,112,552,397,000
Verify that if path to a directory containing certificate files is passed to ``Context.load_verify_locations`` for the ``capath`` parameter, those certificates are used as trust roots for the purposes of verifying connections created using that ``Context``.
tests/test_ssl.py
_load_verify_directory_locations_capath
dholth/pyopenssl
python
def _load_verify_directory_locations_capath(self, capath): '\n Verify that if path to a directory containing certificate files is\n passed to ``Context.load_verify_locations`` for the ``capath``\n parameter, those certificates are used as trust roots for the purposes\n of verifying connections created using that ``Context``.\n ' makedirs(capath) for name in [b'c7adac82.0', b'c3705638.0']: cafile = join_bytes_or_unicode(capath, name) with open(cafile, 'w') as fObj: fObj.write(cleartextCertificatePEM.decode('ascii')) self._load_verify_locations_test(None, capath)
def test_load_verify_directory_bytes_capath(self, tmpfile): '\n `Context.load_verify_locations` accepts a directory name as a `bytes`\n instance and uses the certificates within for verification purposes.\n ' self._load_verify_directory_locations_capath((tmpfile + NON_ASCII.encode(getfilesystemencoding())))
3,514,306,032,294,987,300
`Context.load_verify_locations` accepts a directory name as a `bytes` instance and uses the certificates within for verification purposes.
tests/test_ssl.py
test_load_verify_directory_bytes_capath
dholth/pyopenssl
python
def test_load_verify_directory_bytes_capath(self, tmpfile): '\n `Context.load_verify_locations` accepts a directory name as a `bytes`\n instance and uses the certificates within for verification purposes.\n ' self._load_verify_directory_locations_capath((tmpfile + NON_ASCII.encode(getfilesystemencoding())))
def test_load_verify_directory_unicode_capath(self, tmpfile): '\n `Context.load_verify_locations` accepts a directory name as a `unicode`\n instance and uses the certificates within for verification purposes.\n ' self._load_verify_directory_locations_capath((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
-2,139,179,617,607,170,600
`Context.load_verify_locations` accepts a directory name as a `unicode` instance and uses the certificates within for verification purposes.
tests/test_ssl.py
test_load_verify_directory_unicode_capath
dholth/pyopenssl
python
def test_load_verify_directory_unicode_capath(self, tmpfile): '\n `Context.load_verify_locations` accepts a directory name as a `unicode`\n instance and uses the certificates within for verification purposes.\n ' self._load_verify_directory_locations_capath((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
def test_load_verify_locations_wrong_args(self): '\n `Context.load_verify_locations` raises `TypeError` if with non-`str`\n arguments.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.load_verify_locations(object()) with pytest.raises(TypeError): context.load_verify_locations(object(), object())
7,047,999,644,003,334,000
`Context.load_verify_locations` raises `TypeError` if with non-`str` arguments.
tests/test_ssl.py
test_load_verify_locations_wrong_args
dholth/pyopenssl
python
def test_load_verify_locations_wrong_args(self): '\n `Context.load_verify_locations` raises `TypeError` if with non-`str`\n arguments.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.load_verify_locations(object()) with pytest.raises(TypeError): context.load_verify_locations(object(), object())
@pytest.mark.skipif((not platform.startswith('linux')), reason='Loading fallback paths is a linux-specific behavior to accommodate pyca/cryptography manylinux1 wheels') def test_fallback_default_verify_paths(self, monkeypatch): "\n Test that we load certificates successfully on linux from the fallback\n path. To do this we set the _CRYPTOGRAPHY_MANYLINUX1_CA_FILE and\n _CRYPTOGRAPHY_MANYLINUX1_CA_DIR vars to be equal to whatever the\n current OpenSSL default is and we disable\n SSL_CTX_SET_default_verify_paths so that it can't find certs unless\n it loads via fallback.\n " context = Context(TLSv1_METHOD) monkeypatch.setattr(_lib, 'SSL_CTX_set_default_verify_paths', (lambda x: 1)) monkeypatch.setattr(SSL, '_CRYPTOGRAPHY_MANYLINUX1_CA_FILE', _ffi.string(_lib.X509_get_default_cert_file())) monkeypatch.setattr(SSL, '_CRYPTOGRAPHY_MANYLINUX1_CA_DIR', _ffi.string(_lib.X509_get_default_cert_dir())) context.set_default_verify_paths() store = context.get_cert_store() sk_obj = _lib.X509_STORE_get0_objects(store._store) assert (sk_obj != _ffi.NULL) num = _lib.sk_X509_OBJECT_num(sk_obj) assert (num != 0)
-6,223,923,541,584,947,000
Test that we load certificates successfully on linux from the fallback path. To do this we set the _CRYPTOGRAPHY_MANYLINUX1_CA_FILE and _CRYPTOGRAPHY_MANYLINUX1_CA_DIR vars to be equal to whatever the current OpenSSL default is and we disable SSL_CTX_SET_default_verify_paths so that it can't find certs unless it loads via fallback.
tests/test_ssl.py
test_fallback_default_verify_paths
dholth/pyopenssl
python
@pytest.mark.skipif((not platform.startswith('linux')), reason='Loading fallback paths is a linux-specific behavior to accommodate pyca/cryptography manylinux1 wheels') def test_fallback_default_verify_paths(self, monkeypatch): "\n Test that we load certificates successfully on linux from the fallback\n path. To do this we set the _CRYPTOGRAPHY_MANYLINUX1_CA_FILE and\n _CRYPTOGRAPHY_MANYLINUX1_CA_DIR vars to be equal to whatever the\n current OpenSSL default is and we disable\n SSL_CTX_SET_default_verify_paths so that it can't find certs unless\n it loads via fallback.\n " context = Context(TLSv1_METHOD) monkeypatch.setattr(_lib, 'SSL_CTX_set_default_verify_paths', (lambda x: 1)) monkeypatch.setattr(SSL, '_CRYPTOGRAPHY_MANYLINUX1_CA_FILE', _ffi.string(_lib.X509_get_default_cert_file())) monkeypatch.setattr(SSL, '_CRYPTOGRAPHY_MANYLINUX1_CA_DIR', _ffi.string(_lib.X509_get_default_cert_dir())) context.set_default_verify_paths() store = context.get_cert_store() sk_obj = _lib.X509_STORE_get0_objects(store._store) assert (sk_obj != _ffi.NULL) num = _lib.sk_X509_OBJECT_num(sk_obj) assert (num != 0)
def test_check_env_vars(self, monkeypatch): '\n Test that we return True/False appropriately if the env vars are set.\n ' context = Context(TLSv1_METHOD) dir_var = 'CUSTOM_DIR_VAR' file_var = 'CUSTOM_FILE_VAR' assert (context._check_env_vars_set(dir_var, file_var) is False) monkeypatch.setenv(dir_var, 'value') monkeypatch.setenv(file_var, 'value') assert (context._check_env_vars_set(dir_var, file_var) is True) assert (context._check_env_vars_set(dir_var, file_var) is True)
1,356,964,034,209,508,900
Test that we return True/False appropriately if the env vars are set.
tests/test_ssl.py
test_check_env_vars
dholth/pyopenssl
python
def test_check_env_vars(self, monkeypatch): '\n \n ' context = Context(TLSv1_METHOD) dir_var = 'CUSTOM_DIR_VAR' file_var = 'CUSTOM_FILE_VAR' assert (context._check_env_vars_set(dir_var, file_var) is False) monkeypatch.setenv(dir_var, 'value') monkeypatch.setenv(file_var, 'value') assert (context._check_env_vars_set(dir_var, file_var) is True) assert (context._check_env_vars_set(dir_var, file_var) is True)
def test_verify_no_fallback_if_env_vars_set(self, monkeypatch): "\n Test that we don't use the fallback path if env vars are set.\n " context = Context(TLSv1_METHOD) monkeypatch.setattr(_lib, 'SSL_CTX_set_default_verify_paths', (lambda x: 1)) dir_env_var = _ffi.string(_lib.X509_get_default_cert_dir_env()).decode('ascii') file_env_var = _ffi.string(_lib.X509_get_default_cert_file_env()).decode('ascii') monkeypatch.setenv(dir_env_var, 'value') monkeypatch.setenv(file_env_var, 'value') context.set_default_verify_paths() monkeypatch.setattr(context, '_fallback_default_verify_paths', raiser(SystemError)) context.set_default_verify_paths()
9,116,885,800,212,725,000
Test that we don't use the fallback path if env vars are set.
tests/test_ssl.py
test_verify_no_fallback_if_env_vars_set
dholth/pyopenssl
python
def test_verify_no_fallback_if_env_vars_set(self, monkeypatch): "\n \n " context = Context(TLSv1_METHOD) monkeypatch.setattr(_lib, 'SSL_CTX_set_default_verify_paths', (lambda x: 1)) dir_env_var = _ffi.string(_lib.X509_get_default_cert_dir_env()).decode('ascii') file_env_var = _ffi.string(_lib.X509_get_default_cert_file_env()).decode('ascii') monkeypatch.setenv(dir_env_var, 'value') monkeypatch.setenv(file_env_var, 'value') context.set_default_verify_paths() monkeypatch.setattr(context, '_fallback_default_verify_paths', raiser(SystemError)) context.set_default_verify_paths()
@pytest.mark.skipif((platform == 'win32'), reason='set_default_verify_paths appears not to work on Windows. See LP#404343 and LP#404344.') def test_set_default_verify_paths(self): '\n `Context.set_default_verify_paths` causes the platform-specific CA\n certificate locations to be used for verification purposes.\n ' context = Context(SSLv23_METHOD) context.set_default_verify_paths() context.set_verify(VERIFY_PEER, (lambda conn, cert, errno, depth, preverify_ok: preverify_ok)) client = socket_any_family() client.connect(('encrypted.google.com', 443)) clientSSL = Connection(context, client) clientSSL.set_connect_state() clientSSL.set_tlsext_host_name(b'encrypted.google.com') clientSSL.do_handshake() clientSSL.send(b'GET / HTTP/1.0\r\n\r\n') assert clientSSL.recv(1024)
8,359,346,820,879,438,000
`Context.set_default_verify_paths` causes the platform-specific CA certificate locations to be used for verification purposes.
tests/test_ssl.py
test_set_default_verify_paths
dholth/pyopenssl
python
@pytest.mark.skipif((platform == 'win32'), reason='set_default_verify_paths appears not to work on Windows. See LP#404343 and LP#404344.') def test_set_default_verify_paths(self): '\n `Context.set_default_verify_paths` causes the platform-specific CA\n certificate locations to be used for verification purposes.\n ' context = Context(SSLv23_METHOD) context.set_default_verify_paths() context.set_verify(VERIFY_PEER, (lambda conn, cert, errno, depth, preverify_ok: preverify_ok)) client = socket_any_family() client.connect(('encrypted.google.com', 443)) clientSSL = Connection(context, client) clientSSL.set_connect_state() clientSSL.set_tlsext_host_name(b'encrypted.google.com') clientSSL.do_handshake() clientSSL.send(b'GET / HTTP/1.0\r\n\r\n') assert clientSSL.recv(1024)
def test_fallback_path_is_not_file_or_dir(self): '\n Test that when passed empty arrays or paths that do not exist no\n errors are raised.\n ' context = Context(TLSv1_METHOD) context._fallback_default_verify_paths([], []) context._fallback_default_verify_paths(['/not/a/file'], ['/not/a/dir'])
8,313,584,376,822,908,000
Test that when passed empty arrays or paths that do not exist no errors are raised.
tests/test_ssl.py
test_fallback_path_is_not_file_or_dir
dholth/pyopenssl
python
def test_fallback_path_is_not_file_or_dir(self): '\n Test that when passed empty arrays or paths that do not exist no\n errors are raised.\n ' context = Context(TLSv1_METHOD) context._fallback_default_verify_paths([], []) context._fallback_default_verify_paths(['/not/a/file'], ['/not/a/dir'])
def test_add_extra_chain_cert_invalid_cert(self): '\n `Context.add_extra_chain_cert` raises `TypeError` if called with an\n object which is not an instance of `X509`.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.add_extra_chain_cert(object())
3,380,251,861,144,888,300
`Context.add_extra_chain_cert` raises `TypeError` if called with an object which is not an instance of `X509`.
tests/test_ssl.py
test_add_extra_chain_cert_invalid_cert
dholth/pyopenssl
python
def test_add_extra_chain_cert_invalid_cert(self): '\n `Context.add_extra_chain_cert` raises `TypeError` if called with an\n object which is not an instance of `X509`.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.add_extra_chain_cert(object())
def _handshake_test(self, serverContext, clientContext): '\n Verify that a client and server created with the given contexts can\n successfully handshake and communicate.\n ' (serverSocket, clientSocket) = socket_pair() server = Connection(serverContext, serverSocket) server.set_accept_state() client = Connection(clientContext, clientSocket) client.set_connect_state() for _ in range(3): for s in [client, server]: try: s.do_handshake() except WantReadError: pass
-4,352,019,866,534,083,000
Verify that a client and server created with the given contexts can successfully handshake and communicate.
tests/test_ssl.py
_handshake_test
dholth/pyopenssl
python
def _handshake_test(self, serverContext, clientContext): '\n Verify that a client and server created with the given contexts can\n successfully handshake and communicate.\n ' (serverSocket, clientSocket) = socket_pair() server = Connection(serverContext, serverSocket) server.set_accept_state() client = Connection(clientContext, clientSocket) client.set_connect_state() for _ in range(3): for s in [client, server]: try: s.do_handshake() except WantReadError: pass
def test_set_verify_callback_connection_argument(self): '\n The first argument passed to the verify callback is the\n `Connection` instance for which verification is taking place.\n ' serverContext = Context(TLSv1_METHOD) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) serverConnection = Connection(serverContext, None) class VerifyCallback(object): def callback(self, connection, *args): self.connection = connection return 1 verify = VerifyCallback() clientContext = Context(TLSv1_METHOD) clientContext.set_verify(VERIFY_PEER, verify.callback) clientConnection = Connection(clientContext, None) clientConnection.set_connect_state() handshake_in_memory(clientConnection, serverConnection) assert (verify.connection is clientConnection)
-6,607,677,239,644,830,000
The first argument passed to the verify callback is the `Connection` instance for which verification is taking place.
tests/test_ssl.py
test_set_verify_callback_connection_argument
dholth/pyopenssl
python
def test_set_verify_callback_connection_argument(self): '\n The first argument passed to the verify callback is the\n `Connection` instance for which verification is taking place.\n ' serverContext = Context(TLSv1_METHOD) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) serverConnection = Connection(serverContext, None) class VerifyCallback(object): def callback(self, connection, *args): self.connection = connection return 1 verify = VerifyCallback() clientContext = Context(TLSv1_METHOD) clientContext.set_verify(VERIFY_PEER, verify.callback) clientConnection = Connection(clientContext, None) clientConnection.set_connect_state() handshake_in_memory(clientConnection, serverConnection) assert (verify.connection is clientConnection)
def test_x509_in_verify_works(self): "\n We had a bug where the X509 cert instantiated in the callback wrapper\n didn't __init__ so it was missing objects needed when calling\n get_subject. This test sets up a handshake where we call get_subject\n on the cert provided to the verify callback.\n " serverContext = Context(TLSv1_METHOD) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) serverConnection = Connection(serverContext, None) def verify_cb_get_subject(conn, cert, errnum, depth, ok): assert cert.get_subject() return 1 clientContext = Context(TLSv1_METHOD) clientContext.set_verify(VERIFY_PEER, verify_cb_get_subject) clientConnection = Connection(clientContext, None) clientConnection.set_connect_state() handshake_in_memory(clientConnection, serverConnection)
778,834,109,025,078,800
We had a bug where the X509 cert instantiated in the callback wrapper didn't __init__ so it was missing objects needed when calling get_subject. This test sets up a handshake where we call get_subject on the cert provided to the verify callback.
tests/test_ssl.py
test_x509_in_verify_works
dholth/pyopenssl
python
def test_x509_in_verify_works(self): "\n We had a bug where the X509 cert instantiated in the callback wrapper\n didn't __init__ so it was missing objects needed when calling\n get_subject. This test sets up a handshake where we call get_subject\n on the cert provided to the verify callback.\n " serverContext = Context(TLSv1_METHOD) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) serverConnection = Connection(serverContext, None) def verify_cb_get_subject(conn, cert, errnum, depth, ok): assert cert.get_subject() return 1 clientContext = Context(TLSv1_METHOD) clientContext.set_verify(VERIFY_PEER, verify_cb_get_subject) clientConnection = Connection(clientContext, None) clientConnection.set_connect_state() handshake_in_memory(clientConnection, serverConnection)
def test_set_verify_callback_exception(self): '\n If the verify callback passed to `Context.set_verify` raises an\n exception, verification fails and the exception is propagated to the\n caller of `Connection.do_handshake`.\n ' serverContext = Context(TLSv1_2_METHOD) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) clientContext = Context(TLSv1_2_METHOD) def verify_callback(*args): raise Exception('silly verify failure') clientContext.set_verify(VERIFY_PEER, verify_callback) with pytest.raises(Exception) as exc: self._handshake_test(serverContext, clientContext) assert ('silly verify failure' == str(exc.value))
3,982,180,120,611,278,300
If the verify callback passed to `Context.set_verify` raises an exception, verification fails and the exception is propagated to the caller of `Connection.do_handshake`.
tests/test_ssl.py
test_set_verify_callback_exception
dholth/pyopenssl
python
def test_set_verify_callback_exception(self): '\n If the verify callback passed to `Context.set_verify` raises an\n exception, verification fails and the exception is propagated to the\n caller of `Connection.do_handshake`.\n ' serverContext = Context(TLSv1_2_METHOD) serverContext.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)) serverContext.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM)) clientContext = Context(TLSv1_2_METHOD) def verify_callback(*args): raise Exception('silly verify failure') clientContext.set_verify(VERIFY_PEER, verify_callback) with pytest.raises(Exception) as exc: self._handshake_test(serverContext, clientContext) assert ('silly verify failure' == str(exc.value))
def test_add_extra_chain_cert(self, tmpdir): '\n `Context.add_extra_chain_cert` accepts an `X509`\n instance to add to the certificate chain.\n\n See `_create_certificate_chain` for the details of the\n certificate chain tested.\n\n The chain is tested by starting a server with scert and connecting\n to it with a client which trusts cacert and requires verification to\n succeed.\n ' chain = _create_certificate_chain() [(cakey, cacert), (ikey, icert), (skey, scert)] = chain for (cert, name) in [(cacert, 'ca.pem'), (icert, 'i.pem'), (scert, 's.pem')]: with tmpdir.join(name).open('w') as f: f.write(dump_certificate(FILETYPE_PEM, cert).decode('ascii')) for (key, name) in [(cakey, 'ca.key'), (ikey, 'i.key'), (skey, 's.key')]: with tmpdir.join(name).open('w') as f: f.write(dump_privatekey(FILETYPE_PEM, key).decode('ascii')) serverContext = Context(TLSv1_METHOD) serverContext.use_privatekey(skey) serverContext.use_certificate(scert) serverContext.add_extra_chain_cert(icert) clientContext = Context(TLSv1_METHOD) clientContext.set_verify((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT), verify_cb) clientContext.load_verify_locations(str(tmpdir.join('ca.pem'))) self._handshake_test(serverContext, clientContext)
-7,207,732,484,281,632,000
`Context.add_extra_chain_cert` accepts an `X509` instance to add to the certificate chain. See `_create_certificate_chain` for the details of the certificate chain tested. The chain is tested by starting a server with scert and connecting to it with a client which trusts cacert and requires verification to succeed.
tests/test_ssl.py
test_add_extra_chain_cert
dholth/pyopenssl
python
def test_add_extra_chain_cert(self, tmpdir): '\n `Context.add_extra_chain_cert` accepts an `X509`\n instance to add to the certificate chain.\n\n See `_create_certificate_chain` for the details of the\n certificate chain tested.\n\n The chain is tested by starting a server with scert and connecting\n to it with a client which trusts cacert and requires verification to\n succeed.\n ' chain = _create_certificate_chain() [(cakey, cacert), (ikey, icert), (skey, scert)] = chain for (cert, name) in [(cacert, 'ca.pem'), (icert, 'i.pem'), (scert, 's.pem')]: with tmpdir.join(name).open('w') as f: f.write(dump_certificate(FILETYPE_PEM, cert).decode('ascii')) for (key, name) in [(cakey, 'ca.key'), (ikey, 'i.key'), (skey, 's.key')]: with tmpdir.join(name).open('w') as f: f.write(dump_privatekey(FILETYPE_PEM, key).decode('ascii')) serverContext = Context(TLSv1_METHOD) serverContext.use_privatekey(skey) serverContext.use_certificate(scert) serverContext.add_extra_chain_cert(icert) clientContext = Context(TLSv1_METHOD) clientContext.set_verify((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT), verify_cb) clientContext.load_verify_locations(str(tmpdir.join('ca.pem'))) self._handshake_test(serverContext, clientContext)
def _use_certificate_chain_file_test(self, certdir): '\n Verify that `Context.use_certificate_chain_file` reads a\n certificate chain from a specified file.\n\n The chain is tested by starting a server with scert and connecting to\n it with a client which trusts cacert and requires verification to\n succeed.\n ' chain = _create_certificate_chain() [(cakey, cacert), (ikey, icert), (skey, scert)] = chain makedirs(certdir) chainFile = join_bytes_or_unicode(certdir, 'chain.pem') caFile = join_bytes_or_unicode(certdir, 'ca.pem') with open(chainFile, 'wb') as fObj: fObj.write(dump_certificate(FILETYPE_PEM, scert)) fObj.write(dump_certificate(FILETYPE_PEM, icert)) fObj.write(dump_certificate(FILETYPE_PEM, cacert)) with open(caFile, 'w') as fObj: fObj.write(dump_certificate(FILETYPE_PEM, cacert).decode('ascii')) serverContext = Context(TLSv1_METHOD) serverContext.use_certificate_chain_file(chainFile) serverContext.use_privatekey(skey) clientContext = Context(TLSv1_METHOD) clientContext.set_verify((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT), verify_cb) clientContext.load_verify_locations(caFile) self._handshake_test(serverContext, clientContext)
121,900,881,953,625,920
Verify that `Context.use_certificate_chain_file` reads a certificate chain from a specified file. The chain is tested by starting a server with scert and connecting to it with a client which trusts cacert and requires verification to succeed.
tests/test_ssl.py
_use_certificate_chain_file_test
dholth/pyopenssl
python
def _use_certificate_chain_file_test(self, certdir): '\n Verify that `Context.use_certificate_chain_file` reads a\n certificate chain from a specified file.\n\n The chain is tested by starting a server with scert and connecting to\n it with a client which trusts cacert and requires verification to\n succeed.\n ' chain = _create_certificate_chain() [(cakey, cacert), (ikey, icert), (skey, scert)] = chain makedirs(certdir) chainFile = join_bytes_or_unicode(certdir, 'chain.pem') caFile = join_bytes_or_unicode(certdir, 'ca.pem') with open(chainFile, 'wb') as fObj: fObj.write(dump_certificate(FILETYPE_PEM, scert)) fObj.write(dump_certificate(FILETYPE_PEM, icert)) fObj.write(dump_certificate(FILETYPE_PEM, cacert)) with open(caFile, 'w') as fObj: fObj.write(dump_certificate(FILETYPE_PEM, cacert).decode('ascii')) serverContext = Context(TLSv1_METHOD) serverContext.use_certificate_chain_file(chainFile) serverContext.use_privatekey(skey) clientContext = Context(TLSv1_METHOD) clientContext.set_verify((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT), verify_cb) clientContext.load_verify_locations(caFile) self._handshake_test(serverContext, clientContext)
def test_use_certificate_chain_file_bytes(self, tmpfile): '\n ``Context.use_certificate_chain_file`` accepts the name of a file (as\n an instance of ``bytes``) to specify additional certificates to use to\n construct and verify a trust chain.\n ' self._use_certificate_chain_file_test((tmpfile + NON_ASCII.encode(getfilesystemencoding())))
-2,246,313,123,328,914,700
``Context.use_certificate_chain_file`` accepts the name of a file (as an instance of ``bytes``) to specify additional certificates to use to construct and verify a trust chain.
tests/test_ssl.py
test_use_certificate_chain_file_bytes
dholth/pyopenssl
python
def test_use_certificate_chain_file_bytes(self, tmpfile): '\n ``Context.use_certificate_chain_file`` accepts the name of a file (as\n an instance of ``bytes``) to specify additional certificates to use to\n construct and verify a trust chain.\n ' self._use_certificate_chain_file_test((tmpfile + NON_ASCII.encode(getfilesystemencoding())))
def test_use_certificate_chain_file_unicode(self, tmpfile): '\n ``Context.use_certificate_chain_file`` accepts the name of a file (as\n an instance of ``unicode``) to specify additional certificates to use\n to construct and verify a trust chain.\n ' self._use_certificate_chain_file_test((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
-6,135,412,846,893,548,000
``Context.use_certificate_chain_file`` accepts the name of a file (as an instance of ``unicode``) to specify additional certificates to use to construct and verify a trust chain.
tests/test_ssl.py
test_use_certificate_chain_file_unicode
dholth/pyopenssl
python
def test_use_certificate_chain_file_unicode(self, tmpfile): '\n ``Context.use_certificate_chain_file`` accepts the name of a file (as\n an instance of ``unicode``) to specify additional certificates to use\n to construct and verify a trust chain.\n ' self._use_certificate_chain_file_test((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
def test_use_certificate_chain_file_wrong_args(self): '\n `Context.use_certificate_chain_file` raises `TypeError` if passed a\n non-byte string single argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.use_certificate_chain_file(object())
-1,994,576,325,898,158,300
`Context.use_certificate_chain_file` raises `TypeError` if passed a non-byte string single argument.
tests/test_ssl.py
test_use_certificate_chain_file_wrong_args
dholth/pyopenssl
python
def test_use_certificate_chain_file_wrong_args(self): '\n `Context.use_certificate_chain_file` raises `TypeError` if passed a\n non-byte string single argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.use_certificate_chain_file(object())
def test_use_certificate_chain_file_missing_file(self, tmpfile): '\n `Context.use_certificate_chain_file` raises `OpenSSL.SSL.Error` when\n passed a bad chain file name (for example, the name of a file which\n does not exist).\n ' context = Context(TLSv1_METHOD) with pytest.raises(Error): context.use_certificate_chain_file(tmpfile)
-4,410,025,098,186,456,000
`Context.use_certificate_chain_file` raises `OpenSSL.SSL.Error` when passed a bad chain file name (for example, the name of a file which does not exist).
tests/test_ssl.py
test_use_certificate_chain_file_missing_file
dholth/pyopenssl
python
def test_use_certificate_chain_file_missing_file(self, tmpfile): '\n `Context.use_certificate_chain_file` raises `OpenSSL.SSL.Error` when\n passed a bad chain file name (for example, the name of a file which\n does not exist).\n ' context = Context(TLSv1_METHOD) with pytest.raises(Error): context.use_certificate_chain_file(tmpfile)
def test_set_verify_mode(self): '\n `Context.get_verify_mode` returns the verify mode flags previously\n passed to `Context.set_verify`.\n ' context = Context(TLSv1_METHOD) assert (context.get_verify_mode() == 0) context.set_verify((VERIFY_PEER | VERIFY_CLIENT_ONCE), (lambda *args: None)) assert (context.get_verify_mode() == (VERIFY_PEER | VERIFY_CLIENT_ONCE))
-7,613,582,988,545,973,000
`Context.get_verify_mode` returns the verify mode flags previously passed to `Context.set_verify`.
tests/test_ssl.py
test_set_verify_mode
dholth/pyopenssl
python
def test_set_verify_mode(self): '\n `Context.get_verify_mode` returns the verify mode flags previously\n passed to `Context.set_verify`.\n ' context = Context(TLSv1_METHOD) assert (context.get_verify_mode() == 0) context.set_verify((VERIFY_PEER | VERIFY_CLIENT_ONCE), (lambda *args: None)) assert (context.get_verify_mode() == (VERIFY_PEER | VERIFY_CLIENT_ONCE))
@pytest.mark.parametrize('mode', [None, 1.0, object(), 'mode']) def test_set_verify_wrong_mode_arg(self, mode): '\n `Context.set_verify` raises `TypeError` if the first argument is\n not an integer.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_verify(mode=mode, callback=(lambda *args: None))
-6,083,588,457,272,447,000
`Context.set_verify` raises `TypeError` if the first argument is not an integer.
tests/test_ssl.py
test_set_verify_wrong_mode_arg
dholth/pyopenssl
python
@pytest.mark.parametrize('mode', [None, 1.0, object(), 'mode']) def test_set_verify_wrong_mode_arg(self, mode): '\n `Context.set_verify` raises `TypeError` if the first argument is\n not an integer.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_verify(mode=mode, callback=(lambda *args: None))
@pytest.mark.parametrize('callback', [None, 1.0, 'mode', ('foo', 'bar')]) def test_set_verify_wrong_callable_arg(self, callback): '\n `Context.set_verify` raises `TypeError` if the second argument\n is not callable.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_verify(mode=VERIFY_PEER, callback=callback)
1,604,646,336,629,066,500
`Context.set_verify` raises `TypeError` if the second argument is not callable.
tests/test_ssl.py
test_set_verify_wrong_callable_arg
dholth/pyopenssl
python
@pytest.mark.parametrize('callback', [None, 1.0, 'mode', ('foo', 'bar')]) def test_set_verify_wrong_callable_arg(self, callback): '\n `Context.set_verify` raises `TypeError` if the second argument\n is not callable.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_verify(mode=VERIFY_PEER, callback=callback)
def test_load_tmp_dh_wrong_args(self): '\n `Context.load_tmp_dh` raises `TypeError` if called with a\n non-`str` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.load_tmp_dh(object())
5,867,219,445,520,334,000
`Context.load_tmp_dh` raises `TypeError` if called with a non-`str` argument.
tests/test_ssl.py
test_load_tmp_dh_wrong_args
dholth/pyopenssl
python
def test_load_tmp_dh_wrong_args(self): '\n `Context.load_tmp_dh` raises `TypeError` if called with a\n non-`str` argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.load_tmp_dh(object())
def test_load_tmp_dh_missing_file(self): '\n `Context.load_tmp_dh` raises `OpenSSL.SSL.Error` if the\n specified file does not exist.\n ' context = Context(TLSv1_METHOD) with pytest.raises(Error): context.load_tmp_dh(b'hello')
8,031,790,497,656,255,000
`Context.load_tmp_dh` raises `OpenSSL.SSL.Error` if the specified file does not exist.
tests/test_ssl.py
test_load_tmp_dh_missing_file
dholth/pyopenssl
python
def test_load_tmp_dh_missing_file(self): '\n `Context.load_tmp_dh` raises `OpenSSL.SSL.Error` if the\n specified file does not exist.\n ' context = Context(TLSv1_METHOD) with pytest.raises(Error): context.load_tmp_dh(b'hello')
def _load_tmp_dh_test(self, dhfilename): '\n Verify that calling ``Context.load_tmp_dh`` with the given filename\n does not raise an exception.\n ' context = Context(TLSv1_METHOD) with open(dhfilename, 'w') as dhfile: dhfile.write(dhparam) context.load_tmp_dh(dhfilename)
-7,295,639,584,504,405,000
Verify that calling ``Context.load_tmp_dh`` with the given filename does not raise an exception.
tests/test_ssl.py
_load_tmp_dh_test
dholth/pyopenssl
python
def _load_tmp_dh_test(self, dhfilename): '\n Verify that calling ``Context.load_tmp_dh`` with the given filename\n does not raise an exception.\n ' context = Context(TLSv1_METHOD) with open(dhfilename, 'w') as dhfile: dhfile.write(dhparam) context.load_tmp_dh(dhfilename)
def test_load_tmp_dh_bytes(self, tmpfile): '\n `Context.load_tmp_dh` loads Diffie-Hellman parameters from the\n specified file (given as ``bytes``).\n ' self._load_tmp_dh_test((tmpfile + NON_ASCII.encode(getfilesystemencoding())))
6,835,700,198,745,874,000
`Context.load_tmp_dh` loads Diffie-Hellman parameters from the specified file (given as ``bytes``).
tests/test_ssl.py
test_load_tmp_dh_bytes
dholth/pyopenssl
python
def test_load_tmp_dh_bytes(self, tmpfile): '\n `Context.load_tmp_dh` loads Diffie-Hellman parameters from the\n specified file (given as ``bytes``).\n ' self._load_tmp_dh_test((tmpfile + NON_ASCII.encode(getfilesystemencoding())))
def test_load_tmp_dh_unicode(self, tmpfile): '\n `Context.load_tmp_dh` loads Diffie-Hellman parameters from the\n specified file (given as ``unicode``).\n ' self._load_tmp_dh_test((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
-674,828,957,815,674,800
`Context.load_tmp_dh` loads Diffie-Hellman parameters from the specified file (given as ``unicode``).
tests/test_ssl.py
test_load_tmp_dh_unicode
dholth/pyopenssl
python
def test_load_tmp_dh_unicode(self, tmpfile): '\n `Context.load_tmp_dh` loads Diffie-Hellman parameters from the\n specified file (given as ``unicode``).\n ' self._load_tmp_dh_test((tmpfile.decode(getfilesystemencoding()) + NON_ASCII))
def test_set_tmp_ecdh(self): '\n `Context.set_tmp_ecdh` sets the elliptic curve for Diffie-Hellman to\n the specified curve.\n ' context = Context(TLSv1_METHOD) for curve in get_elliptic_curves(): if curve.name.startswith(u'Oakley-'): continue context.set_tmp_ecdh(curve)
-7,445,959,058,444,571,000
`Context.set_tmp_ecdh` sets the elliptic curve for Diffie-Hellman to the specified curve.
tests/test_ssl.py
test_set_tmp_ecdh
dholth/pyopenssl
python
def test_set_tmp_ecdh(self): '\n `Context.set_tmp_ecdh` sets the elliptic curve for Diffie-Hellman to\n the specified curve.\n ' context = Context(TLSv1_METHOD) for curve in get_elliptic_curves(): if curve.name.startswith(u'Oakley-'): continue context.set_tmp_ecdh(curve)
def test_set_session_cache_mode_wrong_args(self): '\n `Context.set_session_cache_mode` raises `TypeError` if called with\n a non-integer argument.\n called with other than one integer argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_session_cache_mode(object())
3,843,314,358,005,637,000
`Context.set_session_cache_mode` raises `TypeError` if called with a non-integer argument. called with other than one integer argument.
tests/test_ssl.py
test_set_session_cache_mode_wrong_args
dholth/pyopenssl
python
def test_set_session_cache_mode_wrong_args(self): '\n `Context.set_session_cache_mode` raises `TypeError` if called with\n a non-integer argument.\n called with other than one integer argument.\n ' context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_session_cache_mode(object())
def test_session_cache_mode(self): '\n `Context.set_session_cache_mode` specifies how sessions are cached.\n The setting can be retrieved via `Context.get_session_cache_mode`.\n ' context = Context(TLSv1_METHOD) context.set_session_cache_mode(SESS_CACHE_OFF) off = context.set_session_cache_mode(SESS_CACHE_BOTH) assert (SESS_CACHE_OFF == off) assert (SESS_CACHE_BOTH == context.get_session_cache_mode())
6,386,246,240,366,276,000
`Context.set_session_cache_mode` specifies how sessions are cached. The setting can be retrieved via `Context.get_session_cache_mode`.
tests/test_ssl.py
test_session_cache_mode
dholth/pyopenssl
python
def test_session_cache_mode(self): '\n `Context.set_session_cache_mode` specifies how sessions are cached.\n The setting can be retrieved via `Context.get_session_cache_mode`.\n ' context = Context(TLSv1_METHOD) context.set_session_cache_mode(SESS_CACHE_OFF) off = context.set_session_cache_mode(SESS_CACHE_BOTH) assert (SESS_CACHE_OFF == off) assert (SESS_CACHE_BOTH == context.get_session_cache_mode())
def test_get_cert_store(self): '\n `Context.get_cert_store` returns a `X509Store` instance.\n ' context = Context(TLSv1_METHOD) store = context.get_cert_store() assert isinstance(store, X509Store)
-6,773,002,703,421,428,000
`Context.get_cert_store` returns a `X509Store` instance.
tests/test_ssl.py
test_get_cert_store
dholth/pyopenssl
python
def test_get_cert_store(self): '\n \n ' context = Context(TLSv1_METHOD) store = context.get_cert_store() assert isinstance(store, X509Store)
def test_set_tlsext_use_srtp_not_bytes(self): "\n `Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.\n\n It raises a TypeError if the list of profiles is not a byte string.\n " context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_tlsext_use_srtp(text_type('SRTP_AES128_CM_SHA1_80'))
-1,277,184,163,410,455,800
`Context.set_tlsext_use_srtp' enables negotiating SRTP keying material. It raises a TypeError if the list of profiles is not a byte string.
tests/test_ssl.py
test_set_tlsext_use_srtp_not_bytes
dholth/pyopenssl
python
def test_set_tlsext_use_srtp_not_bytes(self): "\n `Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.\n\n It raises a TypeError if the list of profiles is not a byte string.\n " context = Context(TLSv1_METHOD) with pytest.raises(TypeError): context.set_tlsext_use_srtp(text_type('SRTP_AES128_CM_SHA1_80'))
def test_set_tlsext_use_srtp_invalid_profile(self): "\n `Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.\n\n It raises an Error if the call to OpenSSL fails.\n " context = Context(TLSv1_METHOD) with pytest.raises(Error): context.set_tlsext_use_srtp(b'SRTP_BOGUS')
6,736,143,883,811,378,000
`Context.set_tlsext_use_srtp' enables negotiating SRTP keying material. It raises an Error if the call to OpenSSL fails.
tests/test_ssl.py
test_set_tlsext_use_srtp_invalid_profile
dholth/pyopenssl
python
def test_set_tlsext_use_srtp_invalid_profile(self): "\n `Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.\n\n It raises an Error if the call to OpenSSL fails.\n " context = Context(TLSv1_METHOD) with pytest.raises(Error): context.set_tlsext_use_srtp(b'SRTP_BOGUS')
def test_set_tlsext_use_srtp_valid(self): "\n `Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.\n\n It does not return anything.\n " context = Context(TLSv1_METHOD) assert (context.set_tlsext_use_srtp(b'SRTP_AES128_CM_SHA1_80') is None)
-1,962,263,520,625,877,500
`Context.set_tlsext_use_srtp' enables negotiating SRTP keying material. It does not return anything.
tests/test_ssl.py
test_set_tlsext_use_srtp_valid
dholth/pyopenssl
python
def test_set_tlsext_use_srtp_valid(self): "\n `Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.\n\n It does not return anything.\n " context = Context(TLSv1_METHOD) assert (context.set_tlsext_use_srtp(b'SRTP_AES128_CM_SHA1_80') is None)