code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
182
url
stringlengths
46
251
license
stringclasses
4 values
def test_oldPython(self): """ L{_checkPythonVersion} raises L{ImportError} when run on a version of Python that is too old. """ sys.version_info = self.unsupportedPythonVersion with self.assertRaises(ImportError) as raised: _checkPythonVersion() self.assertEqual("Twisted requires Python %d.%d or later." % self.supportedPythonVersion, str(raised.exception))
L{_checkPythonVersion} raises L{ImportError} when run on a version of Python that is too old.
test_oldPython
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
MIT
def test_newPython(self): """ L{_checkPythonVersion} returns L{None} when run on a version of Python that is sufficiently new. """ sys.version_info = self.supportedPythonVersion self.assertIsNone(_checkPythonVersion())
L{_checkPythonVersion} returns L{None} when run on a version of Python that is sufficiently new.
test_newPython
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
MIT
def test_nonModule(self): """ A non-C{dict} value in the attributes dictionary passed to L{_makePackages} is preserved unchanged in the return value. """ modules = {} _makePackages(None, dict(reactor='reactor'), modules) self.assertEqual(modules, dict(reactor='reactor'))
A non-C{dict} value in the attributes dictionary passed to L{_makePackages} is preserved unchanged in the return value.
test_nonModule
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
MIT
def test_moduleWithAttribute(self): """ A C{dict} value in the attributes dictionary passed to L{_makePackages} is turned into a L{ModuleType} instance with attributes populated from the items of that C{dict} value. """ modules = {} _makePackages(None, dict(twisted=dict(version='123')), modules) self.assertIsInstance(modules, dict) self.assertIsInstance(modules['twisted'], ModuleType) self.assertEqual('twisted', modules['twisted'].__name__) self.assertEqual('123', modules['twisted'].version)
A C{dict} value in the attributes dictionary passed to L{_makePackages} is turned into a L{ModuleType} instance with attributes populated from the items of that C{dict} value.
test_moduleWithAttribute
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
MIT
def test_packageWithModule(self): """ Processing of the attributes dictionary is recursive, so a C{dict} value it contains may itself contain a C{dict} value to the same effect. """ modules = {} _makePackages(None, dict(twisted=dict(web=dict(version='321'))), modules) self.assertIsInstance(modules, dict) self.assertIsInstance(modules['twisted'], ModuleType) self.assertEqual('twisted', modules['twisted'].__name__) self.assertIsInstance(modules['twisted'].web, ModuleType) self.assertEqual('twisted.web', modules['twisted'].web.__name__) self.assertEqual('321', modules['twisted'].web.version)
Processing of the attributes dictionary is recursive, so a C{dict} value it contains may itself contain a C{dict} value to the same effect.
test_packageWithModule
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twisted.py
MIT
def test_notPresentIfNotSet(self): """ Arbitrary keys which have not been set in the context have an associated value of L{None}. """ self.assertIsNone(context.get("x"))
Arbitrary keys which have not been set in the context have an associated value of L{None}.
test_notPresentIfNotSet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
MIT
def test_setByCall(self): """ Values may be associated with keys by passing them in a dictionary as the first argument to L{twisted.python.context.call}. """ self.assertEqual(context.call({"x": "y"}, context.get, "x"), "y")
Values may be associated with keys by passing them in a dictionary as the first argument to L{twisted.python.context.call}.
test_setByCall
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
MIT
def test_unsetAfterCall(self): """ After a L{twisted.python.context.call} completes, keys specified in the call are no longer associated with the values from that call. """ context.call({"x": "y"}, lambda: None) self.assertIsNone(context.get("x"))
After a L{twisted.python.context.call} completes, keys specified in the call are no longer associated with the values from that call.
test_unsetAfterCall
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
MIT
def test_setDefault(self): """ A default value may be set for a key in the context using L{twisted.python.context.setDefault}. """ key = object() self.addCleanup(context.defaultContextDict.pop, key, None) context.setDefault(key, "y") self.assertEqual("y", context.get(key))
A default value may be set for a key in the context using L{twisted.python.context.setDefault}.
test_setDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_context.py
MIT
def test_empty(self): """ A monkey patcher without patches shouldn't change a thing. """ self.monkeyPatcher.patch() # We can't assert that all state is unchanged, but at least we can # check our test object. self.assertEqual(self.originalObject.foo, self.testObject.foo) self.assertEqual(self.originalObject.bar, self.testObject.bar) self.assertEqual(self.originalObject.baz, self.testObject.baz)
A monkey patcher without patches shouldn't change a thing.
test_empty
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_constructWithPatches(self): """ Constructing a L{MonkeyPatcher} with patches should add all of the given patches to the patch list. """ patcher = MonkeyPatcher((self.testObject, 'foo', 'haha'), (self.testObject, 'bar', 'hehe')) patcher.patch() self.assertEqual('haha', self.testObject.foo) self.assertEqual('hehe', self.testObject.bar) self.assertEqual(self.originalObject.baz, self.testObject.baz)
Constructing a L{MonkeyPatcher} with patches should add all of the given patches to the patch list.
test_constructWithPatches
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_patchExisting(self): """ Patching an attribute that exists sets it to the value defined in the patch. """ self.monkeyPatcher.addPatch(self.testObject, 'foo', 'haha') self.monkeyPatcher.patch() self.assertEqual(self.testObject.foo, 'haha')
Patching an attribute that exists sets it to the value defined in the patch.
test_patchExisting
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_patchNonExisting(self): """ Patching a non-existing attribute fails with an C{AttributeError}. """ self.monkeyPatcher.addPatch(self.testObject, 'nowhere', 'blow up please') self.assertRaises(AttributeError, self.monkeyPatcher.patch)
Patching a non-existing attribute fails with an C{AttributeError}.
test_patchNonExisting
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_patchAlreadyPatched(self): """ Adding a patch for an object and attribute that already have a patch overrides the existing patch. """ self.monkeyPatcher.addPatch(self.testObject, 'foo', 'blah') self.monkeyPatcher.addPatch(self.testObject, 'foo', 'BLAH') self.monkeyPatcher.patch() self.assertEqual(self.testObject.foo, 'BLAH') self.monkeyPatcher.restore() self.assertEqual(self.testObject.foo, self.originalObject.foo)
Adding a patch for an object and attribute that already have a patch overrides the existing patch.
test_patchAlreadyPatched
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_restoreTwiceIsANoOp(self): """ Restoring an already-restored monkey patch is a no-op. """ self.monkeyPatcher.addPatch(self.testObject, 'foo', 'blah') self.monkeyPatcher.patch() self.monkeyPatcher.restore() self.assertEqual(self.testObject.foo, self.originalObject.foo) self.monkeyPatcher.restore() self.assertEqual(self.testObject.foo, self.originalObject.foo)
Restoring an already-restored monkey patch is a no-op.
test_restoreTwiceIsANoOp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_runWithPatchesDecoration(self): """ runWithPatches should run the given callable, passing in all arguments and keyword arguments, and return the return value of the callable. """ log = [] def f(a, b, c=None): log.append((a, b, c)) return 'foo' result = self.monkeyPatcher.runWithPatches(f, 1, 2, c=10) self.assertEqual('foo', result) self.assertEqual([(1, 2, 10)], log)
runWithPatches should run the given callable, passing in all arguments and keyword arguments, and return the return value of the callable.
test_runWithPatchesDecoration
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_repeatedRunWithPatches(self): """ We should be able to call the same function with runWithPatches more than once. All patches should apply for each call. """ def f(): return (self.testObject.foo, self.testObject.bar, self.testObject.baz) self.monkeyPatcher.addPatch(self.testObject, 'foo', 'haha') result = self.monkeyPatcher.runWithPatches(f) self.assertEqual( ('haha', self.originalObject.bar, self.originalObject.baz), result) result = self.monkeyPatcher.runWithPatches(f) self.assertEqual( ('haha', self.originalObject.bar, self.originalObject.baz), result)
We should be able to call the same function with runWithPatches more than once. All patches should apply for each call.
test_repeatedRunWithPatches
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_runWithPatchesRestores(self): """ C{runWithPatches} should restore the original values after the function has executed. """ self.monkeyPatcher.addPatch(self.testObject, 'foo', 'haha') self.assertEqual(self.originalObject.foo, self.testObject.foo) self.monkeyPatcher.runWithPatches(lambda: None) self.assertEqual(self.originalObject.foo, self.testObject.foo)
C{runWithPatches} should restore the original values after the function has executed.
test_runWithPatchesRestores
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def test_runWithPatchesRestoresOnException(self): """ Test runWithPatches restores the original values even when the function raises an exception. """ def _(): self.assertEqual(self.testObject.foo, 'haha') self.assertEqual(self.testObject.bar, 'blahblah') raise RuntimeError("Something went wrong!") self.monkeyPatcher.addPatch(self.testObject, 'foo', 'haha') self.monkeyPatcher.addPatch(self.testObject, 'bar', 'blahblah') self.assertRaises(RuntimeError, self.monkeyPatcher.runWithPatches, _) self.assertEqual(self.testObject.foo, self.originalObject.foo) self.assertEqual(self.testObject.bar, self.originalObject.bar)
Test runWithPatches restores the original values even when the function raises an exception.
test_runWithPatchesRestoresOnException
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_monkey.py
MIT
def counter(counter=itertools.count()): """ Each time we're called, return the next integer in the natural numbers. """ return next(counter)
Each time we're called, return the next integer in the natural numbers.
counter
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def certificatesForAuthorityAndServer(serviceIdentity=u'example.com'): """ Create a self-signed CA certificate and server certificate signed by the CA. @param serviceIdentity: The identity (hostname) of the server. @type serviceIdentity: L{unicode} @return: a 2-tuple of C{(certificate_authority_certificate, server_certificate)} @rtype: L{tuple} of (L{sslverify.Certificate}, L{sslverify.PrivateCertificate}) """ commonNameForCA = x509.Name( [x509.NameAttribute(NameOID.COMMON_NAME, u'Testing Example CA')] ) commonNameForServer = x509.Name( [x509.NameAttribute(NameOID.COMMON_NAME, u'Testing Example Server')] ) oneDay = datetime.timedelta(1, 0, 0) privateKeyForCA = rsa.generate_private_key( public_exponent=65537, key_size=4096, backend=default_backend() ) publicKeyForCA = privateKeyForCA.public_key() caCertificate = ( x509.CertificateBuilder() .subject_name(commonNameForCA) .issuer_name(commonNameForCA) .not_valid_before(datetime.datetime.today() - oneDay) .not_valid_after(datetime.datetime.today() + oneDay) .serial_number(x509.random_serial_number()) .public_key(publicKeyForCA) .add_extension( x509.BasicConstraints(ca=True, path_length=9), critical=True, ) .sign( private_key=privateKeyForCA, algorithm=hashes.SHA256(), backend=default_backend() ) ) privateKeyForServer = rsa.generate_private_key( public_exponent=65537, key_size=4096, backend=default_backend() ) publicKeyForServer = privateKeyForServer.public_key() try: ipAddress = ipaddress.ip_address(serviceIdentity) except ValueError: subjectAlternativeNames = [ x509.DNSName(serviceIdentity.encode("idna").decode("ascii")) ] else: subjectAlternativeNames = [x509.IPAddress(ipAddress)] serverCertificate = ( x509.CertificateBuilder() .subject_name(commonNameForServer) .issuer_name(commonNameForCA) .not_valid_before(datetime.datetime.today() - oneDay) .not_valid_after(datetime.datetime.today() + oneDay) .serial_number(x509.random_serial_number()) .public_key(publicKeyForServer) .add_extension( x509.BasicConstraints(ca=False, path_length=None), critical=True, ) .add_extension( x509.SubjectAlternativeName( subjectAlternativeNames ), critical=True, ) .sign( private_key=privateKeyForCA, algorithm=hashes.SHA256(), backend=default_backend() ) ) caSelfCert = sslverify.Certificate.loadPEM( caCertificate.public_bytes(Encoding.PEM) ) serverCert = sslverify.PrivateCertificate.loadPEM( b"\n".join([privateKeyForServer.private_bytes( Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption(), ), serverCertificate.public_bytes(Encoding.PEM)]) ) return caSelfCert, serverCert
Create a self-signed CA certificate and server certificate signed by the CA. @param serviceIdentity: The identity (hostname) of the server. @type serviceIdentity: L{unicode} @return: a 2-tuple of C{(certificate_authority_certificate, server_certificate)} @rtype: L{tuple} of (L{sslverify.Certificate}, L{sslverify.PrivateCertificate})
certificatesForAuthorityAndServer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def _loopbackTLSConnection(serverOpts, clientOpts): """ Common implementation code for both L{loopbackTLSConnection} and L{loopbackTLSConnectionInMemory}. Creates a loopback TLS connection using the provided server and client context factories. @param serverOpts: An OpenSSL context factory for the server. @type serverOpts: C{OpenSSLCertificateOptions}, or any class with an equivalent API. @param clientOpts: An OpenSSL context factory for the client. @type clientOpts: C{OpenSSLCertificateOptions}, or any class with an equivalent API. @return: 5-tuple of server-tls-protocol, server-inner-protocol, client-tls-protocol, client-inner-protocol and L{IOPump} @rtype: L{tuple} """ class GreetingServer(protocol.Protocol): greeting = b"greetings!" def connectionMade(self): self.transport.write(self.greeting) class ListeningClient(protocol.Protocol): data = b'' lostReason = None def dataReceived(self, data): self.data += data def connectionLost(self, reason): self.lostReason = reason clientWrappedProto = ListeningClient() serverWrappedProto = GreetingServer() plainClientFactory = protocol.Factory() plainClientFactory.protocol = lambda: clientWrappedProto plainServerFactory = protocol.Factory() plainServerFactory.protocol = lambda: serverWrappedProto clientFactory = TLSMemoryBIOFactory( clientOpts, isClient=True, wrappedFactory=plainServerFactory ) serverFactory = TLSMemoryBIOFactory( serverOpts, isClient=False, wrappedFactory=plainClientFactory ) sProto, cProto, pump = connectedServerAndClient( lambda: serverFactory.buildProtocol(None), lambda: clientFactory.buildProtocol(None) ) return sProto, cProto, serverWrappedProto, clientWrappedProto, pump
Common implementation code for both L{loopbackTLSConnection} and L{loopbackTLSConnectionInMemory}. Creates a loopback TLS connection using the provided server and client context factories. @param serverOpts: An OpenSSL context factory for the server. @type serverOpts: C{OpenSSLCertificateOptions}, or any class with an equivalent API. @param clientOpts: An OpenSSL context factory for the client. @type clientOpts: C{OpenSSLCertificateOptions}, or any class with an equivalent API. @return: 5-tuple of server-tls-protocol, server-inner-protocol, client-tls-protocol, client-inner-protocol and L{IOPump} @rtype: L{tuple}
_loopbackTLSConnection
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def getContext(self): """ Create a context for the server side of the connection. @return: an SSL context using a certificate and key. @rtype: C{OpenSSL.SSL.Context} """ ctx = SSL.Context(SSL.TLSv1_METHOD) if chainedCertFile is not None: ctx.use_certificate_chain_file(chainedCertFile) ctx.use_privatekey_file(privateKeyFile) # Let the test author know if they screwed something up. ctx.check_privatekey() return ctx
Create a context for the server side of the connection. @return: an SSL context using a certificate and key. @rtype: C{OpenSSL.SSL.Context}
loopbackTLSConnection.getContext
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def loopbackTLSConnection(trustRoot, privateKeyFile, chainedCertFile=None): """ Create a loopback TLS connection with the given trust and keys. @param trustRoot: the C{trustRoot} argument for the client connection's context. @type trustRoot: L{sslverify.IOpenSSLTrustRoot} @param privateKeyFile: The name of the file containing the private key. @type privateKeyFile: L{str} (native string; file name) @param chainedCertFile: The name of the chained certificate file. @type chainedCertFile: L{str} (native string; file name) @return: 3-tuple of server-protocol, client-protocol, and L{IOPump} @rtype: L{tuple} """ class ContextFactory(object): def getContext(self): """ Create a context for the server side of the connection. @return: an SSL context using a certificate and key. @rtype: C{OpenSSL.SSL.Context} """ ctx = SSL.Context(SSL.TLSv1_METHOD) if chainedCertFile is not None: ctx.use_certificate_chain_file(chainedCertFile) ctx.use_privatekey_file(privateKeyFile) # Let the test author know if they screwed something up. ctx.check_privatekey() return ctx serverOpts = ContextFactory() clientOpts = sslverify.OpenSSLCertificateOptions(trustRoot=trustRoot) return _loopbackTLSConnection(serverOpts, clientOpts)
Create a loopback TLS connection with the given trust and keys. @param trustRoot: the C{trustRoot} argument for the client connection's context. @type trustRoot: L{sslverify.IOpenSSLTrustRoot} @param privateKeyFile: The name of the file containing the private key. @type privateKeyFile: L{str} (native string; file name) @param chainedCertFile: The name of the chained certificate file. @type chainedCertFile: L{str} (native string; file name) @return: 3-tuple of server-protocol, client-protocol, and L{IOPump} @rtype: L{tuple}
loopbackTLSConnection
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def loopbackTLSConnectionInMemory(trustRoot, privateKey, serverCertificate, clientProtocols=None, serverProtocols=None, clientOptions=None): """ Create a loopback TLS connection with the given trust and keys. Like L{loopbackTLSConnection}, but using in-memory certificates and keys rather than writing them to disk. @param trustRoot: the C{trustRoot} argument for the client connection's context. @type trustRoot: L{sslverify.IOpenSSLTrustRoot} @param privateKey: The private key. @type privateKey: L{str} (native string) @param serverCertificate: The certificate used by the server. @type chainedCertFile: L{str} (native string) @param clientProtocols: The protocols the client is willing to negotiate using NPN/ALPN. @param serverProtocols: The protocols the server is willing to negotiate using NPN/ALPN. @param clientOptions: The type of C{OpenSSLCertificateOptions} class to use for the client. Defaults to C{OpenSSLCertificateOptions}. @return: 3-tuple of server-protocol, client-protocol, and L{IOPump} @rtype: L{tuple} """ if clientOptions is None: clientOptions = sslverify.OpenSSLCertificateOptions clientCertOpts = clientOptions( trustRoot=trustRoot, acceptableProtocols=clientProtocols ) serverCertOpts = sslverify.OpenSSLCertificateOptions( privateKey=privateKey, certificate=serverCertificate, acceptableProtocols=serverProtocols, ) return _loopbackTLSConnection(serverCertOpts, clientCertOpts)
Create a loopback TLS connection with the given trust and keys. Like L{loopbackTLSConnection}, but using in-memory certificates and keys rather than writing them to disk. @param trustRoot: the C{trustRoot} argument for the client connection's context. @type trustRoot: L{sslverify.IOpenSSLTrustRoot} @param privateKey: The private key. @type privateKey: L{str} (native string) @param serverCertificate: The certificate used by the server. @type chainedCertFile: L{str} (native string) @param clientProtocols: The protocols the client is willing to negotiate using NPN/ALPN. @param serverProtocols: The protocols the server is willing to negotiate using NPN/ALPN. @param clientOptions: The type of C{OpenSSLCertificateOptions} class to use for the client. Defaults to C{OpenSSLCertificateOptions}. @return: 3-tuple of server-protocol, client-protocol, and L{IOPump} @rtype: L{tuple}
loopbackTLSConnectionInMemory
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def pathContainingDumpOf(testCase, *dumpables): """ Create a temporary file to store some serializable-as-PEM objects in, and return its name. @param testCase: a test case to use for generating a temporary directory. @type testCase: L{twisted.trial.unittest.TestCase} @param dumpables: arguments are objects from pyOpenSSL with a C{dump} method, taking a pyOpenSSL file-type constant, such as L{OpenSSL.crypto.FILETYPE_PEM} or L{OpenSSL.crypto.FILETYPE_ASN1}. @type dumpables: L{tuple} of L{object} with C{dump} method taking L{int} returning L{bytes} @return: the path to a file where all of the dumpables were dumped in PEM format. @rtype: L{str} """ fname = testCase.mktemp() with open(fname, "wb") as f: for dumpable in dumpables: f.write(dumpable.dump(FILETYPE_PEM)) return fname
Create a temporary file to store some serializable-as-PEM objects in, and return its name. @param testCase: a test case to use for generating a temporary directory. @type testCase: L{twisted.trial.unittest.TestCase} @param dumpables: arguments are objects from pyOpenSSL with a C{dump} method, taking a pyOpenSSL file-type constant, such as L{OpenSSL.crypto.FILETYPE_PEM} or L{OpenSSL.crypto.FILETYPE_ASN1}. @type dumpables: L{tuple} of L{object} with C{dump} method taking L{int} returning L{bytes} @return: the path to a file where all of the dumpables were dumped in PEM format. @rtype: L{str}
pathContainingDumpOf
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def set_mode(self, mode): """ Set the mode. See L{SSL.Context.set_mode}. @param mode: See L{SSL.Context.set_mode}. """ self._mode = mode
Set the mode. See L{SSL.Context.set_mode}. @param mode: See L{SSL.Context.set_mode}.
set_mode
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def set_default_verify_paths(self): """ Set the default paths for the platform. """ self._defaultVerifyPathsSet = True
Set the default paths for the platform.
set_default_verify_paths
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def set_tmp_ecdh(self, curve): """ Set an ECDH curve. Should only be called by OpenSSL 1.0.1 code. @param curve: See L{OpenSSL.SSL.Context.set_tmp_ecdh} """ self._ecCurve = curve
Set an ECDH curve. Should only be called by OpenSSL 1.0.1 code. @param curve: See L{OpenSSL.SSL.Context.set_tmp_ecdh}
set_tmp_ecdh
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_extraKeywords(self): """ When passed a keyword parameter other than C{extraCertificateOptions}, L{sslverify.optionsForClientTLS} raises an exception just like a normal Python function would. """ error = self.assertRaises( TypeError, sslverify.optionsForClientTLS, hostname=u'alpha', someRandomThing=u'beta', ) self.assertEqual( str(error), "optionsForClientTLS() got an unexpected keyword argument " "'someRandomThing'" )
When passed a keyword parameter other than C{extraCertificateOptions}, L{sslverify.optionsForClientTLS} raises an exception just like a normal Python function would.
test_extraKeywords
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_bytesFailFast(self): """ If you pass L{bytes} as the hostname to L{sslverify.optionsForClientTLS} it immediately raises a L{TypeError}. """ error = self.assertRaises( TypeError, sslverify.optionsForClientTLS, b'not-actually-a-hostname.com' ) expectedText = ( "optionsForClientTLS requires text for host names, not " + bytes.__name__ ) self.assertEqual(str(error), expectedText)
If you pass L{bytes} as the hostname to L{sslverify.optionsForClientTLS} it immediately raises a L{TypeError}.
test_bytesFailFast
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_dNSNameHostname(self): """ If you pass a dNSName to L{sslverify.optionsForClientTLS} L{_hostnameIsDnsName} will be True """ options = sslverify.optionsForClientTLS(u'example.com') self.assertTrue(options._hostnameIsDnsName)
If you pass a dNSName to L{sslverify.optionsForClientTLS} L{_hostnameIsDnsName} will be True
test_dNSNameHostname
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_IPv4AddressHostname(self): """ If you pass an IPv4 address to L{sslverify.optionsForClientTLS} L{_hostnameIsDnsName} will be False """ options = sslverify.optionsForClientTLS(u'127.0.0.1') self.assertFalse(options._hostnameIsDnsName)
If you pass an IPv4 address to L{sslverify.optionsForClientTLS} L{_hostnameIsDnsName} will be False
test_IPv4AddressHostname
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_IPv6AddressHostname(self): """ If you pass an IPv6 address to L{sslverify.optionsForClientTLS} L{_hostnameIsDnsName} will be False """ options = sslverify.optionsForClientTLS(u'::1') self.assertFalse(options._hostnameIsDnsName)
If you pass an IPv6 address to L{sslverify.optionsForClientTLS} L{_hostnameIsDnsName} will be False
test_IPv6AddressHostname
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def __init__(self, versionNumber, openSSLlib, openSSLcrypto): """ A no-op constructor. """
A no-op constructor.
__init__
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def configureECDHCurve(self, ctx): """ A null configuration. @param ctx: An L{OpenSSL.SSL.Context} that would be configured. """
A null configuration. @param ctx: An L{OpenSSL.SSL.Context} that would be configured.
configureECDHCurve
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def setUp(self): """ Create class variables of client and server certificates. """ self.sKey, self.sCert = makeCertificate( O=b"Server Test Certificate", CN=b"server") self.cKey, self.cCert = makeCertificate( O=b"Client Test Certificate", CN=b"client") self.caCert1 = makeCertificate( O=b"CA Test Certificate 1", CN=b"ca1")[1] self.caCert2 = makeCertificate( O=b"CA Test Certificate", CN=b"ca2")[1] self.caCerts = [self.caCert1, self.caCert2] self.extraCertChain = self.caCerts
Create class variables of client and server certificates.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def setUp(self): """ Same as L{OpenSSLOptionsTestsMixin.setUp}, but it also patches L{sslverify._ChooseDiffieHellmanEllipticCurve}. """ super(OpenSSLOptionsTests, self).setUp() self.patch(sslverify, "_ChooseDiffieHellmanEllipticCurve", FakeChooseDiffieHellmanEllipticCurve)
Same as L{OpenSSLOptionsTestsMixin.setUp}, but it also patches L{sslverify._ChooseDiffieHellmanEllipticCurve}.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorWithOnlyPrivateKey(self): """ C{privateKey} and C{certificate} make only sense if both are set. """ self.assertRaises( ValueError, sslverify.OpenSSLCertificateOptions, privateKey=self.sKey )
C{privateKey} and C{certificate} make only sense if both are set.
test_constructorWithOnlyPrivateKey
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorWithCertificateAndPrivateKey(self): """ Specifying C{privateKey} and C{certificate} initializes correctly. """ opts = sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert) self.assertEqual(opts.privateKey, self.sKey) self.assertEqual(opts.certificate, self.sCert) self.assertEqual(opts.extraCertChain, [])
Specifying C{privateKey} and C{certificate} initializes correctly.
test_constructorWithCertificateAndPrivateKey
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorDoesNotAllowVerifyWithoutCACerts(self): """ C{verify} must not be C{True} without specifying C{caCerts}. """ self.assertRaises( ValueError, sslverify.OpenSSLCertificateOptions, privateKey=self.sKey, certificate=self.sCert, verify=True )
C{verify} must not be C{True} without specifying C{caCerts}.
test_constructorDoesNotAllowVerifyWithoutCACerts
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorDoesNotAllowLegacyWithTrustRoot(self): """ C{verify}, C{requireCertificate}, and C{caCerts} must not be specified by the caller (to be I{any} value, even the default!) when specifying C{trustRoot}. """ self.assertRaises( TypeError, sslverify.OpenSSLCertificateOptions, privateKey=self.sKey, certificate=self.sCert, verify=True, trustRoot=None, caCerts=self.caCerts, ) self.assertRaises( TypeError, sslverify.OpenSSLCertificateOptions, privateKey=self.sKey, certificate=self.sCert, trustRoot=None, requireCertificate=True, )
C{verify}, C{requireCertificate}, and C{caCerts} must not be specified by the caller (to be I{any} value, even the default!) when specifying C{trustRoot}.
test_constructorDoesNotAllowLegacyWithTrustRoot
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorAllowsCACertsWithoutVerify(self): """ It's currently a NOP, but valid. """ opts = sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, caCerts=self.caCerts) self.assertFalse(opts.verify) self.assertEqual(self.caCerts, opts.caCerts)
It's currently a NOP, but valid.
test_constructorAllowsCACertsWithoutVerify
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorWithVerifyAndCACerts(self): """ Specifying C{verify} and C{caCerts} initializes correctly. """ opts = sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, verify=True, caCerts=self.caCerts) self.assertTrue(opts.verify) self.assertEqual(self.caCerts, opts.caCerts)
Specifying C{verify} and C{caCerts} initializes correctly.
test_constructorWithVerifyAndCACerts
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorSetsExtraChain(self): """ Setting C{extraCertChain} works if C{certificate} and C{privateKey} are set along with it. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, extraCertChain=self.extraCertChain, ) self.assertEqual(self.extraCertChain, opts.extraCertChain)
Setting C{extraCertChain} works if C{certificate} and C{privateKey} are set along with it.
test_constructorSetsExtraChain
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorDoesNotAllowExtraChainWithoutPrivateKey(self): """ A C{extraCertChain} without C{privateKey} doesn't make sense and is thus rejected. """ self.assertRaises( ValueError, sslverify.OpenSSLCertificateOptions, certificate=self.sCert, extraCertChain=self.extraCertChain, )
A C{extraCertChain} without C{privateKey} doesn't make sense and is thus rejected.
test_constructorDoesNotAllowExtraChainWithoutPrivateKey
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_constructorDoesNotAllowExtraChainWithOutPrivateKey(self): """ A C{extraCertChain} without C{certificate} doesn't make sense and is thus rejected. """ self.assertRaises( ValueError, sslverify.OpenSSLCertificateOptions, privateKey=self.sKey, extraCertChain=self.extraCertChain, )
A C{extraCertChain} without C{certificate} doesn't make sense and is thus rejected.
test_constructorDoesNotAllowExtraChainWithOutPrivateKey
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_extraChainFilesAreAddedIfSupplied(self): """ If C{extraCertChain} is set and all prerequisites are met, the specified chain certificates are added to C{Context}s that get created. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, extraCertChain=self.extraCertChain, ) opts._contextFactory = FakeContext ctx = opts.getContext() self.assertEqual(self.sKey, ctx._privateKey) self.assertEqual(self.sCert, ctx._certificate) self.assertEqual(self.extraCertChain, ctx._extraCertChain)
If C{extraCertChain} is set and all prerequisites are met, the specified chain certificates are added to C{Context}s that get created.
test_extraChainFilesAreAddedIfSupplied
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_extraChainDoesNotBreakPyOpenSSL(self): """ C{extraCertChain} doesn't break C{OpenSSL.SSL.Context} creation. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, extraCertChain=self.extraCertChain, ) ctx = opts.getContext() self.assertIsInstance(ctx, SSL.Context)
C{extraCertChain} doesn't break C{OpenSSL.SSL.Context} creation.
test_extraChainDoesNotBreakPyOpenSSL
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_acceptableCiphersAreAlwaysSet(self): """ If the user doesn't supply custom acceptable ciphers, a shipped secure default is used. We can't check directly for it because the effective cipher string we set varies with platforms. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, ) opts._contextFactory = FakeContext ctx = opts.getContext() self.assertEqual(opts._cipherString.encode('ascii'), ctx._cipherList)
If the user doesn't supply custom acceptable ciphers, a shipped secure default is used. We can't check directly for it because the effective cipher string we set varies with platforms.
test_acceptableCiphersAreAlwaysSet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_givesMeaningfulErrorMessageIfNoCipherMatches(self): """ If there is no valid cipher that matches the user's wishes, a L{ValueError} is raised. """ self.assertRaises( ValueError, sslverify.OpenSSLCertificateOptions, privateKey=self.sKey, certificate=self.sCert, acceptableCiphers= sslverify.OpenSSLAcceptableCiphers.fromOpenSSLCipherString('') )
If there is no valid cipher that matches the user's wishes, a L{ValueError} is raised.
test_givesMeaningfulErrorMessageIfNoCipherMatches
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_honorsAcceptableCiphersArgument(self): """ If acceptable ciphers are passed, they are used. """ @implementer(interfaces.IAcceptableCiphers) class FakeAcceptableCiphers(object): def selectCiphers(self, _): return [sslverify.OpenSSLCipher(u'sentinel')] opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, acceptableCiphers=FakeAcceptableCiphers(), ) opts._contextFactory = FakeContext ctx = opts.getContext() self.assertEqual(b'sentinel', ctx._cipherList)
If acceptable ciphers are passed, they are used.
test_honorsAcceptableCiphersArgument
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_basicSecurityOptionsAreSet(self): """ Every context must have C{OP_NO_SSLv2}, C{OP_NO_COMPRESSION}, and C{OP_CIPHER_SERVER_PREFERENCE} set. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE) self.assertEqual(options, ctx._options & options)
Every context must have C{OP_NO_SSLv2}, C{OP_NO_COMPRESSION}, and C{OP_CIPHER_SERVER_PREFERENCE} set.
test_basicSecurityOptionsAreSet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_modeIsSet(self): """ Every context must be in C{MODE_RELEASE_BUFFERS} mode. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, ) opts._contextFactory = FakeContext ctx = opts.getContext() self.assertEqual(SSL.MODE_RELEASE_BUFFERS, ctx._mode)
Every context must be in C{MODE_RELEASE_BUFFERS} mode.
test_modeIsSet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_singleUseKeys(self): """ If C{singleUseKeys} is set, every context must have C{OP_SINGLE_DH_USE} and C{OP_SINGLE_ECDH_USE} set. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, enableSingleUseKeys=True, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = SSL.OP_SINGLE_DH_USE | SSL.OP_SINGLE_ECDH_USE self.assertEqual(options, ctx._options & options)
If C{singleUseKeys} is set, every context must have C{OP_SINGLE_DH_USE} and C{OP_SINGLE_ECDH_USE} set.
test_singleUseKeys
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_methodIsDeprecated(self): """ Passing C{method} to L{sslverify.OpenSSLCertificateOptions} is deprecated. """ sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, method=SSL.SSLv23_METHOD, ) message = ("Passing method to twisted.internet.ssl.CertificateOptions " "was deprecated in Twisted 17.1.0. Please use a " "combination of insecurelyLowerMinimumTo, raiseMinimumTo, " "and lowerMaximumSecurityTo instead, as Twisted will " "correctly configure the method.") warnings = self.flushWarnings([self.test_methodIsDeprecated]) self.assertEqual(1, len(warnings)) self.assertEqual(DeprecationWarning, warnings[0]['category']) self.assertEqual(message, warnings[0]['message'])
Passing C{method} to L{sslverify.OpenSSLCertificateOptions} is deprecated.
test_methodIsDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsv1ByDefault(self): """ L{sslverify.OpenSSLCertificateOptions} will make the default minimum TLS version v1.0, if no C{method}, or C{insecurelyLowerMinimumTo} is given. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3) self.assertEqual(options, ctx._options & options)
L{sslverify.OpenSSLCertificateOptions} will make the default minimum TLS version v1.0, if no C{method}, or C{insecurelyLowerMinimumTo} is given.
test_tlsv1ByDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsAtLeastWithMinimum(self): """ Passing C{insecurelyLowerMinimumTo} along with C{raiseMinimumTo} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception. """ with self.assertRaises(TypeError) as e: sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, raiseMinimumTo=sslverify.TLSVersion.TLSv1_2, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_2, ) self.assertIn('raiseMinimumTo', e.exception.args[0]) self.assertIn('insecurelyLowerMinimumTo', e.exception.args[0]) self.assertIn('exclusive', e.exception.args[0])
Passing C{insecurelyLowerMinimumTo} along with C{raiseMinimumTo} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception.
test_tlsProtocolsAtLeastWithMinimum
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsNoMethodWithAtLeast(self): """ Passing C{raiseMinimumTo} along with C{method} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception. """ with self.assertRaises(TypeError) as e: sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, method=SSL.SSLv23_METHOD, raiseMinimumTo=sslverify.TLSVersion.TLSv1_2, ) self.assertIn('method', e.exception.args[0]) self.assertIn('raiseMinimumTo', e.exception.args[0]) self.assertIn('exclusive', e.exception.args[0])
Passing C{raiseMinimumTo} along with C{method} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception.
test_tlsProtocolsNoMethodWithAtLeast
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsNoMethodWithMinimum(self): """ Passing C{insecurelyLowerMinimumTo} along with C{method} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception. """ with self.assertRaises(TypeError) as e: sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, method=SSL.SSLv23_METHOD, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_2, ) self.assertIn('method', e.exception.args[0]) self.assertIn('insecurelyLowerMinimumTo', e.exception.args[0]) self.assertIn('exclusive', e.exception.args[0])
Passing C{insecurelyLowerMinimumTo} along with C{method} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception.
test_tlsProtocolsNoMethodWithMinimum
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsNoMethodWithMaximum(self): """ Passing C{lowerMaximumSecurityTo} along with C{method} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception. """ with self.assertRaises(TypeError) as e: sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, method=SSL.SSLv23_METHOD, lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_2, ) self.assertIn('method', e.exception.args[0]) self.assertIn('lowerMaximumSecurityTo', e.exception.args[0]) self.assertIn('exclusive', e.exception.args[0])
Passing C{lowerMaximumSecurityTo} along with C{method} to L{sslverify.OpenSSLCertificateOptions} will cause it to raise an exception.
test_tlsProtocolsNoMethodWithMaximum
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsVersionRangeInOrder(self): """ Passing out of order TLS versions to C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} will cause it to raise an exception. """ with self.assertRaises(ValueError) as e: sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_0, lowerMaximumSecurityTo=sslverify.TLSVersion.SSLv3) self.assertEqual(e.exception.args, ( ("insecurelyLowerMinimumTo needs to be lower than " "lowerMaximumSecurityTo"),))
Passing out of order TLS versions to C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} will cause it to raise an exception.
test_tlsVersionRangeInOrder
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsVersionRangeInOrderAtLeast(self): """ Passing out of order TLS versions to C{raiseMinimumTo} and C{lowerMaximumSecurityTo} will cause it to raise an exception. """ with self.assertRaises(ValueError) as e: sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, raiseMinimumTo=sslverify.TLSVersion.TLSv1_0, lowerMaximumSecurityTo=sslverify.TLSVersion.SSLv3) self.assertEqual(e.exception.args, ( ("raiseMinimumTo needs to be lower than " "lowerMaximumSecurityTo"),))
Passing out of order TLS versions to C{raiseMinimumTo} and C{lowerMaximumSecurityTo} will cause it to raise an exception.
test_tlsVersionRangeInOrderAtLeast
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsreduceToMaxWithoutMin(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{lowerMaximumSecurityTo} but no C{raiseMinimumTo} or C{insecurelyLowerMinimumTo} set, and C{lowerMaximumSecurityTo} is below the minimum default, the minimum will be made the new maximum. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, lowerMaximumSecurityTo=sslverify.TLSVersion.SSLv3, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_1 | SSL.OP_NO_TLSv1_2 | opts._OP_NO_TLSv1_3) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{lowerMaximumSecurityTo} but no C{raiseMinimumTo} or C{insecurelyLowerMinimumTo} set, and C{lowerMaximumSecurityTo} is below the minimum default, the minimum will be made the new maximum.
test_tlsProtocolsreduceToMaxWithoutMin
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsSSLv3Only(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to SSLv3, it will exclude all others. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, insecurelyLowerMinimumTo=sslverify.TLSVersion.SSLv3, lowerMaximumSecurityTo=sslverify.TLSVersion.SSLv3, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_1 | SSL.OP_NO_TLSv1_2 | opts._OP_NO_TLSv1_3) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to SSLv3, it will exclude all others.
test_tlsProtocolsSSLv3Only
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsTLSv1Point0Only(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to v1.0, it will exclude all others. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_0, lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_0, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3 | SSL.OP_NO_TLSv1_1 | SSL.OP_NO_TLSv1_2 | opts._OP_NO_TLSv1_3) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to v1.0, it will exclude all others.
test_tlsProtocolsTLSv1Point0Only
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsTLSv1Point1Only(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to v1.1, it will exclude all others. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_1, lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_1, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3 | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_2 | opts._OP_NO_TLSv1_3) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to v1.1, it will exclude all others.
test_tlsProtocolsTLSv1Point1Only
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsTLSv1Point2Only(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to v1.2, it will exclude all others. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_2, lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_2, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3 | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_1 | opts._OP_NO_TLSv1_3) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} and C{lowerMaximumSecurityTo} set to v1.2, it will exclude all others.
test_tlsProtocolsTLSv1Point2Only
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsAllModernTLS(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} set to TLSv1.0 and C{lowerMaximumSecurityTo} to TLSv1.2, it will exclude both SSLs and the (unreleased) TLSv1.3. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_0, lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_2, ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3 | opts._OP_NO_TLSv1_3) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} set to TLSv1.0 and C{lowerMaximumSecurityTo} to TLSv1.2, it will exclude both SSLs and the (unreleased) TLSv1.3.
test_tlsProtocolsAllModernTLS
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsAtLeastAllSecureTLS(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{raiseMinimumTo} set to TLSv1.2, it will ignore all TLSs below 1.2 and SSL. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, raiseMinimumTo=sslverify.TLSVersion.TLSv1_2 ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3 | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_1) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{raiseMinimumTo} set to TLSv1.2, it will ignore all TLSs below 1.2 and SSL.
test_tlsProtocolsAtLeastAllSecureTLS
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsAtLeastWillAcceptHigherDefault(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{raiseMinimumTo} set to a value lower than Twisted's default will cause it to use the more secure default. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, raiseMinimumTo=sslverify.TLSVersion.SSLv3 ) opts._contextFactory = FakeContext ctx = opts.getContext() # Future maintainer warning: this will break if we change our default # up, so you should change it to add the relevant OP_NO flags when we # do make that change and this test fails. options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3) self.assertEqual(options, ctx._options & options) self.assertEqual(opts._defaultMinimumTLSVersion, sslverify.TLSVersion.TLSv1_0)
When calling L{sslverify.OpenSSLCertificateOptions} with C{raiseMinimumTo} set to a value lower than Twisted's default will cause it to use the more secure default.
test_tlsProtocolsAtLeastWillAcceptHigherDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_tlsProtocolsAllSecureTLS(self): """ When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} set to TLSv1.2, it will ignore all TLSs below 1.2 and SSL. """ opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, insecurelyLowerMinimumTo=sslverify.TLSVersion.TLSv1_2 ) opts._contextFactory = FakeContext ctx = opts.getContext() options = (SSL.OP_NO_SSLv2 | SSL.OP_NO_COMPRESSION | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_SSLv3 | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_1) self.assertEqual(options, ctx._options & options)
When calling L{sslverify.OpenSSLCertificateOptions} with C{insecurelyLowerMinimumTo} set to TLSv1.2, it will ignore all TLSs below 1.2 and SSL.
test_tlsProtocolsAllSecureTLS
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_dhParams(self): """ If C{dhParams} is set, they are loaded into each new context. """ class FakeDiffieHellmanParameters(object): _dhFile = FilePath(b'dh.params') dhParams = FakeDiffieHellmanParameters() opts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, dhParameters=dhParams, ) opts._contextFactory = FakeContext ctx = opts.getContext() self.assertEqual( FakeDiffieHellmanParameters._dhFile.path, ctx._dhFilename )
If C{dhParams} is set, they are loaded into each new context.
test_dhParams
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_abbreviatingDistinguishedNames(self): """ Check that abbreviations used in certificates correctly map to complete names. """ self.assertEqual( sslverify.DN(CN=b'a', OU=b'hello'), sslverify.DistinguishedName(commonName=b'a', organizationalUnitName=b'hello')) self.assertNotEqual( sslverify.DN(CN=b'a', OU=b'hello'), sslverify.DN(CN=b'a', OU=b'hello', emailAddress=b'xxx')) dn = sslverify.DN(CN=b'abcdefg') self.assertRaises(AttributeError, setattr, dn, 'Cn', b'x') self.assertEqual(dn.CN, dn.commonName) dn.CN = b'bcdefga' self.assertEqual(dn.CN, dn.commonName)
Check that abbreviations used in certificates correctly map to complete names.
test_abbreviatingDistinguishedNames
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_inspectCertificate(self): """ Test that the C{inspect} method of L{sslverify.Certificate} returns a human-readable string containing some basic information about the certificate. """ c = sslverify.Certificate.loadPEM(A_HOST_CERTIFICATE_PEM) pk = c.getPublicKey() keyHash = pk.keyHash() # Maintenance Note: the algorithm used to compute the "public key hash" # is highly dubious and can differ between underlying versions of # OpenSSL (and across versions of Twisted), since it is not actually # the hash of the public key by itself. If we can get the appropriate # APIs to get the hash of the key itself out of OpenSSL, then we should # be able to make it statically declared inline below again rather than # computing it here. self.assertEqual( c.inspect().split('\n'), ["Certificate For Subject:", " Common Name: example.twistedmatrix.com", " Country Name: US", " Email Address: [email protected]", " Locality Name: Boston", " Organization Name: Twisted Matrix Labs", " Organizational Unit Name: Security", " State Or Province Name: Massachusetts", "", "Issuer:", " Common Name: example.twistedmatrix.com", " Country Name: US", " Email Address: [email protected]", " Locality Name: Boston", " Organization Name: Twisted Matrix Labs", " Organizational Unit Name: Security", " State Or Province Name: Massachusetts", "", "Serial Number: 12345", "Digest: C4:96:11:00:30:C3:EC:EE:A3:55:AA:ED:8C:84:85:18", "Public Key with Hash: " + keyHash])
Test that the C{inspect} method of L{sslverify.Certificate} returns a human-readable string containing some basic information about the certificate.
test_inspectCertificate
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_publicKeyMatching(self): """ L{PublicKey.matches} returns L{True} for keys from certificates with the same key, and L{False} for keys from certificates with different keys. """ hostA = sslverify.Certificate.loadPEM(A_HOST_CERTIFICATE_PEM) hostB = sslverify.Certificate.loadPEM(A_HOST_CERTIFICATE_PEM) peerA = sslverify.Certificate.loadPEM(A_PEER_CERTIFICATE_PEM) self.assertTrue(hostA.getPublicKey().matches(hostB.getPublicKey())) self.assertFalse(peerA.getPublicKey().matches(hostA.getPublicKey()))
L{PublicKey.matches} returns L{True} for keys from certificates with the same key, and L{False} for keys from certificates with different keys.
test_publicKeyMatching
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_certificateOptionsSerialization(self): """ Test that __setstate__(__getstate__()) round-trips properly. """ firstOpts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, method=SSL.SSLv23_METHOD, verify=True, caCerts=[self.sCert], verifyDepth=2, requireCertificate=False, verifyOnce=False, enableSingleUseKeys=False, enableSessions=False, fixBrokenPeers=True, enableSessionTickets=True) context = firstOpts.getContext() self.assertIs(context, firstOpts._context) self.assertIsNotNone(context) state = firstOpts.__getstate__() self.assertNotIn("_context", state) opts = sslverify.OpenSSLCertificateOptions() opts.__setstate__(state) self.assertEqual(opts.privateKey, self.sKey) self.assertEqual(opts.certificate, self.sCert) self.assertEqual(opts.method, SSL.SSLv23_METHOD) self.assertTrue(opts.verify) self.assertEqual(opts.caCerts, [self.sCert]) self.assertEqual(opts.verifyDepth, 2) self.assertFalse(opts.requireCertificate) self.assertFalse(opts.verifyOnce) self.assertFalse(opts.enableSingleUseKeys) self.assertFalse(opts.enableSessions) self.assertTrue(opts.fixBrokenPeers) self.assertTrue(opts.enableSessionTickets)
Test that __setstate__(__getstate__()) round-trips properly.
test_certificateOptionsSerialization
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_certificateOptionsSessionTickets(self): """ Enabling session tickets should not set the OP_NO_TICKET option. """ opts = sslverify.OpenSSLCertificateOptions(enableSessionTickets=True) ctx = opts.getContext() self.assertEqual(0, ctx.set_options(0) & 0x00004000)
Enabling session tickets should not set the OP_NO_TICKET option.
test_certificateOptionsSessionTickets
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_certificateOptionsSessionTicketsDisabled(self): """ Enabling session tickets should set the OP_NO_TICKET option. """ opts = sslverify.OpenSSLCertificateOptions(enableSessionTickets=False) ctx = opts.getContext() self.assertEqual(0x00004000, ctx.set_options(0) & 0x00004000)
Enabling session tickets should set the OP_NO_TICKET option.
test_certificateOptionsSessionTicketsDisabled
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_allowedAnonymousClientConnection(self): """ Check that anonymous connections are allowed when certificates aren't required on the server. """ onData = defer.Deferred() self.loopback(sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, requireCertificate=False), sslverify.OpenSSLCertificateOptions( requireCertificate=False), onData=onData) return onData.addCallback( lambda result: self.assertEqual(result, WritingProtocol.byte))
Check that anonymous connections are allowed when certificates aren't required on the server.
test_allowedAnonymousClientConnection
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_refusedAnonymousClientConnection(self): """ Check that anonymous connections are refused when certificates are required on the server. """ onServerLost = defer.Deferred() onClientLost = defer.Deferred() self.loopback(sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, verify=True, caCerts=[self.sCert], requireCertificate=True), sslverify.OpenSSLCertificateOptions( requireCertificate=False), onServerLost=onServerLost, onClientLost=onClientLost) d = defer.DeferredList([onClientLost, onServerLost], consumeErrors=True) def afterLost(result): ((cSuccess, cResult), (sSuccess, sResult)) = result self.assertFalse(cSuccess) self.assertFalse(sSuccess) # Win32 fails to report the SSL Error, and report a connection lost # instead: there is a race condition so that's not totally # surprising (see ticket #2877 in the tracker) self.assertIsInstance(cResult.value, (SSL.Error, ConnectionLost)) self.assertIsInstance(sResult.value, SSL.Error) return d.addCallback(afterLost)
Check that anonymous connections are refused when certificates are required on the server.
test_refusedAnonymousClientConnection
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_failedCertificateVerification(self): """ Check that connecting with a certificate not accepted by the server CA fails. """ onServerLost = defer.Deferred() onClientLost = defer.Deferred() self.loopback(sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, verify=False, requireCertificate=False), sslverify.OpenSSLCertificateOptions(verify=True, requireCertificate=False, caCerts=[self.cCert]), onServerLost=onServerLost, onClientLost=onClientLost) d = defer.DeferredList([onClientLost, onServerLost], consumeErrors=True) def afterLost(result): ((cSuccess, cResult), (sSuccess, sResult)) = result self.assertFalse(cSuccess) self.assertFalse(sSuccess) return d.addCallback(afterLost)
Check that connecting with a certificate not accepted by the server CA fails.
test_failedCertificateVerification
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_successfulCertificateVerification(self): """ Test a successful connection with client certificate validation on server side. """ onData = defer.Deferred() self.loopback(sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, verify=False, requireCertificate=False), sslverify.OpenSSLCertificateOptions(verify=True, requireCertificate=True, caCerts=[self.sCert]), onData=onData) return onData.addCallback( lambda result: self.assertEqual(result, WritingProtocol.byte))
Test a successful connection with client certificate validation on server side.
test_successfulCertificateVerification
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_successfulSymmetricSelfSignedCertificateVerification(self): """ Test a successful connection with validation on both server and client sides. """ onData = defer.Deferred() self.loopback(sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, verify=True, requireCertificate=True, caCerts=[self.cCert]), sslverify.OpenSSLCertificateOptions(privateKey=self.cKey, certificate=self.cCert, verify=True, requireCertificate=True, caCerts=[self.sCert]), onData=onData) return onData.addCallback( lambda result: self.assertEqual(result, WritingProtocol.byte))
Test a successful connection with validation on both server and client sides.
test_successfulSymmetricSelfSignedCertificateVerification
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_verification(self): """ Check certificates verification building custom certificates data. """ clientDN = sslverify.DistinguishedName(commonName='client') clientKey = sslverify.KeyPair.generate() clientCertReq = clientKey.certificateRequest(clientDN) serverDN = sslverify.DistinguishedName(commonName='server') serverKey = sslverify.KeyPair.generate() serverCertReq = serverKey.certificateRequest(serverDN) clientSelfCertReq = clientKey.certificateRequest(clientDN) clientSelfCertData = clientKey.signCertificateRequest( clientDN, clientSelfCertReq, lambda dn: True, 132) clientSelfCert = clientKey.newCertificate(clientSelfCertData) serverSelfCertReq = serverKey.certificateRequest(serverDN) serverSelfCertData = serverKey.signCertificateRequest( serverDN, serverSelfCertReq, lambda dn: True, 516) serverSelfCert = serverKey.newCertificate(serverSelfCertData) clientCertData = serverKey.signCertificateRequest( serverDN, clientCertReq, lambda dn: True, 7) clientCert = clientKey.newCertificate(clientCertData) serverCertData = clientKey.signCertificateRequest( clientDN, serverCertReq, lambda dn: True, 42) serverCert = serverKey.newCertificate(serverCertData) onData = defer.Deferred() serverOpts = serverCert.options(serverSelfCert) clientOpts = clientCert.options(clientSelfCert) self.loopback(serverOpts, clientOpts, onData=onData) return onData.addCallback( lambda result: self.assertEqual(result, WritingProtocol.byte))
Check certificates verification building custom certificates data.
test_verification
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_ellipticCurveDiffieHellman(self): """ Connections use ECDH when OpenSSL supports it. """ if not get_elliptic_curves(): raise unittest.SkipTest("OpenSSL does not support ECDH.") onData = defer.Deferred() # TLS 1.3 cipher suites do not specify the key exchange # mechanism: # https://wiki.openssl.org/index.php/TLS1.3#Differences_with_TLS1.2_and_below # # and OpenSSL only supports ECHDE groups with TLS 1.3: # https://wiki.openssl.org/index.php/TLS1.3#Groups # # so TLS 1.3 implies ECDHE. Force this test to use TLS 1.2 to # ensure ECDH is selected when it might not be. self.loopback( sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, requireCertificate=False, lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_2 ), sslverify.OpenSSLCertificateOptions( requireCertificate=False, lowerMaximumSecurityTo=sslverify.TLSVersion.TLSv1_2, ), onData=onData, ) @onData.addCallback def assertECDH(_): self.assertEqual(len(self.clientConn.factory.protocols), 1) [clientProtocol] = self.clientConn.factory.protocols cipher = clientProtocol.getHandle().get_cipher_name() self.assertIn(u"ECDH", cipher) return onData
Connections use ECDH when OpenSSL supports it.
test_ellipticCurveDiffieHellman
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_getstateDeprecation(self): """ L{sslverify.OpenSSLCertificateOptions.__getstate__} is deprecated. """ self.callDeprecated( (Version("Twisted", 15, 0, 0), "a real persistence system"), sslverify.OpenSSLCertificateOptions().__getstate__)
L{sslverify.OpenSSLCertificateOptions.__getstate__} is deprecated.
test_getstateDeprecation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_setstateDeprecation(self): """ L{sslverify.OpenSSLCertificateOptions.__setstate__} is deprecated. """ self.callDeprecated( (Version("Twisted", 15, 0, 0), "a real persistence system"), sslverify.OpenSSLCertificateOptions().__setstate__, {})
L{sslverify.OpenSSLCertificateOptions.__setstate__} is deprecated.
test_setstateDeprecation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def setUp(self): """ Patch L{sslverify._ChooseDiffieHellmanEllipticCurve}. """ self.patch(sslverify, "_ChooseDiffieHellmanEllipticCurve", FakeChooseDiffieHellmanEllipticCurve)
Patch L{sslverify._ChooseDiffieHellmanEllipticCurve}.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_caCertsPlatformDefaults(self): """ Specifying a C{trustRoot} of L{sslverify.OpenSSLDefaultPaths} when initializing L{sslverify.OpenSSLCertificateOptions} loads the platform-provided trusted certificates via C{set_default_verify_paths}. """ opts = sslverify.OpenSSLCertificateOptions( trustRoot=sslverify.OpenSSLDefaultPaths(), ) fc = FakeContext(SSL.TLSv1_METHOD) opts._contextFactory = lambda method: fc opts.getContext() self.assertTrue(fc._defaultVerifyPathsSet)
Specifying a C{trustRoot} of L{sslverify.OpenSSLDefaultPaths} when initializing L{sslverify.OpenSSLCertificateOptions} loads the platform-provided trusted certificates via C{set_default_verify_paths}.
test_caCertsPlatformDefaults
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_trustRootPlatformRejectsUntrustedCA(self): """ Specifying a C{trustRoot} of L{platformTrust} when initializing L{sslverify.OpenSSLCertificateOptions} causes certificates issued by a newly created CA to be rejected by an SSL connection using these options. Note that this test should I{always} pass, even on platforms where the CA certificates are not installed, as long as L{platformTrust} rejects completely invalid / unknown root CA certificates. This is simply a smoke test to make sure that verification is happening at all. """ caSelfCert, serverCert = certificatesForAuthorityAndServer() chainedCert = pathContainingDumpOf(self, serverCert, caSelfCert) privateKey = pathContainingDumpOf(self, serverCert.privateKey) sProto, cProto, sWrapped, cWrapped, pump = loopbackTLSConnection( trustRoot=platformTrust(), privateKeyFile=privateKey, chainedCertFile=chainedCert, ) # No data was received. self.assertEqual(cWrapped.data, b'') # It was an L{SSL.Error}. self.assertEqual(cWrapped.lostReason.type, SSL.Error) # Some combination of OpenSSL and PyOpenSSL is bad at reporting errors. err = cWrapped.lostReason.value self.assertEqual(err.args[0][0][2], 'tlsv1 alert unknown ca')
Specifying a C{trustRoot} of L{platformTrust} when initializing L{sslverify.OpenSSLCertificateOptions} causes certificates issued by a newly created CA to be rejected by an SSL connection using these options. Note that this test should I{always} pass, even on platforms where the CA certificates are not installed, as long as L{platformTrust} rejects completely invalid / unknown root CA certificates. This is simply a smoke test to make sure that verification is happening at all.
test_trustRootPlatformRejectsUntrustedCA
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_trustRootSpecificCertificate(self): """ Specifying a L{Certificate} object for L{trustRoot} will result in that certificate being the only trust root for a client. """ caCert, serverCert = certificatesForAuthorityAndServer() otherCa, otherServer = certificatesForAuthorityAndServer() sProto, cProto, sWrapped, cWrapped, pump = loopbackTLSConnection( trustRoot=caCert, privateKeyFile=pathContainingDumpOf(self, serverCert.privateKey), chainedCertFile=pathContainingDumpOf(self, serverCert), ) pump.flush() self.assertIsNone(cWrapped.lostReason) self.assertEqual(cWrapped.data, sWrapped.greeting)
Specifying a L{Certificate} object for L{trustRoot} will result in that certificate being the only trust root for a client.
test_trustRootSpecificCertificate
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def broken(*a, **k): """ Raise an exception. @param a: Arguments for an C{info_callback} @param k: Keyword arguments for an C{info_callback} """ 1 / 0
Raise an exception. @param a: Arguments for an C{info_callback} @param k: Keyword arguments for an C{info_callback}
serviceIdentitySetup.broken
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def serviceIdentitySetup(self, clientHostname, serverHostname, serverContextSetup=lambda ctx: None, validCertificate=True, clientPresentsCertificate=False, validClientCertificate=True, serverVerifies=False, buggyInfoCallback=False, fakePlatformTrust=False, useDefaultTrust=False): """ Connect a server and a client. @param clientHostname: The I{client's idea} of the server's hostname; passed as the C{hostname} to the L{sslverify.OpenSSLCertificateOptions} instance. @type clientHostname: L{unicode} @param serverHostname: The I{server's own idea} of the server's hostname; present in the certificate presented by the server. @type serverHostname: L{unicode} @param serverContextSetup: a 1-argument callable invoked with the L{OpenSSL.SSL.Context} after it's produced. @type serverContextSetup: L{callable} taking L{OpenSSL.SSL.Context} returning L{None}. @param validCertificate: Is the server's certificate valid? L{True} if so, L{False} otherwise. @type validCertificate: L{bool} @param clientPresentsCertificate: Should the client present a certificate to the server? Defaults to 'no'. @type clientPresentsCertificate: L{bool} @param validClientCertificate: If the client presents a certificate, should it actually be a valid one, i.e. signed by the same CA that the server is checking? Defaults to 'yes'. @type validClientCertificate: L{bool} @param serverVerifies: Should the server verify the client's certificate? Defaults to 'no'. @type serverVerifies: L{bool} @param buggyInfoCallback: Should we patch the implementation so that the C{info_callback} passed to OpenSSL to have a bug and raise an exception (L{ZeroDivisionError})? Defaults to 'no'. @type buggyInfoCallback: L{bool} @param fakePlatformTrust: Should we fake the platformTrust to be the same as our fake server certificate authority, so that we can test it's being used? Defaults to 'no' and we just pass platform trust. @type fakePlatformTrust: L{bool} @param useDefaultTrust: Should we avoid passing the C{trustRoot} to L{ssl.optionsForClientTLS}? Defaults to 'no'. @type useDefaultTrust: L{bool} @return: the client TLS protocol, the client wrapped protocol, the server TLS protocol, the server wrapped protocol and an L{IOPump} which, when its C{pump} and C{flush} methods are called, will move data between the created client and server protocol instances @rtype: 5-L{tuple} of 4 L{IProtocol}s and L{IOPump} """ serverCA, serverCert = certificatesForAuthorityAndServer( serverHostname ) other = {} passClientCert = None clientCA, clientCert = certificatesForAuthorityAndServer(u'client') if serverVerifies: other.update(trustRoot=clientCA) if clientPresentsCertificate: if validClientCertificate: passClientCert = clientCert else: bogusCA, bogus = certificatesForAuthorityAndServer(u'client') passClientCert = bogus serverOpts = sslverify.OpenSSLCertificateOptions( privateKey=serverCert.privateKey.original, certificate=serverCert.original, **other ) serverContextSetup(serverOpts.getContext()) if not validCertificate: serverCA, otherServer = certificatesForAuthorityAndServer( serverHostname ) if buggyInfoCallback: def broken(*a, **k): """ Raise an exception. @param a: Arguments for an C{info_callback} @param k: Keyword arguments for an C{info_callback} """ 1 / 0 self.patch( sslverify.ClientTLSOptions, "_identityVerifyingInfoCallback", broken, ) signature = {'hostname': clientHostname} if passClientCert: signature.update(clientCertificate=passClientCert) if not useDefaultTrust: signature.update(trustRoot=serverCA) if fakePlatformTrust: self.patch(sslverify, "platformTrust", lambda: serverCA) clientOpts = sslverify.optionsForClientTLS(**signature) class GreetingServer(protocol.Protocol): greeting = b"greetings!" lostReason = None data = b'' def connectionMade(self): self.transport.write(self.greeting) def dataReceived(self, data): self.data += data def connectionLost(self, reason): self.lostReason = reason class GreetingClient(protocol.Protocol): greeting = b'cheerio!' data = b'' lostReason = None def connectionMade(self): self.transport.write(self.greeting) def dataReceived(self, data): self.data += data def connectionLost(self, reason): self.lostReason = reason serverWrappedProto = GreetingServer() clientWrappedProto = GreetingClient() clientFactory = protocol.Factory() clientFactory.protocol = lambda: clientWrappedProto serverFactory = protocol.Factory() serverFactory.protocol = lambda: serverWrappedProto self.serverOpts = serverOpts self.clientOpts = clientOpts clientTLSFactory = TLSMemoryBIOFactory( clientOpts, isClient=True, wrappedFactory=clientFactory ) serverTLSFactory = TLSMemoryBIOFactory( serverOpts, isClient=False, wrappedFactory=serverFactory ) cProto, sProto, pump = connectedServerAndClient( lambda: serverTLSFactory.buildProtocol(None), lambda: clientTLSFactory.buildProtocol(None), ) return cProto, sProto, clientWrappedProto, serverWrappedProto, pump
Connect a server and a client. @param clientHostname: The I{client's idea} of the server's hostname; passed as the C{hostname} to the L{sslverify.OpenSSLCertificateOptions} instance. @type clientHostname: L{unicode} @param serverHostname: The I{server's own idea} of the server's hostname; present in the certificate presented by the server. @type serverHostname: L{unicode} @param serverContextSetup: a 1-argument callable invoked with the L{OpenSSL.SSL.Context} after it's produced. @type serverContextSetup: L{callable} taking L{OpenSSL.SSL.Context} returning L{None}. @param validCertificate: Is the server's certificate valid? L{True} if so, L{False} otherwise. @type validCertificate: L{bool} @param clientPresentsCertificate: Should the client present a certificate to the server? Defaults to 'no'. @type clientPresentsCertificate: L{bool} @param validClientCertificate: If the client presents a certificate, should it actually be a valid one, i.e. signed by the same CA that the server is checking? Defaults to 'yes'. @type validClientCertificate: L{bool} @param serverVerifies: Should the server verify the client's certificate? Defaults to 'no'. @type serverVerifies: L{bool} @param buggyInfoCallback: Should we patch the implementation so that the C{info_callback} passed to OpenSSL to have a bug and raise an exception (L{ZeroDivisionError})? Defaults to 'no'. @type buggyInfoCallback: L{bool} @param fakePlatformTrust: Should we fake the platformTrust to be the same as our fake server certificate authority, so that we can test it's being used? Defaults to 'no' and we just pass platform trust. @type fakePlatformTrust: L{bool} @param useDefaultTrust: Should we avoid passing the C{trustRoot} to L{ssl.optionsForClientTLS}? Defaults to 'no'. @type useDefaultTrust: L{bool} @return: the client TLS protocol, the client wrapped protocol, the server TLS protocol, the server wrapped protocol and an L{IOPump} which, when its C{pump} and C{flush} methods are called, will move data between the created client and server protocol instances @rtype: 5-L{tuple} of 4 L{IProtocol}s and L{IOPump}
serviceIdentitySetup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_invalidHostname(self): """ When a certificate containing an invalid hostname is received from the server, the connection is immediately dropped. """ cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup( u"wrong-host.example.com", u"correct-host.example.com", ) self.assertEqual(cWrapped.data, b'') self.assertEqual(sWrapped.data, b'') cErr = cWrapped.lostReason.value sErr = sWrapped.lostReason.value self.assertIsInstance(cErr, VerificationError) self.assertIsInstance(sErr, ConnectionClosed)
When a certificate containing an invalid hostname is received from the server, the connection is immediately dropped.
test_invalidHostname
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_validHostname(self): """ Whenever a valid certificate containing a valid hostname is received, connection proceeds normally. """ cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup( u"valid.example.com", u"valid.example.com", ) self.assertEqual(cWrapped.data, b'greetings!') cErr = cWrapped.lostReason sErr = sWrapped.lostReason self.assertIsNone(cErr) self.assertIsNone(sErr)
Whenever a valid certificate containing a valid hostname is received, connection proceeds normally.
test_validHostname
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_validHostnameInvalidCertificate(self): """ When an invalid certificate containing a perfectly valid hostname is received, the connection is aborted with an OpenSSL error. """ cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup( u"valid.example.com", u"valid.example.com", validCertificate=False, ) self.assertEqual(cWrapped.data, b'') self.assertEqual(sWrapped.data, b'') cErr = cWrapped.lostReason.value sErr = sWrapped.lostReason.value self.assertIsInstance(cErr, SSL.Error) self.assertIsInstance(sErr, SSL.Error)
When an invalid certificate containing a perfectly valid hostname is received, the connection is aborted with an OpenSSL error.
test_validHostnameInvalidCertificate
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_realCAsBetterNotSignOurBogusTestCerts(self): """ If we use the default trust from the platform, our dinky certificate should I{really} fail. """ cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup( u"valid.example.com", u"valid.example.com", validCertificate=False, useDefaultTrust=True, ) self.assertEqual(cWrapped.data, b'') self.assertEqual(sWrapped.data, b'') cErr = cWrapped.lostReason.value sErr = sWrapped.lostReason.value self.assertIsInstance(cErr, SSL.Error) self.assertIsInstance(sErr, SSL.Error)
If we use the default trust from the platform, our dinky certificate should I{really} fail.
test_realCAsBetterNotSignOurBogusTestCerts
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_butIfTheyDidItWouldWork(self): """ L{ssl.optionsForClientTLS} should be using L{ssl.platformTrust} by default, so if we fake that out then it should trust ourselves again. """ cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup( u"valid.example.com", u"valid.example.com", useDefaultTrust=True, fakePlatformTrust=True, ) self.assertEqual(cWrapped.data, b'greetings!') cErr = cWrapped.lostReason sErr = sWrapped.lostReason self.assertIsNone(cErr) self.assertIsNone(sErr)
L{ssl.optionsForClientTLS} should be using L{ssl.platformTrust} by default, so if we fake that out then it should trust ourselves again.
test_butIfTheyDidItWouldWork
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT
def test_clientPresentsCertificate(self): """ When the server verifies and the client presents a valid certificate for that verification by passing it to L{sslverify.optionsForClientTLS}, communication proceeds. """ cProto, sProto, cWrapped, sWrapped, pump = self.serviceIdentitySetup( u"valid.example.com", u"valid.example.com", validCertificate=True, serverVerifies=True, clientPresentsCertificate=True, ) self.assertEqual(cWrapped.data, b'greetings!') cErr = cWrapped.lostReason sErr = sWrapped.lostReason self.assertIsNone(cErr) self.assertIsNone(sErr)
When the server verifies and the client presents a valid certificate for that verification by passing it to L{sslverify.optionsForClientTLS}, communication proceeds.
test_clientPresentsCertificate
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_sslverify.py
MIT