Пример #1
0
    def test_jwt_get_jwt_raw_no_token(self, live_testapp):
        """Should run get_jwt_raw and throw an error."""
        with mock.patch('flask.request.headers.get', return_value='Bearer'):
            with pytest.raises(AuthError) as error:
                get_jwt_raw()

            value = error.value
            assert value.code == 401
            assert value.content == {
                'code': 'invalid_header',
                'description': 'Token not found.'
            }
Пример #2
0
    def test_jwt_get_jwt_raw_empty(self, live_testapp):
        """Should run get_jwt_raw and get raw token."""
        with mock.patch('flask.request.headers.get', return_value=None):
            with pytest.raises(AuthError) as error:
                get_jwt_raw()

            value = error.value
            assert value.code == 401
            assert value.content == {
                'code': 'authorization_header_missing',
                'description': 'Authorization header is expected.'
            }
Пример #3
0
    def test_jwt_get_jwt_raw_extra_stuff(self, live_testapp):
        """Should run get_jwt_raw and throw an error."""
        with mock.patch('flask.request.headers.get',
                        return_value='Bearer token.here.and stuff'):
            with pytest.raises(AuthError) as error:
                get_jwt_raw()

            value = error.value
            assert value.code == 401
            assert value.content == {
                'code': 'invalid_header',
                'description': 'Authorization header must be Bearer token.'
            }
Пример #4
0
    def test_jwt_get_jwt_raw_no_bearer(self, live_testapp):
        """Should run get_jwt_raw and throw an error."""
        with mock.patch('flask.request.headers.get',
                        return_value='Yolo to.ke.n'):
            with pytest.raises(AuthError) as error:
                get_jwt_raw()

            value = error.value
            assert value.code == 401
            assert value.content == {
                'code': 'invalid_header',
                'description': 'Authorization header must start with Bearer.'
            }
Пример #5
0
 def test_jwt_get_jwt_raw(self, live_testapp):
     """Should run get_jwt_raw and return the token."""
     with mock.patch('flask.request.headers.get',
                     return_value='Bearer Blah'):
         token = get_jwt_raw()
         assert token == 'Blah'