mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
from sentry.models.userpermission import UserPermission
|
|
from sentry.testutils.cases import APITestCase
|
|
from sentry.testutils.helpers.features import with_feature
|
|
from sentry.testutils.silo import control_silo_test
|
|
|
|
|
|
@control_silo_test
|
|
class UserListTest(APITestCase):
|
|
endpoint = "sentry-api-0-user-index"
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.superuser = self.create_user("[email protected]", is_superuser=True)
|
|
self.normal_user = self.create_user("[email protected]", is_superuser=False)
|
|
|
|
self.login_as(user=self.superuser, superuser=True)
|
|
|
|
def test_normal_user_fails(self):
|
|
self.login_as(self.normal_user)
|
|
self.get_error_response(status_code=403)
|
|
|
|
@with_feature("auth:enterprise-staff-cookie")
|
|
def test_staff_simple(self):
|
|
self.staff_user = self.create_user(is_staff=True)
|
|
self.login_as(self.staff_user, staff=True)
|
|
|
|
response = self.get_success_response()
|
|
assert len(response.data) == 3
|
|
|
|
def test_superuser_simple(self):
|
|
response = self.get_success_response()
|
|
assert len(response.data) == 2
|
|
|
|
def test_generic_query(self):
|
|
response = self.get_success_response(qs_params={"query": "@example.com"})
|
|
assert len(response.data) == 2
|
|
|
|
response = self.get_success_response(qs_params={"query": "bar"})
|
|
assert len(response.data) == 1
|
|
assert response.data[0]["id"] == str(self.superuser.id)
|
|
|
|
response = self.get_success_response(qs_params={"query": "foobar"})
|
|
assert len(response.data) == 0
|
|
|
|
def test_superuser_query(self):
|
|
response = self.get_success_response(qs_params={"query": "is:superuser"})
|
|
assert len(response.data) == 1
|
|
assert response.data[0]["id"] == str(self.superuser.id)
|
|
|
|
def test_email_query(self):
|
|
response = self.get_success_response(qs_params={"query": "email:[email protected]"})
|
|
assert len(response.data) == 1
|
|
assert response.data[0]["id"] == str(self.superuser.id)
|
|
|
|
response = self.get_success_response(qs_params={"query": "email:foobar"})
|
|
assert len(response.data) == 0
|
|
|
|
def test_basic_query(self):
|
|
UserPermission.objects.create(user=self.superuser, permission="broadcasts.admin")
|
|
|
|
response = self.get_success_response(qs_params={"query": "permission:broadcasts.admin"})
|
|
assert len(response.data) == 1
|
|
|
|
response = self.get_success_response(qs_params={"query": "permission:foobar"})
|
|
assert len(response.data) == 0
|