예제 #1
0
    def test_disable_for_url(self):
        def sslify_disable(request):
            return request.get_full_path().startswith('/disabled')

        with self.settings(SSLIFY_DISABLE_FOR_REQUEST=[sslify_disable]):
            middleware = SSLifyMiddleware()
            request = self.factory.get('/disabled/')
            request = middleware.process_request(request)
            self.assertIsNone(request)

            request = self.factory.get('/enabled/')
            result = middleware.process_request(request)
            self.assert_https_redirect(result)
예제 #2
0
    def test_disable_for_url(self):
        def sslify_disable(request):
            return request.get_full_path().startswith('/disabled')

        with self.settings(SSLIFY_DISABLE_FOR_REQUEST=[sslify_disable]):
            middleware = SSLifyMiddleware()
            request = self.factory.get('/disabled/')
            request = middleware.process_request(request)
            self.assertIsNone(request)

            request = self.factory.get('/enabled/')
            result = middleware.process_request(request)
            self.assert_https_redirect(result)
예제 #3
0
    def test_custom_ssl_port(self):
        custom_port = 8443
        with self.settings(SSLIFY_PORT=custom_port):
            request = self.factory.get('/woot/')
            middleware = SSLifyMiddleware()
            request = middleware.process_request(request)

            self.assertEqual(custom_port, urlsplit(request['Location']).port)
예제 #4
0
    def test_custom_ssl_port(self):
        custom_port = 8443
        with self.settings(SSLIFY_PORT=custom_port):
            request = self.factory.get('/woot/')
            middleware = SSLifyMiddleware()
            request = middleware.process_request(request)

            self.assertEqual(custom_port, urlsplit(request['Location']).port)
예제 #5
0
    def test_perma_redirects_http_to_https(self):
        request = self.factory.get('/woot/')
        self.assertTrue(request.build_absolute_uri().startswith('http://'))

        middleware = SSLifyMiddleware()
        result = middleware.process_request(request)

        self.assert_https_redirect(result)
        self.assertEqual(443, urlsplit(result['Location']).port)
예제 #6
0
    def test_perma_redirects_http_to_https(self):
        request = self.factory.get('/woot/')
        self.assertTrue(request.build_absolute_uri().startswith('http://'))

        middleware = SSLifyMiddleware()
        result = middleware.process_request(request)

        self.assert_https_redirect(result)
        self.assertEqual(443, urlsplit(result['Location']).port)