-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(flags): limit scopes for secret updates (#82897)
closes getsentry/team-replay#522 changes the secret endpoint permissions so that only managers & owners can update a secret (anyone can post) -- only exception is the original creator of the secret can always update their secret, regardless of their scope.
- Loading branch information
1 parent
a279f1d
commit 32ef888
Showing
2 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,96 @@ def test_post_other_organization(self): | |
response = self.client.post(url, data={}) | ||
assert response.status_code == 403, response.content | ||
|
||
def test_update_same_creator(self): | ||
new_user = self.create_user("[email protected]") | ||
member = self.create_member(organization=self.organization, user=new_user) | ||
self.login_as(user=member) | ||
|
||
with self.feature(self.features): | ||
response = self.client.post( | ||
self.url, | ||
data={"secret": "41271af8b9804cd99a4c787a28274991", "provider": "generic"}, | ||
) | ||
assert response.status_code == 201, response.content | ||
|
||
models = FlagWebHookSigningSecretModel.objects.filter(provider="generic").all() | ||
assert len(models) == 1 | ||
assert models[0].secret == "41271af8b9804cd99a4c787a28274991" | ||
|
||
# update secret should be allowed since the creator is the same | ||
with self.feature(self.features): | ||
response = self.client.post( | ||
self.url, | ||
data={"secret": "31271af8b9804cd99a4c787a28274993", "provider": "generic"}, | ||
) | ||
assert response.status_code == 201, response.content | ||
|
||
models = FlagWebHookSigningSecretModel.objects.filter(provider="generic").all() | ||
assert len(models) == 1 | ||
assert models[0].secret == "31271af8b9804cd99a4c787a28274993" | ||
|
||
def test_update_no_access(self): | ||
FlagWebHookSigningSecretModel.objects.create( | ||
created_by="12314124", | ||
organization=self.organization, | ||
provider="generic", | ||
secret="41271af8b9804cd99a4c787a28274991", | ||
) | ||
|
||
models = FlagWebHookSigningSecretModel.objects.filter(provider="generic").all() | ||
assert len(models) == 1 | ||
assert models[0].secret == "41271af8b9804cd99a4c787a28274991" | ||
|
||
# update secret should not allowed since the creator is not the same | ||
new_user = self.create_user("[email protected]") | ||
member = self.create_member(organization=self.organization, user=new_user) | ||
self.login_as(user=member) | ||
with self.feature(self.features): | ||
response = self.client.post( | ||
self.url, | ||
data={"secret": "31271af8b9804cd99a4c787a28274993", "provider": "generic"}, | ||
) | ||
assert response.status_code == 403, response.content | ||
assert ( | ||
response.data | ||
== "You must be an organization owner or manager, or the creator of this secret in order to perform this action." | ||
) | ||
|
||
models = FlagWebHookSigningSecretModel.objects.filter(provider="generic").all() | ||
assert len(models) == 1 | ||
assert models[0].secret == "41271af8b9804cd99a4c787a28274991" | ||
|
||
def test_update_has_scope(self): | ||
FlagWebHookSigningSecretModel.objects.create( | ||
created_by="12314124", | ||
organization=self.organization, | ||
provider="generic", | ||
secret="41271af8b9804cd99a4c787a28274991", | ||
) | ||
|
||
models = FlagWebHookSigningSecretModel.objects.filter(provider="generic").all() | ||
assert len(models) == 1 | ||
assert models[0].secret == "41271af8b9804cd99a4c787a28274991" | ||
|
||
# update secret should be allowed due to proper scope | ||
new_user = self.create_user("[email protected]") | ||
owner = self.create_member( | ||
organization=self.organization, | ||
user=new_user, | ||
role="owner", | ||
) | ||
self.login_as(user=owner) | ||
with self.feature(self.features): | ||
response = self.client.post( | ||
self.url, | ||
data={"secret": "31271af8b9804cd99a4c787a28274993", "provider": "generic"}, | ||
) | ||
assert response.status_code == 201, response.content | ||
|
||
models = FlagWebHookSigningSecretModel.objects.filter(provider="generic").all() | ||
assert len(models) == 1 | ||
assert models[0].secret == "31271af8b9804cd99a4c787a28274993" | ||
|
||
|
||
class OrganizationFlagsWebHookSigningSecretEndpointTestCase(APITestCase): | ||
endpoint = "sentry-api-0-organization-flag-hooks-signing-secret" | ||
|