Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions infrabox/test/api/collaborators_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from temp_tools import TestClient
from test_template import ApiTestTemplate

Expand Down Expand Up @@ -64,3 +66,29 @@ def test_collaborators_delete(self):
SELECT count(*) FROM collaborator WHERE user_id = %s
""", [self.collaborator_id])
self.assertEqual(r[0], 0)

def test_administrator_cannot_promote_self_to_owner(self):
TestClient.execute("""
INSERT INTO "user" (id, github_id, username, avatar_url)
VALUES (%s, 2, %s, 'url1');
""", [self.collaborator_id,
self.test_collaborator_data['username']])
TestClient.execute("""
INSERT INTO collaborator (user_id, project_id, role)
VALUES (%s, %s, 'Administrator')
""", [self.collaborator_id, self.project_id])
TestClient.opa_push()

r = TestClient.app.put(
'api/v1/projects/%s/collaborators/%s' % (self.project_id, self.collaborator_id),
data=json.dumps({'role': 'Owner'}),
headers=TestClient.get_user_authorization(self.collaborator_id),
content_type='application/json')

self.assertEqual(r.status_code, 403)
self.assertEqual(json.loads(r.data)['message'], 'A project is limited to one owner.')
role = TestClient.execute_one("""
SELECT role FROM collaborator
WHERE user_id = %s AND project_id = %s
""", [self.collaborator_id, self.project_id])
self.assertEqual(role[0], 'Administrator')
3 changes: 3 additions & 0 deletions src/api/handlers/projects/collaborators.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def put(self, project_id, user_id):
if [userrole] not in roles:
abort(400, "Role unknown.")

if userrole == 'Owner':
abort(403, "A project is limited to one owner.")

# Do update
g.db.execute(
"""
Expand Down
Loading