|
@@ -1,6 +1,8 @@
|
|
|
+from sentry.hybridcloud.models import ApiKeyReplica
|
|
|
from sentry.models import ApiKey
|
|
|
+from sentry.silo import SiloMode
|
|
|
from sentry.testutils.cases import APITestCase
|
|
|
-from sentry.testutils.silo import control_silo_test
|
|
|
+from sentry.testutils.silo import assume_test_silo_mode, control_silo_test
|
|
|
|
|
|
DEFAULT_SCOPES = ["project:read", "event:read", "team:read", "org:read", "member:read"]
|
|
|
|
|
@@ -31,13 +33,38 @@ class OrganizationApiKeyDetailsPut(OrganizationApiKeyDetailsBase):
|
|
|
method = "put"
|
|
|
|
|
|
def test_update_api_key_details(self):
|
|
|
- data = {"label": "New Label", "allowed_origins": "sentry.io"}
|
|
|
+ data = {
|
|
|
+ "label": "New Label",
|
|
|
+ "allowed_origins": "sentry.io",
|
|
|
+ "scope_list": ["a", "b", "c", "d"],
|
|
|
+ }
|
|
|
self.get_success_response(self.organization.slug, self.api_key.id, **data)
|
|
|
|
|
|
api_key = ApiKey.objects.get(id=self.api_key.id, organization_id=self.organization.id)
|
|
|
|
|
|
assert api_key.label == "New Label"
|
|
|
assert api_key.allowed_origins == "sentry.io"
|
|
|
+ assert api_key.get_scopes() == ["a", "b", "c", "d"]
|
|
|
+
|
|
|
+ def test_update_api_key_details_legacy_data(self):
|
|
|
+ # Some old api keys have this psql special format string
|
|
|
+ self.api_key.scope_list = "{event:read,member:read,org:read,project:read,team:read}"
|
|
|
+ self.api_key.save()
|
|
|
+
|
|
|
+ with assume_test_silo_mode(SiloMode.REGION):
|
|
|
+ assert ApiKeyReplica.objects.get(apikey_id=self.api_key.id).get_scopes() == [
|
|
|
+ "event:read",
|
|
|
+ "member:read",
|
|
|
+ "org:read",
|
|
|
+ "project:read",
|
|
|
+ "team:read",
|
|
|
+ ]
|
|
|
+
|
|
|
+ data = {"scope_list": ["a", "b", "c", "d"]}
|
|
|
+ self.get_success_response(self.organization.slug, self.api_key.id, **data)
|
|
|
+
|
|
|
+ api_key = ApiKey.objects.get(id=self.api_key.id, organization_id=self.organization.id)
|
|
|
+ assert api_key.get_scopes() == ["a", "b", "c", "d"]
|
|
|
|
|
|
|
|
|
@control_silo_test(stable=True)
|