Skip to content
Merged
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
29 changes: 14 additions & 15 deletions libs/labelbox/tests/integration/test_api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,22 @@ def test_create_api_key_invalid_time_unit(client):

@pytest.mark.skipif(
condition=os.environ["LABELBOX_TEST_ENVIRON"] == "prod",
reason="Accounts with sdmin permission can create API keys",
reason="Accounts with admin permission can create API keys",
)
def test_create_api_key_insufficient_permissions(client):
"""Test that creating an API key fails when the user has insufficient permissions."""
user_email = client.get_user().email

assert client.get_user().org_role().name == "Admin"

# Attempt to create another API key using the limited permissions client
# This should fail due to insufficient permissions
with pytest.raises(LabelboxError) as excinfo:
client.create_api_key(
name=f"Test Key {uuid.uuid4()}",
user=user_email,
role="Admin",
validity=5,
time_unit=TimeUnit.MINUTE,
)

assert "192" in str(excinfo.value)
if client.get_user().org_role().name != "Admin":
# Attempt to create another API key using the limited permissions client
# This should fail due to insufficient permissions
with pytest.raises(LabelboxError) as excinfo:
client.create_api_key(
name=f"Test Key {uuid.uuid4()}",
user=user_email,
role="Admin",
validity=5,
time_unit=TimeUnit.MINUTE,
)

assert "192" in str(excinfo.value)
Loading