Ejemplo n.º 1
0
 def test_authenticate_token(self):
     """
     Test OAuth2 authentication with access token
     """
     request = self.factory.get("/a-resource", **self.auth_headers)
     backend = OAuth2Backend()
     credentials = {'request': request}
     u = backend.authenticate(**credentials)
     self.assertEqual(u, self.superuser)
    def test_authenticate(self):
        auth_headers = {
            'HTTP_AUTHORIZATION': 'Bearer ' + 'tokstr',
        }
        request = self.factory.get("/a-resource", **auth_headers)

        backend = OAuth2Backend()
        credentials = {'request': request}
        u = backend.authenticate(**credentials)
        self.assertEqual(u, self.user)
    def test_authenticate(self):
        auth_headers = {
            "HTTP_AUTHORIZATION": "Bearer " + "tokstr",
        }
        request = self.factory.get("/a-resource", **auth_headers)

        backend = OAuth2Backend()
        credentials = {"request": request}
        u = backend.authenticate(**credentials)
        self.assertEqual(u, self.user)
Ejemplo n.º 4
0
    def test_authenticate_raises_error_with_invalid_hex_in_query_params(self):
        auth_headers = {
            "HTTP_AUTHORIZATION": "Bearer " + "tokstr",
        }
        request = self.factory.get("/a-resource?auth_token=%%7A",
                                   **auth_headers)
        credentials = {"request": request}

        with pytest.raises(SuspiciousOperation):
            OAuth2Backend().authenticate(**credentials)
    def test_authenticate_fail(self):
        auth_headers = {
            'HTTP_AUTHORIZATION': 'Bearer ' + 'badstring',
        }
        request = self.factory.get("/a-resource", **auth_headers)

        backend = OAuth2Backend()
        credentials = {'request': request}
        self.assertIsNone(backend.authenticate(**credentials))

        credentials = {'username': '******', 'password': '******'}
        self.assertIsNone(backend.authenticate(**credentials))
    def test_authenticate_fail(self):
        auth_headers = {
            "HTTP_AUTHORIZATION": "Bearer " + "badstring",
        }
        request = self.factory.get("/a-resource", **auth_headers)

        backend = OAuth2Backend()
        credentials = {"request": request}
        self.assertIsNone(backend.authenticate(**credentials))

        credentials = {"username": "******", "password": "******"}
        self.assertIsNone(backend.authenticate(**credentials))
 def test_get_user(self):
     backend = OAuth2Backend()
     self.assertEqual(self.user, backend.get_user(self.user.pk))
     self.assertIsNone(backend.get_user(123456))
Ejemplo n.º 8
0
    def test_value_errors_are_reraised(self, patched_verify_request):
        patched_verify_request.side_effect = ValueError("Generic error")

        with pytest.raises(ValueError):
            OAuth2Backend().authenticate(request={})