authentik.stages.authenticator_static.tests
Test Static API
1"""Test Static API""" 2 3from django.urls import reverse 4from rest_framework.test import APITestCase 5 6from authentik.core.models import User 7from authentik.core.tests.utils import create_test_admin_user 8from authentik.lib.generators import generate_id 9from authentik.stages.authenticator.tests import TestCase, ThrottlingTestMixin 10from authentik.stages.authenticator_static.models import StaticDevice 11 12 13class AuthenticatorStaticStageTests(APITestCase): 14 """Test Static API""" 15 16 def test_api_delete(self): 17 """Test api delete""" 18 user = User.objects.create(username="foo") 19 self.client.force_login(user) 20 dev = StaticDevice.objects.create(user=user) 21 response = self.client.delete( 22 reverse("authentik_api:staticdevice-detail", kwargs={"pk": dev.pk}) 23 ) 24 self.assertEqual(response.status_code, 204) 25 26 27class DeviceTest(TestCase): 28 """A few generic tests to get us started.""" 29 30 def setUp(self): 31 self.user = create_test_admin_user("alice") 32 33 def test_str(self): 34 """Test __str__ of model""" 35 device = StaticDevice.objects.create(user=self.user, name="Device") 36 37 str(device) 38 39 def test_str_unpopulated(self): 40 """Test __str__ of model""" 41 device = StaticDevice() 42 43 str(device) 44 45 46class ThrottlingTestCase(ThrottlingTestMixin, TestCase): 47 """Test static device throttling""" 48 49 def setUp(self): 50 user = create_test_admin_user("alice") 51 self.device = user.staticdevice_set.create() 52 self.device.token_set.create(token=generate_id(length=16)) 53 self.device.token_set.create(token=generate_id(length=16)) 54 self.device.token_set.create(token=generate_id(length=16)) 55 56 def valid_token(self): 57 return self.device.token_set.first().token 58 59 def invalid_token(self): 60 return "bogus"
class
AuthenticatorStaticStageTests(rest_framework.test.APITestCase):
14class AuthenticatorStaticStageTests(APITestCase): 15 """Test Static API""" 16 17 def test_api_delete(self): 18 """Test api delete""" 19 user = User.objects.create(username="foo") 20 self.client.force_login(user) 21 dev = StaticDevice.objects.create(user=user) 22 response = self.client.delete( 23 reverse("authentik_api:staticdevice-detail", kwargs={"pk": dev.pk}) 24 ) 25 self.assertEqual(response.status_code, 204)
Test Static API
def
test_api_delete(self):
17 def test_api_delete(self): 18 """Test api delete""" 19 user = User.objects.create(username="foo") 20 self.client.force_login(user) 21 dev = StaticDevice.objects.create(user=user) 22 response = self.client.delete( 23 reverse("authentik_api:staticdevice-detail", kwargs={"pk": dev.pk}) 24 ) 25 self.assertEqual(response.status_code, 204)
Test api delete
class
DeviceTest(django.test.testcases.TestCase):
28class DeviceTest(TestCase): 29 """A few generic tests to get us started.""" 30 31 def setUp(self): 32 self.user = create_test_admin_user("alice") 33 34 def test_str(self): 35 """Test __str__ of model""" 36 device = StaticDevice.objects.create(user=self.user, name="Device") 37 38 str(device) 39 40 def test_str_unpopulated(self): 41 """Test __str__ of model""" 42 device = StaticDevice() 43 44 str(device)
A few generic tests to get us started.
class
ThrottlingTestCase(authentik.stages.authenticator.tests.ThrottlingTestMixin, django.test.testcases.TestCase):
47class ThrottlingTestCase(ThrottlingTestMixin, TestCase): 48 """Test static device throttling""" 49 50 def setUp(self): 51 user = create_test_admin_user("alice") 52 self.device = user.staticdevice_set.create() 53 self.device.token_set.create(token=generate_id(length=16)) 54 self.device.token_set.create(token=generate_id(length=16)) 55 self.device.token_set.create(token=generate_id(length=16)) 56 57 def valid_token(self): 58 return self.device.token_set.first().token 59 60 def invalid_token(self): 61 return "bogus"
Test static device throttling
def
setUp(self):
50 def setUp(self): 51 user = create_test_admin_user("alice") 52 self.device = user.staticdevice_set.create() 53 self.device.token_set.create(token=generate_id(length=16)) 54 self.device.token_set.create(token=generate_id(length=16)) 55 self.device.token_set.create(token=generate_id(length=16))
Hook method for setting up the test fixture before exercising it.