Esempio n. 1
0
    def test_no_apikey(self, api):
        '''Should raise a HTTP 401 if no API Key is provided'''
        response = api.post(url_for('api.fake'))

        assert401(response)
        assert response.content_type == 'application/json'
        assert 'message' in response.json
Esempio n. 2
0
    def test_invalid_apikey(self, api):
        '''Should raise a HTTP 401 if an invalid API Key is provided'''
        response = api.post(url_for('api.fake'), headers={'X-API-KEY': 'fake'})

        assert401(response)
        assert response.content_type == 'application/json'
        assert 'message' in response.json
Esempio n. 3
0
    def test_invalid_apikey(self, api):
        '''Should raise a HTTP 401 if an invalid API Key is provided'''
        response = api.post(url_for('api.fake'), headers={'X-API-KEY': 'fake'})

        assert401(response)
        assert response.content_type == 'application/json'
        assert 'message' in response.json
Esempio n. 4
0
    def test_no_apikey(self, api):
        '''Should raise a HTTP 401 if no API Key is provided'''
        response = api.post(url_for('api.fake'))

        assert401(response)
        assert response.content_type == 'application/json'
        assert 'message' in response.json
Esempio n. 5
0
    def test_inactive_user(self, api):
        '''Should raise a HTTP 401 if the user is inactive'''
        user = UserFactory(active=False)
        with api.user(user) as user:
            response = api.post(url_for('api.fake'),
                                headers={'X-API-KEY': user.apikey})

        assert401(response)
        assert response.content_type == 'application/json'
        assert 'message' in response.json
Esempio n. 6
0
    def test_inactive_user(self, api):
        '''Should raise a HTTP 401 if the user is inactive'''
        user = UserFactory(active=False)
        with api.user(user) as user:
            response = api.post(url_for('api.fake'),
                                headers={'X-API-KEY': user.apikey})

        assert401(response)
        assert response.content_type == 'application/json'
        assert 'message' in response.json
Esempio n. 7
0
    def test_bad_oauth_auth(self, api, oauth):
        '''Should handle wrong OAuth header authentication'''
        user = UserFactory()
        OAuth2Token.objects.create(
            client=oauth,
            user=user,
            access_token='access-token',
            refresh_token='refresh-token',
        )

        response = api.post(url_for('api.fake'), headers={
            'Authorization': ' '.join(['Bearer', 'not-my-token'])
        })

        assert401(response)
        assert response.content_type == 'application/json'
Esempio n. 8
0
    def test_bad_oauth_auth(self, api, oauth):
        '''Should handle wrong OAuth header authentication'''
        user = UserFactory()
        OAuth2Token.objects.create(
            client=oauth,
            user=user,
            access_token='access-token',
            refresh_token='refresh-token',
        )

        response = api.post(url_for('api.fake'), headers={
            'Authorization': ' '.join(['Bearer', 'not-my-token'])
        })

        assert401(response)
        assert response.content_type == 'application/json'