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
194
url
stringlengths
46
254
license
stringclasses
4 values
def testDeferredYielding(self): """ Ensure that yielding a Deferred directly is trapped as an error. """ # See the comment _deferGenerator about d.callback(Deferred). def _genDeferred(): yield getThing() _genDeferred = deprecatedDeferredGenerator(_genDeferred) return self.assertFailure(_genDeferred(), TypeError)
Ensure that yielding a Deferred directly is trapped as an error.
testDeferredYielding
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def testYieldNonDeferred(self): """ Ensure that yielding a non-deferred passes it back as the result of the yield expression. @return: A L{twisted.internet.defer.Deferred} @rtype: L{twisted.internet.defer.Deferred} """ def _test(): yield 5 returnValue(5) _test = inlineCallbacks(_test) return _test().addCallback(self.assertEqual, 5)
Ensure that yielding a non-deferred passes it back as the result of the yield expression. @return: A L{twisted.internet.defer.Deferred} @rtype: L{twisted.internet.defer.Deferred}
testYieldNonDeferred
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def testReturnNoValue(self): """Ensure a standard python return results in a None result.""" def _noReturn(): yield 5 return _noReturn = inlineCallbacks(_noReturn) return _noReturn().addCallback(self.assertEqual, None)
Ensure a standard python return results in a None result.
testReturnNoValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def testReturnValue(self): """Ensure that returnValue works.""" def _return(): yield 5 returnValue(6) _return = inlineCallbacks(_return) return _return().addCallback(self.assertEqual, 6)
Ensure that returnValue works.
testReturnValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def test_nonGeneratorReturn(self): """ Ensure that C{TypeError} with a message about L{inlineCallbacks} is raised when a non-generator returns something other than a generator. """ def _noYield(): return 5 _noYield = inlineCallbacks(_noYield) self.assertIn("inlineCallbacks", str(self.assertRaises(TypeError, _noYield)))
Ensure that C{TypeError} with a message about L{inlineCallbacks} is raised when a non-generator returns something other than a generator.
test_nonGeneratorReturn
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def test_nonGeneratorReturnValue(self): """ Ensure that C{TypeError} with a message about L{inlineCallbacks} is raised when a non-generator calls L{returnValue}. """ def _noYield(): returnValue(5) _noYield = inlineCallbacks(_noYield) self.assertIn("inlineCallbacks", str(self.assertRaises(TypeError, _noYield)))
Ensure that C{TypeError} with a message about L{inlineCallbacks} is raised when a non-generator calls L{returnValue}.
test_nonGeneratorReturnValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def test_deferredGeneratorDeprecated(self): """ L{deferredGenerator} is deprecated. """ @deferredGenerator def decoratedFunction(): yield None warnings = self.flushWarnings([self.test_deferredGeneratorDeprecated]) self.assertEqual(len(warnings), 1) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual( warnings[0]['message'], "twisted.internet.defer.deferredGenerator was deprecated in " "Twisted 15.0.0; please use " "twisted.internet.defer.inlineCallbacks instead")
L{deferredGenerator} is deprecated.
test_deferredGeneratorDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def test_waitForDeferredDeprecated(self): """ L{waitForDeferred} is deprecated. """ d = Deferred() waitForDeferred(d) warnings = self.flushWarnings([self.test_waitForDeferredDeprecated]) self.assertEqual(len(warnings), 1) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual( warnings[0]['message'], "twisted.internet.defer.waitForDeferred was deprecated in " "Twisted 15.0.0; please use " "twisted.internet.defer.inlineCallbacks instead")
L{waitForDeferred} is deprecated.
test_waitForDeferredDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defgen.py
MIT
def connectionMade(self): """ Signal the parent process that we're ready. """ self.transport.write(b"x")
Signal the parent process that we're ready.
connectionMade
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/stdio_test_halfclose.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/stdio_test_halfclose.py
MIT
def readConnectionLost(self): """ This is the desired event. Once it has happened, stop the reactor so the process will exit. """ self.exitCode = 0 reactor.stop()
This is the desired event. Once it has happened, stop the reactor so the process will exit.
readConnectionLost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/stdio_test_halfclose.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/stdio_test_halfclose.py
MIT
def connectionLost(self, reason): """ This may only be invoked after C{readConnectionLost}. If it happens otherwise, mark it as an error and shut down. """ if self.exitCode is None: self.exitCode = 1 log.err(reason, "Unexpected call to connectionLost") reactor.stop()
This may only be invoked after C{readConnectionLost}. If it happens otherwise, mark it as an error and shut down.
connectionLost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/stdio_test_halfclose.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/stdio_test_halfclose.py
MIT
def _unimport(self, name): """ Find the given module and all of its hierarchically inferior modules in C{sys.modules}, remove them from it, and return whatever was found. """ modules = dict([ (moduleName, module) for (moduleName, module) in list(sys.modules.items()) if (moduleName == self.name or moduleName.startswith(self.name + "."))]) for name in modules: del sys.modules[name] return modules
Find the given module and all of its hierarchically inferior modules in C{sys.modules}, remove them from it, and return whatever was found.
_unimport
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 _install(modules): """ Take a mapping defining a package and turn it into real C{ModuleType} instances in C{sys.modules}. Consider these example:: a = {"foo": "bar"} b = {"twisted": {"__version__": "42.6"}} c = {"twisted": {"plugin": {"getPlugins": stub}}} C{_install(a)} will place an item into C{sys.modules} with C{"foo"} as the key and C{"bar" as the value. C{_install(b)} will place an item into C{sys.modules} with C{"twisted"} as the key. The value will be a new module object. The module will have a C{"__version__"} attribute with C{"42.6"} as the value. C{_install(c)} will place an item into C{sys.modules} with C{"twisted"} as the key. The value will be a new module object with a C{"plugin"} attribute. An item will also be placed into C{sys.modules} with the key C{"twisted.plugin"} which refers to that module object. That module will have an attribute C{"getPlugins"} with a value of C{stub}. @param modules: A mapping from names to definitions of modules. The names are native strings like C{"twisted"} or C{"unittest"}. Values may be arbitrary objects. Any value which is not a dictionary will be added to C{sys.modules} unmodified. Any dictionary value indicates the value is a new module and its items define the attributes of that module. The definition of this structure is recursive, so a value in the dictionary may be a dictionary to trigger another level of processing. @return: L{None} """ result = {} _makePackages(None, modules, result) sys.modules.update(result)
Take a mapping defining a package and turn it into real C{ModuleType} instances in C{sys.modules}. Consider these example:: a = {"foo": "bar"} b = {"twisted": {"__version__": "42.6"}} c = {"twisted": {"plugin": {"getPlugins": stub}}} C{_install(a)} will place an item into C{sys.modules} with C{"foo"} as the key and C{"bar" as the value. C{_install(b)} will place an item into C{sys.modules} with C{"twisted"} as the key. The value will be a new module object. The module will have a C{"__version__"} attribute with C{"42.6"} as the value. C{_install(c)} will place an item into C{sys.modules} with C{"twisted"} as the key. The value will be a new module object with a C{"plugin"} attribute. An item will also be placed into C{sys.modules} with the key C{"twisted.plugin"} which refers to that module object. That module will have an attribute C{"getPlugins"} with a value of C{stub}. @param modules: A mapping from names to definitions of modules. The names are native strings like C{"twisted"} or C{"unittest"}. Values may be arbitrary objects. Any value which is not a dictionary will be added to C{sys.modules} unmodified. Any dictionary value indicates the value is a new module and its items define the attributes of that module. The definition of this structure is recursive, so a value in the dictionary may be a dictionary to trigger another level of processing. @return: L{None}
_install
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 _makePackages(parent, attributes, result): """ Construct module objects (for either modules or packages). @param parent: L{None} or a module object which is the Python package containing all of the modules being created by this function call. Its name will be prepended to the name of all created modules. @param attributes: A mapping giving the attributes of the particular module object this call is creating. @param result: A mapping which is populated with all created module names. This is suitable for use in updating C{sys.modules}. @return: A mapping of all of the attributes created by this call. This is suitable for populating the dictionary of C{parent}. @see: L{_install}. """ attrs = {} for (name, value) in list(attributes.items()): if parent is None: if isinstance(value, dict): module = ModuleType(name) module.__dict__.update(_makePackages(module, value, result)) result[name] = module else: result[name] = value else: if isinstance(value, dict): module = ModuleType(parent.__name__ + '.' + name) module.__dict__.update(_makePackages(module, value, result)) result[parent.__name__ + '.' + name] = module attrs[name] = module else: attrs[name] = value return attrs
Construct module objects (for either modules or packages). @param parent: L{None} or a module object which is the Python package containing all of the modules being created by this function call. Its name will be prepended to the name of all created modules. @param attributes: A mapping giving the attributes of the particular module object this call is creating. @param result: A mapping which is populated with all created module names. This is suitable for use in updating C{sys.modules}. @return: A mapping of all of the attributes created by this call. This is suitable for populating the dictionary of C{parent}. @see: L{_install}.
_makePackages
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 setUp(self): """ Save the original value of C{sys.version_info} so it can be restored after the tests mess with it. """ self.version = sys.version_info
Save the original value of C{sys.version_info} so it can be restored after the tests mess with it.
setUp
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 tearDown(self): """ Restore the original values saved in L{setUp}. """ sys.version_info = self.version
Restore the original values saved in L{setUp}.
tearDown
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_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_oldPythonPy3(self): """ L{_checkPythonVersion} raises L{ImportError} when run on a version of Python that is too old. """ sys.version_info = self.Py3unsupportedPythonVersion with self.assertRaises(ImportError) as raised: _checkPythonVersion() self.assertEqual("Twisted on Python 3 requires Python %d.%d or later." % self.Py3supportedPythonVersion, str(raised.exception))
L{_checkPythonVersion} raises L{ImportError} when run on a version of Python that is too old.
test_oldPythonPy3
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_newPythonPy3(self): """ L{_checkPythonVersion} returns L{None} when run on a version of Python that is sufficiently new. """ sys.version_info = self.Py3supportedPythonVersion self.assertIsNone(_checkPythonVersion())
L{_checkPythonVersion} returns L{None} when run on a version of Python that is sufficiently new.
test_newPythonPy3
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_constructorWithOnlyCertificate(self): """ C{privateKey} and C{certificate} make only sense if both are set. """ self.assertRaises( ValueError, sslverify.OpenSSLCertificateOptions, certificate=self.sCert )
C{privateKey} and C{certificate} make only sense if both are set.
test_constructorWithOnlyCertificate
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