authentik.sources.oauth.tests.test_type_twitch

Twitch Type tests

 1"""Twitch Type tests"""
 2
 3from django.test import TestCase
 4
 5from authentik.sources.oauth.models import OAuthSource
 6from authentik.sources.oauth.types.twitch import TwitchType
 7
 8# https://dev.twitch.tv/docs/authentication/getting-tokens-oidc/#getting-claims-information-from-an-access-token
 9TWITCH_USER = {
10    "aud": "ym2tq9o71tikh2zyebksiture1hzg5",
11    "exp": 1665261184,
12    "iat": 1665260184,
13    "iss": "https://id.twitch.tv/oauth2",
14    "sub": "603916897",
15    "email": "foo@bar.baz",
16    "preferred_username": "FooBar",
17}
18
19
20class TestTypeTwitch(TestCase):
21    """OAuth Source tests"""
22
23    def setUp(self):
24        self.source = OAuthSource.objects.create(
25            name="test",
26            slug="test",
27            provider_type="twitch",
28            authorization_url="",
29            profile_url="",
30            consumer_key="",
31        )
32
33    def test_enroll_context(self):
34        """Test twitch Enrollment context"""
35        ak_context = TwitchType().get_base_user_properties(source=self.source, info=TWITCH_USER)
36        self.assertEqual(ak_context["username"], TWITCH_USER["preferred_username"])
37        self.assertEqual(ak_context["email"], TWITCH_USER["email"])
38        self.assertEqual(ak_context["name"], TWITCH_USER["preferred_username"])
TWITCH_USER = {'aud': 'ym2tq9o71tikh2zyebksiture1hzg5', 'exp': 1665261184, 'iat': 1665260184, 'iss': 'https://id.twitch.tv/oauth2', 'sub': '603916897', 'email': 'foo@bar.baz', 'preferred_username': 'FooBar'}
class TestTypeTwitch(django.test.testcases.TestCase):
21class TestTypeTwitch(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="twitch",
29            authorization_url="",
30            profile_url="",
31            consumer_key="",
32        )
33
34    def test_enroll_context(self):
35        """Test twitch Enrollment context"""
36        ak_context = TwitchType().get_base_user_properties(source=self.source, info=TWITCH_USER)
37        self.assertEqual(ak_context["username"], TWITCH_USER["preferred_username"])
38        self.assertEqual(ak_context["email"], TWITCH_USER["email"])
39        self.assertEqual(ak_context["name"], TWITCH_USER["preferred_username"])

OAuth Source tests

def setUp(self):
24    def setUp(self):
25        self.source = OAuthSource.objects.create(
26            name="test",
27            slug="test",
28            provider_type="twitch",
29            authorization_url="",
30            profile_url="",
31            consumer_key="",
32        )

Hook method for setting up the test fixture before exercising it.

def test_enroll_context(self):
34    def test_enroll_context(self):
35        """Test twitch Enrollment context"""
36        ak_context = TwitchType().get_base_user_properties(source=self.source, info=TWITCH_USER)
37        self.assertEqual(ak_context["username"], TWITCH_USER["preferred_username"])
38        self.assertEqual(ak_context["email"], TWITCH_USER["email"])
39        self.assertEqual(ak_context["name"], TWITCH_USER["preferred_username"])

Test twitch Enrollment context