diff --git a/tests/test_progit_flask_api_auth.py b/tests/test_progit_flask_api_auth.py index d72415d..0132d07 100644 --- a/tests/test_progit_flask_api_auth.py +++ b/tests/test_progit_flask_api_auth.py @@ -102,6 +102,38 @@ class PagureFlaskApiAuthtests(tests.Modeltests): } ) + def test_auth_expired(self): + """ Test the authentication when the token has expired. + """ + tests.create_projects(self.session) + tests.create_tokens(self.session) + + output = self.app.post('/api/0/test/new_issue') + self.assertEqual(output.status_code, 401) + data = json.loads(output.data) + self.assertDictEqual( + data, + { + "error": "Invalid or expired token. Please visit " \ + "https://pagure.org/ get or renew your API token.", + "output": "notok" + } + ) + + headers = {'Authorization': 'token expired_token'} + + output = self.app.post('/api/0/test/new_issue', headers=headers) + self.assertEqual(output.status_code, 401) + data = json.loads(output.data) + self.assertDictEqual( + data, + { + "error": "Invalid or expired token. Please visit " \ + "https://pagure.org/ get or renew your API token.", + "output": "notok" + } + ) + def test_auth(self): """ Test the token based authentication. """