authentik.brands.tests

Test brands

  1"""Test brands"""
  2
  3from json import loads
  4
  5from django.urls import reverse
  6from rest_framework.test import APITestCase
  7
  8from authentik.blueprints.tests import apply_blueprint
  9from authentik.brands.models import Brand
 10from authentik.core.models import Application
 11from authentik.core.tests.utils import create_test_admin_user, create_test_brand
 12from authentik.lib.generators import generate_id
 13from authentik.providers.oauth2.models import OAuth2Provider
 14from authentik.providers.saml.models import SAMLProvider
 15from authentik.tenants.flags import Flag
 16
 17
 18class TestBrands(APITestCase):
 19    """Test brands"""
 20
 21    def setUp(self):
 22        super().setUp()
 23        self.default_flags = {}
 24        for flag in Flag.available(visibility="public"):
 25            self.default_flags[flag().key] = flag.get()
 26        Brand.objects.all().delete()
 27
 28    def test_current_brand(self):
 29        """Test Current brand API"""
 30        brand = create_test_brand()
 31        self.assertJSONEqual(
 32            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
 33            {
 34                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
 35                "branding_logo_themed_urls": None,
 36                "branding_favicon": "/static/dist/assets/icons/icon.png",
 37                "branding_favicon_themed_urls": None,
 38                "branding_title": "authentik",
 39                "branding_custom_css": "",
 40                "matched_domain": brand.domain,
 41                "ui_footer_links": [],
 42                "ui_theme": "automatic",
 43                "default_locale": "",
 44                "flags": self.default_flags,
 45            },
 46        )
 47
 48    def test_brand_subdomain(self):
 49        """Test Current brand API"""
 50        Brand.objects.create(domain="bar.baz", branding_title="custom")
 51        self.assertJSONEqual(
 52            self.client.get(
 53                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
 54            ).content.decode(),
 55            {
 56                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
 57                "branding_logo_themed_urls": None,
 58                "branding_favicon": "/static/dist/assets/icons/icon.png",
 59                "branding_favicon_themed_urls": None,
 60                "branding_title": "custom",
 61                "branding_custom_css": "",
 62                "matched_domain": "bar.baz",
 63                "ui_footer_links": [],
 64                "ui_theme": "automatic",
 65                "default_locale": "",
 66                "flags": self.default_flags,
 67            },
 68        )
 69
 70    def test_fallback(self):
 71        """Test fallback brand"""
 72        self.assertJSONEqual(
 73            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
 74            {
 75                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
 76                "branding_logo_themed_urls": None,
 77                "branding_favicon": "/static/dist/assets/icons/icon.png",
 78                "branding_favicon_themed_urls": None,
 79                "branding_title": "authentik",
 80                "branding_custom_css": "",
 81                "matched_domain": "fallback",
 82                "ui_footer_links": [],
 83                "ui_theme": "automatic",
 84                "default_locale": "",
 85                "flags": self.default_flags,
 86            },
 87        )
 88
 89    @apply_blueprint("default/default-brand.yaml")
 90    def test_blueprint(self):
 91        """Test Current brand API"""
 92        response = loads(self.client.get(reverse("authentik_api:brand-current")).content.decode())
 93        response.pop("flow_authentication", None)
 94        response.pop("flow_invalidation", None)
 95        response.pop("flow_user_settings", None)
 96        self.assertEqual(
 97            response,
 98            {
 99                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
100                "branding_logo_themed_urls": None,
101                "branding_favicon": "/static/dist/assets/icons/icon.png",
102                "branding_favicon_themed_urls": None,
103                "branding_title": "authentik",
104                "branding_custom_css": "",
105                "matched_domain": "authentik-default",
106                "ui_footer_links": [],
107                "ui_theme": "automatic",
108                "default_locale": "",
109                "flags": self.default_flags,
110            },
111        )
112
113    @apply_blueprint("default/default-brand.yaml")
114    def test_blueprint_with_other_brand(self):
115        """Test Current brand API"""
116        Brand.objects.create(domain="bar.baz", branding_title="custom")
117        response = loads(self.client.get(reverse("authentik_api:brand-current")).content.decode())
118        response.pop("flow_authentication", None)
119        response.pop("flow_invalidation", None)
120        response.pop("flow_user_settings", None)
121        self.assertEqual(
122            response,
123            {
124                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
125                "branding_logo_themed_urls": None,
126                "branding_favicon": "/static/dist/assets/icons/icon.png",
127                "branding_favicon_themed_urls": None,
128                "branding_title": "authentik",
129                "branding_custom_css": "",
130                "matched_domain": "authentik-default",
131                "ui_footer_links": [],
132                "ui_theme": "automatic",
133                "default_locale": "",
134                "flags": self.default_flags,
135            },
136        )
137        self.assertJSONEqual(
138            self.client.get(
139                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
140            ).content.decode(),
141            {
142                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
143                "branding_logo_themed_urls": None,
144                "branding_favicon": "/static/dist/assets/icons/icon.png",
145                "branding_favicon_themed_urls": None,
146                "branding_title": "custom",
147                "branding_custom_css": "",
148                "matched_domain": "bar.baz",
149                "ui_footer_links": [],
150                "ui_theme": "automatic",
151                "default_locale": "",
152                "flags": self.default_flags,
153            },
154        )
155
156    def test_brand_subdomain_same_suffix(self):
157        """Test Current brand API"""
158        Brand.objects.create(domain="bar.baz", branding_title="custom-weak")
159        Brand.objects.create(domain="foo.bar.baz", branding_title="custom-strong")
160        self.assertJSONEqual(
161            self.client.get(
162                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
163            ).content.decode(),
164            {
165                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
166                "branding_logo_themed_urls": None,
167                "branding_favicon": "/static/dist/assets/icons/icon.png",
168                "branding_favicon_themed_urls": None,
169                "branding_title": "custom-strong",
170                "branding_custom_css": "",
171                "matched_domain": "foo.bar.baz",
172                "ui_footer_links": [],
173                "ui_theme": "automatic",
174                "default_locale": "",
175                "flags": self.default_flags,
176            },
177        )
178
179    def test_brand_subdomain_other_suffix(self):
180        """Test Current brand API"""
181        Brand.objects.create(domain="bar.baz", branding_title="custom-weak")
182        Brand.objects.create(domain="foo.bar.baz", branding_title="custom-strong")
183        self.assertJSONEqual(
184            self.client.get(
185                reverse("authentik_api:brand-current"), HTTP_HOST="other.bar.baz"
186            ).content.decode(),
187            {
188                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
189                "branding_logo_themed_urls": None,
190                "branding_favicon": "/static/dist/assets/icons/icon.png",
191                "branding_favicon_themed_urls": None,
192                "branding_title": "custom-weak",
193                "branding_custom_css": "",
194                "matched_domain": "bar.baz",
195                "ui_footer_links": [],
196                "ui_theme": "automatic",
197                "default_locale": "",
198                "flags": self.default_flags,
199            },
200        )
201
202    def test_create_default_multiple(self):
203        """Test attempted creation of multiple default brands"""
204        Brand.objects.create(
205            domain="foo",
206            default=True,
207            branding_title="custom",
208        )
209        user = create_test_admin_user()
210        self.client.force_login(user)
211        response = self.client.post(
212            reverse("authentik_api:brand-list"), data={"domain": "bar", "default": True}
213        )
214        self.assertEqual(response.status_code, 400)
215
216    def test_webfinger_no_app(self):
217        """Test Webfinger"""
218        create_test_brand()
219        self.assertJSONEqual(
220            self.client.get(reverse("authentik_brands:webfinger")).content.decode(), {}
221        )
222
223    def test_webfinger_not_supported(self):
224        """Test Webfinger"""
225        brand = create_test_brand()
226        provider = SAMLProvider.objects.create(
227            name=generate_id(),
228        )
229        app = Application.objects.create(name=generate_id(), slug=generate_id(), provider=provider)
230        brand.default_application = app
231        brand.save()
232        self.assertJSONEqual(
233            self.client.get(reverse("authentik_brands:webfinger")).content.decode(), {}
234        )
235
236    def test_webfinger_oidc(self):
237        """Test Webfinger"""
238        brand = create_test_brand()
239        provider = OAuth2Provider.objects.create(
240            name=generate_id(),
241        )
242        app = Application.objects.create(name=generate_id(), slug=generate_id(), provider=provider)
243        brand.default_application = app
244        brand.save()
245        self.assertJSONEqual(
246            self.client.get(reverse("authentik_brands:webfinger")).content.decode(),
247            {
248                "links": [
249                    {
250                        "href": f"http://testserver/application/o/{app.slug}/",
251                        "rel": "http://openid.net/specs/connect/1.0/issuer",
252                    }
253                ],
254                "subject": None,
255            },
256        )
257
258    def test_branding_url(self):
259        """Test branding attributes return correct values"""
260        brand = create_test_brand()
261        brand.branding_default_flow_background = "https://goauthentik.io/img/icon.png"
262        brand.branding_favicon = "https://goauthentik.io/img/icon.png"
263        brand.branding_logo = "https://goauthentik.io/img/icon.png"
264        brand.save()
265        self.assertEqual(
266            brand.branding_default_flow_background_url(), "https://goauthentik.io/img/icon.png"
267        )
268        self.assertJSONEqual(
269            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
270            {
271                "branding_logo": "https://goauthentik.io/img/icon.png",
272                "branding_logo_themed_urls": None,
273                "branding_favicon": "https://goauthentik.io/img/icon.png",
274                "branding_favicon_themed_urls": None,
275                "branding_title": "authentik",
276                "branding_custom_css": "",
277                "matched_domain": brand.domain,
278                "ui_footer_links": [],
279                "ui_theme": "automatic",
280                "default_locale": "",
281                "flags": self.default_flags,
282            },
283        )
284
285    def test_custom_css(self):
286        """Test custom_css"""
287        brand = create_test_brand()
288        brand.branding_custom_css = """* {
289            font-family: "Foo bar";
290        }"""
291        brand.save()
292        res = self.client.get(reverse("authentik_core:if-user"))
293        self.assertEqual(res.status_code, 200)
294        self.assertIn(brand.branding_custom_css, res.content.decode())
class TestBrands(rest_framework.test.APITestCase):
 19class TestBrands(APITestCase):
 20    """Test brands"""
 21
 22    def setUp(self):
 23        super().setUp()
 24        self.default_flags = {}
 25        for flag in Flag.available(visibility="public"):
 26            self.default_flags[flag().key] = flag.get()
 27        Brand.objects.all().delete()
 28
 29    def test_current_brand(self):
 30        """Test Current brand API"""
 31        brand = create_test_brand()
 32        self.assertJSONEqual(
 33            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
 34            {
 35                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
 36                "branding_logo_themed_urls": None,
 37                "branding_favicon": "/static/dist/assets/icons/icon.png",
 38                "branding_favicon_themed_urls": None,
 39                "branding_title": "authentik",
 40                "branding_custom_css": "",
 41                "matched_domain": brand.domain,
 42                "ui_footer_links": [],
 43                "ui_theme": "automatic",
 44                "default_locale": "",
 45                "flags": self.default_flags,
 46            },
 47        )
 48
 49    def test_brand_subdomain(self):
 50        """Test Current brand API"""
 51        Brand.objects.create(domain="bar.baz", branding_title="custom")
 52        self.assertJSONEqual(
 53            self.client.get(
 54                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
 55            ).content.decode(),
 56            {
 57                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
 58                "branding_logo_themed_urls": None,
 59                "branding_favicon": "/static/dist/assets/icons/icon.png",
 60                "branding_favicon_themed_urls": None,
 61                "branding_title": "custom",
 62                "branding_custom_css": "",
 63                "matched_domain": "bar.baz",
 64                "ui_footer_links": [],
 65                "ui_theme": "automatic",
 66                "default_locale": "",
 67                "flags": self.default_flags,
 68            },
 69        )
 70
 71    def test_fallback(self):
 72        """Test fallback brand"""
 73        self.assertJSONEqual(
 74            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
 75            {
 76                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
 77                "branding_logo_themed_urls": None,
 78                "branding_favicon": "/static/dist/assets/icons/icon.png",
 79                "branding_favicon_themed_urls": None,
 80                "branding_title": "authentik",
 81                "branding_custom_css": "",
 82                "matched_domain": "fallback",
 83                "ui_footer_links": [],
 84                "ui_theme": "automatic",
 85                "default_locale": "",
 86                "flags": self.default_flags,
 87            },
 88        )
 89
 90    @apply_blueprint("default/default-brand.yaml")
 91    def test_blueprint(self):
 92        """Test Current brand API"""
 93        response = loads(self.client.get(reverse("authentik_api:brand-current")).content.decode())
 94        response.pop("flow_authentication", None)
 95        response.pop("flow_invalidation", None)
 96        response.pop("flow_user_settings", None)
 97        self.assertEqual(
 98            response,
 99            {
100                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
101                "branding_logo_themed_urls": None,
102                "branding_favicon": "/static/dist/assets/icons/icon.png",
103                "branding_favicon_themed_urls": None,
104                "branding_title": "authentik",
105                "branding_custom_css": "",
106                "matched_domain": "authentik-default",
107                "ui_footer_links": [],
108                "ui_theme": "automatic",
109                "default_locale": "",
110                "flags": self.default_flags,
111            },
112        )
113
114    @apply_blueprint("default/default-brand.yaml")
115    def test_blueprint_with_other_brand(self):
116        """Test Current brand API"""
117        Brand.objects.create(domain="bar.baz", branding_title="custom")
118        response = loads(self.client.get(reverse("authentik_api:brand-current")).content.decode())
119        response.pop("flow_authentication", None)
120        response.pop("flow_invalidation", None)
121        response.pop("flow_user_settings", None)
122        self.assertEqual(
123            response,
124            {
125                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
126                "branding_logo_themed_urls": None,
127                "branding_favicon": "/static/dist/assets/icons/icon.png",
128                "branding_favicon_themed_urls": None,
129                "branding_title": "authentik",
130                "branding_custom_css": "",
131                "matched_domain": "authentik-default",
132                "ui_footer_links": [],
133                "ui_theme": "automatic",
134                "default_locale": "",
135                "flags": self.default_flags,
136            },
137        )
138        self.assertJSONEqual(
139            self.client.get(
140                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
141            ).content.decode(),
142            {
143                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
144                "branding_logo_themed_urls": None,
145                "branding_favicon": "/static/dist/assets/icons/icon.png",
146                "branding_favicon_themed_urls": None,
147                "branding_title": "custom",
148                "branding_custom_css": "",
149                "matched_domain": "bar.baz",
150                "ui_footer_links": [],
151                "ui_theme": "automatic",
152                "default_locale": "",
153                "flags": self.default_flags,
154            },
155        )
156
157    def test_brand_subdomain_same_suffix(self):
158        """Test Current brand API"""
159        Brand.objects.create(domain="bar.baz", branding_title="custom-weak")
160        Brand.objects.create(domain="foo.bar.baz", branding_title="custom-strong")
161        self.assertJSONEqual(
162            self.client.get(
163                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
164            ).content.decode(),
165            {
166                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
167                "branding_logo_themed_urls": None,
168                "branding_favicon": "/static/dist/assets/icons/icon.png",
169                "branding_favicon_themed_urls": None,
170                "branding_title": "custom-strong",
171                "branding_custom_css": "",
172                "matched_domain": "foo.bar.baz",
173                "ui_footer_links": [],
174                "ui_theme": "automatic",
175                "default_locale": "",
176                "flags": self.default_flags,
177            },
178        )
179
180    def test_brand_subdomain_other_suffix(self):
181        """Test Current brand API"""
182        Brand.objects.create(domain="bar.baz", branding_title="custom-weak")
183        Brand.objects.create(domain="foo.bar.baz", branding_title="custom-strong")
184        self.assertJSONEqual(
185            self.client.get(
186                reverse("authentik_api:brand-current"), HTTP_HOST="other.bar.baz"
187            ).content.decode(),
188            {
189                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
190                "branding_logo_themed_urls": None,
191                "branding_favicon": "/static/dist/assets/icons/icon.png",
192                "branding_favicon_themed_urls": None,
193                "branding_title": "custom-weak",
194                "branding_custom_css": "",
195                "matched_domain": "bar.baz",
196                "ui_footer_links": [],
197                "ui_theme": "automatic",
198                "default_locale": "",
199                "flags": self.default_flags,
200            },
201        )
202
203    def test_create_default_multiple(self):
204        """Test attempted creation of multiple default brands"""
205        Brand.objects.create(
206            domain="foo",
207            default=True,
208            branding_title="custom",
209        )
210        user = create_test_admin_user()
211        self.client.force_login(user)
212        response = self.client.post(
213            reverse("authentik_api:brand-list"), data={"domain": "bar", "default": True}
214        )
215        self.assertEqual(response.status_code, 400)
216
217    def test_webfinger_no_app(self):
218        """Test Webfinger"""
219        create_test_brand()
220        self.assertJSONEqual(
221            self.client.get(reverse("authentik_brands:webfinger")).content.decode(), {}
222        )
223
224    def test_webfinger_not_supported(self):
225        """Test Webfinger"""
226        brand = create_test_brand()
227        provider = SAMLProvider.objects.create(
228            name=generate_id(),
229        )
230        app = Application.objects.create(name=generate_id(), slug=generate_id(), provider=provider)
231        brand.default_application = app
232        brand.save()
233        self.assertJSONEqual(
234            self.client.get(reverse("authentik_brands:webfinger")).content.decode(), {}
235        )
236
237    def test_webfinger_oidc(self):
238        """Test Webfinger"""
239        brand = create_test_brand()
240        provider = OAuth2Provider.objects.create(
241            name=generate_id(),
242        )
243        app = Application.objects.create(name=generate_id(), slug=generate_id(), provider=provider)
244        brand.default_application = app
245        brand.save()
246        self.assertJSONEqual(
247            self.client.get(reverse("authentik_brands:webfinger")).content.decode(),
248            {
249                "links": [
250                    {
251                        "href": f"http://testserver/application/o/{app.slug}/",
252                        "rel": "http://openid.net/specs/connect/1.0/issuer",
253                    }
254                ],
255                "subject": None,
256            },
257        )
258
259    def test_branding_url(self):
260        """Test branding attributes return correct values"""
261        brand = create_test_brand()
262        brand.branding_default_flow_background = "https://goauthentik.io/img/icon.png"
263        brand.branding_favicon = "https://goauthentik.io/img/icon.png"
264        brand.branding_logo = "https://goauthentik.io/img/icon.png"
265        brand.save()
266        self.assertEqual(
267            brand.branding_default_flow_background_url(), "https://goauthentik.io/img/icon.png"
268        )
269        self.assertJSONEqual(
270            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
271            {
272                "branding_logo": "https://goauthentik.io/img/icon.png",
273                "branding_logo_themed_urls": None,
274                "branding_favicon": "https://goauthentik.io/img/icon.png",
275                "branding_favicon_themed_urls": None,
276                "branding_title": "authentik",
277                "branding_custom_css": "",
278                "matched_domain": brand.domain,
279                "ui_footer_links": [],
280                "ui_theme": "automatic",
281                "default_locale": "",
282                "flags": self.default_flags,
283            },
284        )
285
286    def test_custom_css(self):
287        """Test custom_css"""
288        brand = create_test_brand()
289        brand.branding_custom_css = """* {
290            font-family: "Foo bar";
291        }"""
292        brand.save()
293        res = self.client.get(reverse("authentik_core:if-user"))
294        self.assertEqual(res.status_code, 200)
295        self.assertIn(brand.branding_custom_css, res.content.decode())

Test brands

def setUp(self):
22    def setUp(self):
23        super().setUp()
24        self.default_flags = {}
25        for flag in Flag.available(visibility="public"):
26            self.default_flags[flag().key] = flag.get()
27        Brand.objects.all().delete()

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

def test_current_brand(self):
29    def test_current_brand(self):
30        """Test Current brand API"""
31        brand = create_test_brand()
32        self.assertJSONEqual(
33            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
34            {
35                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
36                "branding_logo_themed_urls": None,
37                "branding_favicon": "/static/dist/assets/icons/icon.png",
38                "branding_favicon_themed_urls": None,
39                "branding_title": "authentik",
40                "branding_custom_css": "",
41                "matched_domain": brand.domain,
42                "ui_footer_links": [],
43                "ui_theme": "automatic",
44                "default_locale": "",
45                "flags": self.default_flags,
46            },
47        )

Test Current brand API

def test_brand_subdomain(self):
49    def test_brand_subdomain(self):
50        """Test Current brand API"""
51        Brand.objects.create(domain="bar.baz", branding_title="custom")
52        self.assertJSONEqual(
53            self.client.get(
54                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
55            ).content.decode(),
56            {
57                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
58                "branding_logo_themed_urls": None,
59                "branding_favicon": "/static/dist/assets/icons/icon.png",
60                "branding_favicon_themed_urls": None,
61                "branding_title": "custom",
62                "branding_custom_css": "",
63                "matched_domain": "bar.baz",
64                "ui_footer_links": [],
65                "ui_theme": "automatic",
66                "default_locale": "",
67                "flags": self.default_flags,
68            },
69        )

Test Current brand API

def test_fallback(self):
71    def test_fallback(self):
72        """Test fallback brand"""
73        self.assertJSONEqual(
74            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
75            {
76                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
77                "branding_logo_themed_urls": None,
78                "branding_favicon": "/static/dist/assets/icons/icon.png",
79                "branding_favicon_themed_urls": None,
80                "branding_title": "authentik",
81                "branding_custom_css": "",
82                "matched_domain": "fallback",
83                "ui_footer_links": [],
84                "ui_theme": "automatic",
85                "default_locale": "",
86                "flags": self.default_flags,
87            },
88        )

Test fallback brand

@apply_blueprint('default/default-brand.yaml')
def test_blueprint(self):
 90    @apply_blueprint("default/default-brand.yaml")
 91    def test_blueprint(self):
 92        """Test Current brand API"""
 93        response = loads(self.client.get(reverse("authentik_api:brand-current")).content.decode())
 94        response.pop("flow_authentication", None)
 95        response.pop("flow_invalidation", None)
 96        response.pop("flow_user_settings", None)
 97        self.assertEqual(
 98            response,
 99            {
100                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
101                "branding_logo_themed_urls": None,
102                "branding_favicon": "/static/dist/assets/icons/icon.png",
103                "branding_favicon_themed_urls": None,
104                "branding_title": "authentik",
105                "branding_custom_css": "",
106                "matched_domain": "authentik-default",
107                "ui_footer_links": [],
108                "ui_theme": "automatic",
109                "default_locale": "",
110                "flags": self.default_flags,
111            },
112        )

Test Current brand API

@apply_blueprint('default/default-brand.yaml')
def test_blueprint_with_other_brand(self):
114    @apply_blueprint("default/default-brand.yaml")
115    def test_blueprint_with_other_brand(self):
116        """Test Current brand API"""
117        Brand.objects.create(domain="bar.baz", branding_title="custom")
118        response = loads(self.client.get(reverse("authentik_api:brand-current")).content.decode())
119        response.pop("flow_authentication", None)
120        response.pop("flow_invalidation", None)
121        response.pop("flow_user_settings", None)
122        self.assertEqual(
123            response,
124            {
125                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
126                "branding_logo_themed_urls": None,
127                "branding_favicon": "/static/dist/assets/icons/icon.png",
128                "branding_favicon_themed_urls": None,
129                "branding_title": "authentik",
130                "branding_custom_css": "",
131                "matched_domain": "authentik-default",
132                "ui_footer_links": [],
133                "ui_theme": "automatic",
134                "default_locale": "",
135                "flags": self.default_flags,
136            },
137        )
138        self.assertJSONEqual(
139            self.client.get(
140                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
141            ).content.decode(),
142            {
143                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
144                "branding_logo_themed_urls": None,
145                "branding_favicon": "/static/dist/assets/icons/icon.png",
146                "branding_favicon_themed_urls": None,
147                "branding_title": "custom",
148                "branding_custom_css": "",
149                "matched_domain": "bar.baz",
150                "ui_footer_links": [],
151                "ui_theme": "automatic",
152                "default_locale": "",
153                "flags": self.default_flags,
154            },
155        )

Test Current brand API

def test_brand_subdomain_same_suffix(self):
157    def test_brand_subdomain_same_suffix(self):
158        """Test Current brand API"""
159        Brand.objects.create(domain="bar.baz", branding_title="custom-weak")
160        Brand.objects.create(domain="foo.bar.baz", branding_title="custom-strong")
161        self.assertJSONEqual(
162            self.client.get(
163                reverse("authentik_api:brand-current"), HTTP_HOST="foo.bar.baz"
164            ).content.decode(),
165            {
166                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
167                "branding_logo_themed_urls": None,
168                "branding_favicon": "/static/dist/assets/icons/icon.png",
169                "branding_favicon_themed_urls": None,
170                "branding_title": "custom-strong",
171                "branding_custom_css": "",
172                "matched_domain": "foo.bar.baz",
173                "ui_footer_links": [],
174                "ui_theme": "automatic",
175                "default_locale": "",
176                "flags": self.default_flags,
177            },
178        )

Test Current brand API

def test_brand_subdomain_other_suffix(self):
180    def test_brand_subdomain_other_suffix(self):
181        """Test Current brand API"""
182        Brand.objects.create(domain="bar.baz", branding_title="custom-weak")
183        Brand.objects.create(domain="foo.bar.baz", branding_title="custom-strong")
184        self.assertJSONEqual(
185            self.client.get(
186                reverse("authentik_api:brand-current"), HTTP_HOST="other.bar.baz"
187            ).content.decode(),
188            {
189                "branding_logo": "/static/dist/assets/icons/icon_left_brand.svg",
190                "branding_logo_themed_urls": None,
191                "branding_favicon": "/static/dist/assets/icons/icon.png",
192                "branding_favicon_themed_urls": None,
193                "branding_title": "custom-weak",
194                "branding_custom_css": "",
195                "matched_domain": "bar.baz",
196                "ui_footer_links": [],
197                "ui_theme": "automatic",
198                "default_locale": "",
199                "flags": self.default_flags,
200            },
201        )

Test Current brand API

def test_create_default_multiple(self):
203    def test_create_default_multiple(self):
204        """Test attempted creation of multiple default brands"""
205        Brand.objects.create(
206            domain="foo",
207            default=True,
208            branding_title="custom",
209        )
210        user = create_test_admin_user()
211        self.client.force_login(user)
212        response = self.client.post(
213            reverse("authentik_api:brand-list"), data={"domain": "bar", "default": True}
214        )
215        self.assertEqual(response.status_code, 400)

Test attempted creation of multiple default brands

def test_webfinger_no_app(self):
217    def test_webfinger_no_app(self):
218        """Test Webfinger"""
219        create_test_brand()
220        self.assertJSONEqual(
221            self.client.get(reverse("authentik_brands:webfinger")).content.decode(), {}
222        )

Test Webfinger

def test_webfinger_not_supported(self):
224    def test_webfinger_not_supported(self):
225        """Test Webfinger"""
226        brand = create_test_brand()
227        provider = SAMLProvider.objects.create(
228            name=generate_id(),
229        )
230        app = Application.objects.create(name=generate_id(), slug=generate_id(), provider=provider)
231        brand.default_application = app
232        brand.save()
233        self.assertJSONEqual(
234            self.client.get(reverse("authentik_brands:webfinger")).content.decode(), {}
235        )

Test Webfinger

def test_webfinger_oidc(self):
237    def test_webfinger_oidc(self):
238        """Test Webfinger"""
239        brand = create_test_brand()
240        provider = OAuth2Provider.objects.create(
241            name=generate_id(),
242        )
243        app = Application.objects.create(name=generate_id(), slug=generate_id(), provider=provider)
244        brand.default_application = app
245        brand.save()
246        self.assertJSONEqual(
247            self.client.get(reverse("authentik_brands:webfinger")).content.decode(),
248            {
249                "links": [
250                    {
251                        "href": f"http://testserver/application/o/{app.slug}/",
252                        "rel": "http://openid.net/specs/connect/1.0/issuer",
253                    }
254                ],
255                "subject": None,
256            },
257        )

Test Webfinger

def test_branding_url(self):
259    def test_branding_url(self):
260        """Test branding attributes return correct values"""
261        brand = create_test_brand()
262        brand.branding_default_flow_background = "https://goauthentik.io/img/icon.png"
263        brand.branding_favicon = "https://goauthentik.io/img/icon.png"
264        brand.branding_logo = "https://goauthentik.io/img/icon.png"
265        brand.save()
266        self.assertEqual(
267            brand.branding_default_flow_background_url(), "https://goauthentik.io/img/icon.png"
268        )
269        self.assertJSONEqual(
270            self.client.get(reverse("authentik_api:brand-current")).content.decode(),
271            {
272                "branding_logo": "https://goauthentik.io/img/icon.png",
273                "branding_logo_themed_urls": None,
274                "branding_favicon": "https://goauthentik.io/img/icon.png",
275                "branding_favicon_themed_urls": None,
276                "branding_title": "authentik",
277                "branding_custom_css": "",
278                "matched_domain": brand.domain,
279                "ui_footer_links": [],
280                "ui_theme": "automatic",
281                "default_locale": "",
282                "flags": self.default_flags,
283            },
284        )

Test branding attributes return correct values

def test_custom_css(self):
286    def test_custom_css(self):
287        """Test custom_css"""
288        brand = create_test_brand()
289        brand.branding_custom_css = """* {
290            font-family: "Foo bar";
291        }"""
292        brand.save()
293        res = self.client.get(reverse("authentik_core:if-user"))
294        self.assertEqual(res.status_code, 200)
295        self.assertIn(brand.branding_custom_css, res.content.decode())

Test custom_css