core: fix filtering users by type attribute (#6638)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
parent
31904f28ad
commit
d29163e3ad
|
@ -309,7 +309,7 @@ class UsersFilter(FilterSet):
|
||||||
path = CharFilter(field_name="path")
|
path = CharFilter(field_name="path")
|
||||||
path_startswith = CharFilter(field_name="path", lookup_expr="startswith")
|
path_startswith = CharFilter(field_name="path", lookup_expr="startswith")
|
||||||
|
|
||||||
type = MultipleChoiceFilter(field_name="type")
|
type = MultipleChoiceFilter(choices=UserTypes.choices, field_name="type")
|
||||||
|
|
||||||
groups_by_name = ModelMultipleChoiceFilter(
|
groups_by_name = ModelMultipleChoiceFilter(
|
||||||
field_name="ak_groups__name",
|
field_name="ak_groups__name",
|
||||||
|
|
|
@ -28,6 +28,19 @@ class TestUsersAPI(APITestCase):
|
||||||
self.admin = create_test_admin_user()
|
self.admin = create_test_admin_user()
|
||||||
self.user = User.objects.create(username="test-user")
|
self.user = User.objects.create(username="test-user")
|
||||||
|
|
||||||
|
def test_filter_type(self):
|
||||||
|
"""Test API filtering by type"""
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
user = create_test_admin_user(type=UserTypes.EXTERNAL)
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:user-list"),
|
||||||
|
data={
|
||||||
|
"type": UserTypes.EXTERNAL,
|
||||||
|
"username": user.username,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_metrics(self):
|
def test_metrics(self):
|
||||||
"""Test user's metrics"""
|
"""Test user's metrics"""
|
||||||
self.client.force_login(self.admin)
|
self.client.force_login(self.admin)
|
||||||
|
|
|
@ -21,7 +21,7 @@ def create_test_flow(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_test_admin_user(name: Optional[str] = None) -> User:
|
def create_test_admin_user(name: Optional[str] = None, **kwargs) -> User:
|
||||||
"""Generate a test-admin user"""
|
"""Generate a test-admin user"""
|
||||||
uid = generate_id(20) if not name else name
|
uid = generate_id(20) if not name else name
|
||||||
group = Group.objects.create(name=uid, is_superuser=True)
|
group = Group.objects.create(name=uid, is_superuser=True)
|
||||||
|
@ -29,6 +29,7 @@ def create_test_admin_user(name: Optional[str] = None) -> User:
|
||||||
username=uid,
|
username=uid,
|
||||||
name=uid,
|
name=uid,
|
||||||
email=f"{uid}@goauthentik.io",
|
email=f"{uid}@goauthentik.io",
|
||||||
|
**kwargs,
|
||||||
)
|
)
|
||||||
user.set_password(uid)
|
user.set_password(uid)
|
||||||
user.save()
|
user.save()
|
||||||
|
@ -36,12 +37,12 @@ def create_test_admin_user(name: Optional[str] = None) -> User:
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def create_test_tenant() -> Tenant:
|
def create_test_tenant(**kwargs) -> Tenant:
|
||||||
"""Generate a test tenant, removing all other tenants to make sure this one
|
"""Generate a test tenant, removing all other tenants to make sure this one
|
||||||
matches."""
|
matches."""
|
||||||
uid = generate_id(20)
|
uid = generate_id(20)
|
||||||
Tenant.objects.all().delete()
|
Tenant.objects.all().delete()
|
||||||
return Tenant.objects.create(domain=uid, default=True)
|
return Tenant.objects.create(domain=uid, default=True, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def create_test_cert(use_ec_private_key=False) -> CertificateKeyPair:
|
def create_test_cert(use_ec_private_key=False) -> CertificateKeyPair:
|
||||||
|
|
Reference in New Issue