authentik.sources.oauth.tests.test_type_wechat
WeChat Type tests
1"""WeChat Type tests""" 2 3from django.test import RequestFactory, TestCase 4 5from authentik.sources.oauth.models import OAuthSource 6from authentik.sources.oauth.types.wechat import WeChatType 7 8WECHAT_USER = { 9 "openid": "OPENID", 10 "nickname": "NICKNAME", 11 "sex": 1, 12 "province": "PROVINCE", 13 "city": "CITY", 14 "country": "COUNTRY", 15 "headimgurl": "https://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0", 16 "privilege": ["PRIVILEGE1", "PRIVILEGE2"], 17 "unionid": " o6_buyCrymLUUFYHxvDU6M2PHl22", 18} 19 20 21class TestTypeWeChat(TestCase): 22 """OAuth Source tests""" 23 24 def setUp(self): 25 self.source = OAuthSource.objects.create( 26 name="test", 27 slug="test", 28 provider_type="wechat", 29 ) 30 self.factory = RequestFactory() 31 32 def test_enroll_context(self): 33 """Test WeChat Enrollment context""" 34 ak_context = WeChatType().get_base_user_properties( 35 source=self.source, info=WECHAT_USER, client=None, token={} 36 ) 37 self.assertEqual(ak_context["username"], WECHAT_USER["unionid"]) 38 self.assertIsNone(ak_context["email"]) 39 self.assertEqual(ak_context["name"], WECHAT_USER["nickname"]) 40 self.assertEqual(ak_context["attributes"]["openid"], WECHAT_USER["openid"]) 41 self.assertEqual(ak_context["attributes"]["unionid"], WECHAT_USER["unionid"]) 42 43 def test_enroll_context_no_unionid(self): 44 """Test WeChat Enrollment context without unionid""" 45 user = WECHAT_USER.copy() 46 del user["unionid"] 47 ak_context = WeChatType().get_base_user_properties( 48 source=self.source, info=user, client=None, token={} 49 ) 50 self.assertEqual(ak_context["username"], WECHAT_USER["openid"]) 51 self.assertIsNone(ak_context["email"]) 52 self.assertEqual(ak_context["name"], WECHAT_USER["nickname"])
WECHAT_USER =
{'openid': 'OPENID', 'nickname': 'NICKNAME', 'sex': 1, 'province': 'PROVINCE', 'city': 'CITY', 'country': 'COUNTRY', 'headimgurl': 'https://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0', 'privilege': ['PRIVILEGE1', 'PRIVILEGE2'], 'unionid': ' o6_buyCrymLUUFYHxvDU6M2PHl22'}
class
TestTypeWeChat(django.test.testcases.TestCase):
22class TestTypeWeChat(TestCase): 23 """OAuth Source tests""" 24 25 def setUp(self): 26 self.source = OAuthSource.objects.create( 27 name="test", 28 slug="test", 29 provider_type="wechat", 30 ) 31 self.factory = RequestFactory() 32 33 def test_enroll_context(self): 34 """Test WeChat Enrollment context""" 35 ak_context = WeChatType().get_base_user_properties( 36 source=self.source, info=WECHAT_USER, client=None, token={} 37 ) 38 self.assertEqual(ak_context["username"], WECHAT_USER["unionid"]) 39 self.assertIsNone(ak_context["email"]) 40 self.assertEqual(ak_context["name"], WECHAT_USER["nickname"]) 41 self.assertEqual(ak_context["attributes"]["openid"], WECHAT_USER["openid"]) 42 self.assertEqual(ak_context["attributes"]["unionid"], WECHAT_USER["unionid"]) 43 44 def test_enroll_context_no_unionid(self): 45 """Test WeChat Enrollment context without unionid""" 46 user = WECHAT_USER.copy() 47 del user["unionid"] 48 ak_context = WeChatType().get_base_user_properties( 49 source=self.source, info=user, client=None, token={} 50 ) 51 self.assertEqual(ak_context["username"], WECHAT_USER["openid"]) 52 self.assertIsNone(ak_context["email"]) 53 self.assertEqual(ak_context["name"], WECHAT_USER["nickname"])
OAuth Source tests
def
setUp(self):
25 def setUp(self): 26 self.source = OAuthSource.objects.create( 27 name="test", 28 slug="test", 29 provider_type="wechat", 30 ) 31 self.factory = RequestFactory()
Hook method for setting up the test fixture before exercising it.
def
test_enroll_context(self):
33 def test_enroll_context(self): 34 """Test WeChat Enrollment context""" 35 ak_context = WeChatType().get_base_user_properties( 36 source=self.source, info=WECHAT_USER, client=None, token={} 37 ) 38 self.assertEqual(ak_context["username"], WECHAT_USER["unionid"]) 39 self.assertIsNone(ak_context["email"]) 40 self.assertEqual(ak_context["name"], WECHAT_USER["nickname"]) 41 self.assertEqual(ak_context["attributes"]["openid"], WECHAT_USER["openid"]) 42 self.assertEqual(ak_context["attributes"]["unionid"], WECHAT_USER["unionid"])
Test WeChat Enrollment context
def
test_enroll_context_no_unionid(self):
44 def test_enroll_context_no_unionid(self): 45 """Test WeChat Enrollment context without unionid""" 46 user = WECHAT_USER.copy() 47 del user["unionid"] 48 ak_context = WeChatType().get_base_user_properties( 49 source=self.source, info=user, client=None, token={} 50 ) 51 self.assertEqual(ak_context["username"], WECHAT_USER["openid"]) 52 self.assertIsNone(ak_context["email"]) 53 self.assertEqual(ak_context["name"], WECHAT_USER["nickname"])
Test WeChat Enrollment context without unionid