def test_certificateOptionsFromPEMs(self, tmpdir, recwarn): """ pem.certificateOptionsFromPEMs raises a deprecation warning. """ with pytest.warns(DeprecationWarning) as ws: pem.certificateOptionsFromPEMs( pem.parse(CERT_PEMS[0]) + pem.parse(KEY_PEM), ) assert "certificateOptionsFromPEMs" in str(ws[0].message)
def test_certificateOptionsFromPEMs(self, monkeypatch, recwarn): """ pem.certificateOptionsFromPEMs raises a deprecation warning and calls the original method with the same arguments. """ cr = call_recorder(lambda *a, **kw: None) monkeypatch.setattr(pem, "certificateOptionsFromPEMsOriginal", cr) pem.certificateOptionsFromPEMs("foo", bar="baz") assert [call("foo", bar="baz")] == cr.calls w = recwarn.pop(DeprecationWarning) assert "certificateOptionsFromPEMs" in str(w.message)
import pem # the actual html/css/js... files being served are all located here DOCUMENTS = FilePath(__file__).parent().child("public") ERROR_RESOURCE = DOCUMENTS.child("error").child("index.html") INSECURE_PORT = os.environ.get("INSECURE_PORT") SECURE_PORT = os.environ.get("SECURE_PORT") # all certificates are passed in as environment variables PRIVATE_KEY = os.environ.get("PRIVATE_KEY") CERTIFICATE_CHAIN = os.environ.get("CERTIFICATE_CHAIN") DH_PARAMETER = os.environ.get("DH_PARAMETER") ctxFactory = pem.certificateOptionsFromPEMs( pem.parse(PRIVATE_KEY), pem.parse(CERTIFICATE_CHAIN), dhParameters=pem.DiffieHellmanParameters(DH_PARAMETER)) class RedirectResource(Resource): isLeaf = True def render(self, request): host = request.requestHeaders.getRawHeaders('host')[0].split(':', 1)[0] port = '' if SECURE_PORT is not None: port = ':{0}'.format(SECURE_PORT) return redirectTo('https://{0}{1}{2}'.format(host, port, request.uri), request)
# the actual html/css/js... files being served are all located here DOCUMENTS = FilePath(__file__).parent().child("public") ERROR_RESOURCE = DOCUMENTS.child("error").child("index.html") INSECURE_PORT = os.environ.get("INSECURE_PORT") SECURE_PORT = os.environ.get("SECURE_PORT") # all certificates are passed in as environment variables PRIVATE_KEY = os.environ.get("PRIVATE_KEY") CERTIFICATE_CHAIN = os.environ.get("CERTIFICATE_CHAIN") DH_PARAMETER = os.environ.get("DH_PARAMETER") ctxFactory = pem.certificateOptionsFromPEMs( pem.parse(PRIVATE_KEY), pem.parse(CERTIFICATE_CHAIN), dhParameters=pem.DiffieHellmanParameters(DH_PARAMETER) ) class RedirectResource(Resource): isLeaf = True def render(self, request): host = request.requestHeaders.getRawHeaders('host')[0].split(':', 1)[0] port = '' if SECURE_PORT is not None: port = ':{0}'.format(SECURE_PORT) return redirectTo( 'https://{0}{1}{2}'.format(host, port, request.uri), request