Exemplo n.º 1
0
    def test_respects_enabled_switch(self):
        def get_response(request):
            request.axes_locked_out = True
            return HttpResponse()

        response = AxesMiddleware(get_response)(self.request)
        self.assertEqual(response.status_code, self.STATUS_SUCCESS)
Exemplo n.º 2
0
    def test_lockout_response(self):
        def get_response(request):
            request.axes_locked_out = True
            return HttpResponse()

        response = AxesMiddleware(get_response)(self.request)
        self.assertEqual(response.status_code, self.STATUS_LOCKOUT)
Exemplo n.º 3
0
    def test_success_response(self):
        def get_response(request):
            request.axes_locked_out = False
            return HttpResponse()

        response = AxesMiddleware(get_response)(self.request)
        self.assertEqual(response.status_code, self.STATUS_SUCCESS)
Exemplo n.º 4
0
    def test_lockout_response_with_drf_integration(
        self, mock_get_failure_limit, mock_get_failures
    ):
        def get_response(request):
            return HttpResponse()

        response = AxesMiddleware(get_response)(self.request)
        self.assertTrue(hasattr(self.request, "axes_locked_out"))
        self.assertTrue(self.request.axes_locked_out)
        self.assertEqual(response.status_code, self.STATUS_LOCKOUT)
Exemplo n.º 5
0
    def test_response_does_not_contain_extra_attrs_without_drf_integration(
        self, ):
        def get_response(request):
            return HttpResponse()

        self.assertNotIn("rest_framework", settings.INSTALLED_APPS)

        AxesMiddleware(get_response)(self.request)

        self.assertFalse(hasattr(self.request, "axes_locked_out"))
        self.assertFalse(hasattr(self.request, "axes_attempt_time"))
        self.assertFalse(hasattr(self.request, "axes_ip_address"))
        self.assertFalse(hasattr(self.request, "axes_user_agent"))
        self.assertFalse(hasattr(self.request, "axes_path_info"))
        self.assertFalse(hasattr(self.request, "axes_http_accept"))
        self.assertFalse(hasattr(self.request, "axes_updated"))
Exemplo n.º 6
0
    def test_response_contains_required_attrs_with_drf_integration(self):
        def get_response(request):
            return HttpResponse()

        self.assertFalse(hasattr(self.request, "axes_locked_out"))
        self.assertFalse(hasattr(self.request, "axes_attempt_time"))
        self.assertFalse(hasattr(self.request, "axes_ip_address"))
        self.assertFalse(hasattr(self.request, "axes_user_agent"))
        self.assertFalse(hasattr(self.request, "axes_path_info"))
        self.assertFalse(hasattr(self.request, "axes_http_accept"))
        self.assertFalse(hasattr(self.request, "axes_updated"))

        AxesMiddleware(get_response)(self.request)

        self.assertTrue(hasattr(self.request, "axes_locked_out"))
        self.assertTrue(hasattr(self.request, "axes_attempt_time"))
        self.assertTrue(hasattr(self.request, "axes_ip_address"))
        self.assertTrue(hasattr(self.request, "axes_user_agent"))
        self.assertTrue(hasattr(self.request, "axes_path_info"))
        self.assertTrue(hasattr(self.request, "axes_http_accept"))
        self.assertTrue(hasattr(self.request, "axes_updated"))
Exemplo n.º 7
0
 def test_process_exception_other(self, _):
     exception = Exception()
     response = AxesMiddleware(self.get_response).process_exception(
         self.request, exception)
     self.assertEqual(response, None)
Exemplo n.º 8
0
 def test_process_exception_axes(self, _):
     exception = AxesSignalPermissionDenied()
     response = AxesMiddleware(self.get_response).process_exception(
         self.request, exception)
     self.assertEqual(response, self.LOCKOUT_RESPONSE)