| |
@@ -4722,6 +4722,65 @@
|
| |
self.assertEqual(output.status_code, 401)
|
| |
|
| |
|
| |
+ class PagureFlaskApiProjectVerifyAPITokenTests(tests.Modeltests):
|
| |
+ """Tests for the flask API of pagure for verifying project API token validity"""
|
| |
+
|
| |
+ maxDiff = None
|
| |
+
|
| |
+ def setUp(self):
|
| |
+ """Set up the environnment, ran before every tests."""
|
| |
+ super(PagureFlaskApiProjectVerifyAPITokenTests, self).setUp()
|
| |
+ tests.create_projects(self.session)
|
| |
+ tests.create_tokens(self.session, project_id=None)
|
| |
+ tests.create_tokens_acl(self.session, "aaabbbcccddd", "modify_project")
|
| |
+
|
| |
+ def test_api_verifyapitoken_valid(self):
|
| |
+ """Test accessing api_project_verify_api_token with valid token."""
|
| |
+
|
| |
+ headers = {"Authorization": "token aaabbbcccddd"}
|
| |
+
|
| |
+ output = self.app.post("/api/0/test/token/verify", headers=headers)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.get_data(as_text=True))
|
| |
+ self.assertEqual(data, {"message": "Token is valid"})
|
| |
+
|
| |
+ def test_api_verifyapitoken_not_valid(self):
|
| |
+ """Test accessing api_project_verify_api_token with invalid token."""
|
| |
+
|
| |
+ headers = {"Authorization": "token dddcccbbbaaa"}
|
| |
+
|
| |
+ output = self.app.post("/api/0/test/token/verify", headers=headers)
|
| |
+ self.assertEqual(output.status_code, 401)
|
| |
+ data = json.loads(output.get_data(as_text=True))
|
| |
+ self.assertDictEqual(
|
| |
+ data,
|
| |
+ {
|
| |
+ "error": "Invalid or expired token. Please visit "
|
| |
+ "http://localhost.localdomain/settings#nav-api-tab to get or renew "
|
| |
+ "your API token.",
|
| |
+ "error_code": "EINVALIDTOK",
|
| |
+ "errors": "Invalid token",
|
| |
+ },
|
| |
+ )
|
| |
+
|
| |
+ def test_api_verifyapitoken_no_headers(self):
|
| |
+ """Test accessing api_project_verify_api_token without passing headers."""
|
| |
+
|
| |
+ output = self.app.post("/api/0/test/token/verify")
|
| |
+ self.assertEqual(output.status_code, 401)
|
| |
+ data = json.loads(output.get_data(as_text=True))
|
| |
+ self.assertDictEqual(
|
| |
+ data,
|
| |
+ {
|
| |
+ "error": "Invalid or expired token. Please visit "
|
| |
+ "http://localhost.localdomain/settings#nav-api-tab to get or renew "
|
| |
+ "your API token.",
|
| |
+ "error_code": "EINVALIDTOK",
|
| |
+ "errors": "Invalid token",
|
| |
+ },
|
| |
+ )
|
| |
+
|
| |
+
|
| |
class PagureFlaskApiProjectConnectorTests(tests.Modeltests):
|
| |
"""Tests for the flask API of pagure for getting connector of a project"""
|
| |
|
| |
Add a simple endpoint which verify token validity for the specified project. Return 200 if token is valid or 401 if expired/invalid. See #5420
Signed-off-by: Mattia Verga mattia.verga@tiscali.it