Exemplo n.º 1
0
    def test_custom_authorization_header(self):
        headers = {
            'HTTP_AUTHORIZATION_TOKEN': 'JWT token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertEqual(header, 'token')
Exemplo n.º 2
0
    def test_custom_authorization_header(self):
        headers = {
            'HTTP_AUTHORIZATION_TOKEN': 'JWT token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertEqual(header, 'token')
Exemplo n.º 3
0
    def test_invalid_authorization_header_prefix(self):
        headers = {
            'HTTP_AUTHORIZATION': 'INVALID token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertIsNone(header)
Exemplo n.º 4
0
    def test_invalid_authorization_header_prefix(self):
        headers = {
            'HTTP_AUTHORIZATION': 'INVALID token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertIsNone(header)
Exemplo n.º 5
0
    def test_invalid_header_prefix(self):
        headers = {
            jwt_settings.JWT_AUTH_HEADER_NAME: 'INVALID token',
        }

        request = self.request_factory.get('/', **headers)
        authorization_header = utils.get_authorization_header(request)

        self.assertIsNone(authorization_header)
Exemplo n.º 6
0
    def test_get_header(self):
        headers = {
            jwt_settings.JWT_AUTH_HEADER_NAME:
            '{} {}'.format(jwt_settings.JWT_AUTH_HEADER_PREFIX, self.token),
        }

        request = self.request_factory.get('/', **headers)
        authorization_header = utils.get_authorization_header(request)

        self.assertEqual(authorization_header, self.token)
Exemplo n.º 7
0
    def test_custom_authorization_header(self):
        headers = {
            'HTTP_AUTHORIZATION_TOKEN': '{} token'.format(
                jwt_settings.JWT_AUTH_HEADER_PREFIX),
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertEqual(header, 'token')
Exemplo n.º 8
0
    def authenticate(self, request= None, **credentials):
        if request is None:
            return None

        token = get_authorization_header(request)

        if token is not None:
            return User.find_by_token(token)

        return None