|
@ -23,58 +23,69 @@ class ProjectTestCase(BaseTestCase): |
|
|
r = self.client.get(self.url) |
|
|
r = self.client.get(self.url) |
|
|
self.assertContains(r, "Change Project Name") |
|
|
self.assertContains(r, "Change Project Name") |
|
|
|
|
|
|
|
|
def test_it_shows_api_keys(self): |
|
|
|
|
|
|
|
|
def test_it_masks_keys_by_default(self): |
|
|
self.project.api_key_readonly = "R" * 32 |
|
|
self.project.api_key_readonly = "R" * 32 |
|
|
|
|
|
self.project.ping_key = "P" * 22 |
|
|
self.project.save() |
|
|
self.project.save() |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
|
|
|
|
|
form = {"show_api_keys": "1"} |
|
|
|
|
|
|
|
|
r = self.client.get(self.url) |
|
|
|
|
|
self.assertEqual(r.status_code, 200) |
|
|
|
|
|
|
|
|
|
|
|
self.assertNotContains(r, "X" * 32) |
|
|
|
|
|
self.assertNotContains(r, "R" * 32) |
|
|
|
|
|
self.assertNotContains(r, "P" * 22) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_shows_keys(self): |
|
|
|
|
|
self.project.api_key_readonly = "R" * 32 |
|
|
|
|
|
self.project.ping_key = "P" * 22 |
|
|
|
|
|
self.project.save() |
|
|
|
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
|
|
|
|
|
|
|
|
form = {"show_keys": "1"} |
|
|
r = self.client.post(self.url, form) |
|
|
r = self.client.post(self.url, form) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
|
|
|
|
|
|
self.assertContains(r, "X" * 32) |
|
|
self.assertContains(r, "X" * 32) |
|
|
self.assertContains(r, "R" * 32) |
|
|
self.assertContains(r, "R" * 32) |
|
|
|
|
|
self.assertContains(r, "P" * 22) |
|
|
self.assertContains(r, "Prometheus metrics endpoint") |
|
|
self.assertContains(r, "Prometheus metrics endpoint") |
|
|
|
|
|
|
|
|
def test_it_creates_api_key(self): |
|
|
|
|
|
|
|
|
def test_it_creates_readonly_key(self): |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
|
|
|
|
|
form = {"create_api_keys": "1"} |
|
|
|
|
|
|
|
|
form = {"create_key": "api_key_readonly"} |
|
|
r = self.client.post(self.url, form) |
|
|
r = self.client.post(self.url, form) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
|
|
|
|
|
|
self.project.refresh_from_db() |
|
|
self.project.refresh_from_db() |
|
|
api_key = self.project.api_key |
|
|
|
|
|
self.assertTrue(len(api_key) > 10) |
|
|
|
|
|
self.assertFalse("b'" in api_key) |
|
|
|
|
|
|
|
|
self.assertEqual(len(self.project.api_key_readonly), 32) |
|
|
|
|
|
self.assertFalse("b'" in self.project.api_key_readonly) |
|
|
|
|
|
|
|
|
def test_it_requires_rw_access_to_create_api_key(self): |
|
|
|
|
|
|
|
|
def test_it_requires_rw_access_to_create_key(self): |
|
|
self.bobs_membership.role = "r" |
|
|
self.bobs_membership.role = "r" |
|
|
self.bobs_membership.save() |
|
|
self.bobs_membership.save() |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(self.url, {"create_api_keys": "1"}) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, {"create_key": "api_key_readonly"}) |
|
|
self.assertEqual(r.status_code, 403) |
|
|
self.assertEqual(r.status_code, 403) |
|
|
|
|
|
|
|
|
def test_it_revokes_api_key(self): |
|
|
def test_it_revokes_api_key(self): |
|
|
self.project.api_key_readonly = "R" * 32 |
|
|
|
|
|
self.project.save() |
|
|
|
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(self.url, {"revoke_api_keys": "1"}) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, {"revoke_key": "api_key"}) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
|
|
|
|
|
|
self.project.refresh_from_db() |
|
|
self.project.refresh_from_db() |
|
|
self.assertEqual(self.project.api_key, "") |
|
|
self.assertEqual(self.project.api_key, "") |
|
|
self.assertEqual(self.project.api_key_readonly, "") |
|
|
|
|
|
|
|
|
|
|
|
def test_it_requires_rw_access_to_revoke_api_key(self): |
|
|
def test_it_requires_rw_access_to_revoke_api_key(self): |
|
|
self.bobs_membership.role = "r" |
|
|
self.bobs_membership.role = "r" |
|
|
self.bobs_membership.save() |
|
|
self.bobs_membership.save() |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(self.url, {"revoke_api_keys": "1"}) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, {"revoke_key": "api_key"}) |
|
|
self.assertEqual(r.status_code, 403) |
|
|
self.assertEqual(r.status_code, 403) |
|
|
|
|
|
|
|
|
def test_it_adds_team_member(self): |
|
|
def test_it_adds_team_member(self): |
|
@ -348,5 +359,5 @@ class ProjectTestCase(BaseTestCase): |
|
|
self.bobs_membership.save() |
|
|
self.bobs_membership.save() |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(self.url, {"show_api_keys": "1"}) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, {"show_keys": "1"}) |
|
|
self.assertEqual(r.status_code, 403) |
|
|
self.assertEqual(r.status_code, 403) |