authentik.sources.oauth.tests.test_type_entra_id
Entra ID Type tests
1"""Entra ID Type tests""" 2 3from django.test import TestCase 4 5from authentik.sources.oauth.models import OAuthSource 6from authentik.sources.oauth.types.entra_id import EntraIDOAuthCallback, EntraIDType 7 8# https://docs.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http#response-2 9EID_USER = { 10 "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", 11 "@odata.id": ( 12 "https://graph.microsoft.com/v2/7ce9b89e-646a-41d2-9fa6-8371c6a8423d/" 13 "directoryObjects/018b0aff-8aff-473e-bf9c-b50e27f52208/Microsoft.DirectoryServices.User" 14 ), 15 "businessPhones": [], 16 "displayName": "foo bar", 17 "givenName": "foo", 18 "jobTitle": None, 19 "mail": "foo@goauthentik.io", 20 "mobilePhone": None, 21 "officeLocation": None, 22 "preferredLanguage": None, 23 "surname": "bar", 24 "userPrincipalName": "foo@goauthentik.io", 25 "id": "018b0aff-8aff-473e-bf9c-b50e27f52208", 26} 27 28 29class TestTypeAzureAD(TestCase): 30 """OAuth Source tests""" 31 32 def setUp(self): 33 self.source = OAuthSource.objects.create( 34 name="test", 35 slug="test", 36 provider_type="openidconnect", 37 authorization_url="", 38 profile_url="", 39 consumer_key="", 40 ) 41 42 def test_enroll_context(self): 43 """Test azure_ad Enrollment context""" 44 ak_context = EntraIDType().get_base_user_properties(source=self.source, info=EID_USER) 45 self.assertEqual(ak_context["username"], EID_USER["userPrincipalName"]) 46 self.assertEqual(ak_context["email"], EID_USER["mail"]) 47 self.assertEqual(ak_context["name"], EID_USER["displayName"]) 48 49 def test_user_id(self): 50 """Test Entra ID user ID""" 51 self.assertEqual(EntraIDOAuthCallback().get_user_id(EID_USER), EID_USER["id"])
EID_USER =
{'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users/$entity', '@odata.id': 'https://graph.microsoft.com/v2/7ce9b89e-646a-41d2-9fa6-8371c6a8423d/directoryObjects/018b0aff-8aff-473e-bf9c-b50e27f52208/Microsoft.DirectoryServices.User', 'businessPhones': [], 'displayName': 'foo bar', 'givenName': 'foo', 'jobTitle': None, 'mail': 'foo@goauthentik.io', 'mobilePhone': None, 'officeLocation': None, 'preferredLanguage': None, 'surname': 'bar', 'userPrincipalName': 'foo@goauthentik.io', 'id': '018b0aff-8aff-473e-bf9c-b50e27f52208'}
class
TestTypeAzureAD(django.test.testcases.TestCase):
30class TestTypeAzureAD(TestCase): 31 """OAuth Source tests""" 32 33 def setUp(self): 34 self.source = OAuthSource.objects.create( 35 name="test", 36 slug="test", 37 provider_type="openidconnect", 38 authorization_url="", 39 profile_url="", 40 consumer_key="", 41 ) 42 43 def test_enroll_context(self): 44 """Test azure_ad Enrollment context""" 45 ak_context = EntraIDType().get_base_user_properties(source=self.source, info=EID_USER) 46 self.assertEqual(ak_context["username"], EID_USER["userPrincipalName"]) 47 self.assertEqual(ak_context["email"], EID_USER["mail"]) 48 self.assertEqual(ak_context["name"], EID_USER["displayName"]) 49 50 def test_user_id(self): 51 """Test Entra ID user ID""" 52 self.assertEqual(EntraIDOAuthCallback().get_user_id(EID_USER), EID_USER["id"])
OAuth Source tests
def
setUp(self):
33 def setUp(self): 34 self.source = OAuthSource.objects.create( 35 name="test", 36 slug="test", 37 provider_type="openidconnect", 38 authorization_url="", 39 profile_url="", 40 consumer_key="", 41 )
Hook method for setting up the test fixture before exercising it.
def
test_enroll_context(self):
43 def test_enroll_context(self): 44 """Test azure_ad Enrollment context""" 45 ak_context = EntraIDType().get_base_user_properties(source=self.source, info=EID_USER) 46 self.assertEqual(ak_context["username"], EID_USER["userPrincipalName"]) 47 self.assertEqual(ak_context["email"], EID_USER["mail"]) 48 self.assertEqual(ak_context["name"], EID_USER["displayName"])
Test azure_ad Enrollment context