From d9eb4c5248d24077ce26de80dbe20a5ce8493f93 Mon Sep 17 00:00:00 2001 From: Jens L Date: Fri, 12 Jan 2024 16:20:29 +0100 Subject: [PATCH] sources/oauth: fix OAuth source type serializer (#8140) * sources/oauth: fix OAuth source type serializer Signed-off-by: Jens Langhammer * format Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- authentik/sources/oauth/api/source.py | 2 +- authentik/sources/oauth/tests/test_views.py | 18 ++++++++++++++++-- schema.yml | 4 ++-- web/src/admin/sources/oauth/OAuthSourceForm.ts | 6 +++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/authentik/sources/oauth/api/source.py b/authentik/sources/oauth/api/source.py index 08b676de5..a67dc1802 100644 --- a/authentik/sources/oauth/api/source.py +++ b/authentik/sources/oauth/api/source.py @@ -24,7 +24,7 @@ class SourceTypeSerializer(PassiveSerializer): """Serializer for SourceType""" name = CharField(required=True) - slug = CharField(required=True) + verbose_name = CharField(required=True) urls_customizable = BooleanField() request_token_url = CharField(read_only=True, allow_null=True) authorization_url = CharField(read_only=True, allow_null=True) diff --git a/authentik/sources/oauth/tests/test_views.py b/authentik/sources/oauth/tests/test_views.py index 16e57c057..46f0584d3 100644 --- a/authentik/sources/oauth/tests/test_views.py +++ b/authentik/sources/oauth/tests/test_views.py @@ -1,13 +1,14 @@ """OAuth Source tests""" -from django.test import TestCase from django.urls import reverse from requests_mock import Mocker +from rest_framework.test import APITestCase +from authentik.core.tests.utils import create_test_admin_user from authentik.sources.oauth.api.source import OAuthSourceSerializer from authentik.sources.oauth.models import OAuthSource -class TestOAuthSource(TestCase): +class TestOAuthSource(APITestCase): """OAuth Source tests""" def setUp(self): @@ -20,6 +21,19 @@ class TestOAuthSource(TestCase): consumer_key="", ) + def test_api_read(self): + """Test reading a source""" + self.client.force_login(create_test_admin_user()) + response = self.client.get( + reverse( + "authentik_api:oauthsource-detail", + kwargs={ + "slug": self.source.slug, + }, + ) + ) + self.assertEqual(response.status_code, 200) + def test_api_validate(self): """Test API validation""" self.assertTrue( diff --git a/schema.yml b/schema.yml index ef149443f..85dd0e5f5 100644 --- a/schema.yml +++ b/schema.yml @@ -42368,7 +42368,7 @@ components: properties: name: type: string - slug: + verbose_name: type: string urls_customizable: type: boolean @@ -42404,8 +42404,8 @@ components: - oidc_well_known_url - profile_url - request_token_url - - slug - urls_customizable + - verbose_name SpBindingEnum: enum: - redirect diff --git a/web/src/admin/sources/oauth/OAuthSourceForm.ts b/web/src/admin/sources/oauth/OAuthSourceForm.ts index 92763bf7b..bb5124d09 100644 --- a/web/src/admin/sources/oauth/OAuthSourceForm.ts +++ b/web/src/admin/sources/oauth/OAuthSourceForm.ts @@ -64,7 +64,7 @@ export class OAuthSourceForm extends WithCapabilitiesConfig(BaseSourceForm { - data.providerType = (this.providerType?.slug || "") as ProviderTypeEnum; + data.providerType = (this.providerType?.name || "") as ProviderTypeEnum; let source: OAuthSource; if (this.instance) { source = await new SourcesApi(DEFAULT_CONFIG).sourcesOauthPartialUpdate({ @@ -178,7 +178,7 @@ export class OAuthSourceForm extends WithCapabilitiesConfig(BaseSourceForm ` : html``} - ${this.providerType.slug === ProviderTypeEnum.Openidconnect || + ${this.providerType.name === ProviderTypeEnum.Openidconnect || this.providerType.oidcWellKnownUrl !== "" ? html` ` : html``} - ${this.providerType.slug === ProviderTypeEnum.Openidconnect || + ${this.providerType.name === ProviderTypeEnum.Openidconnect || this.providerType.oidcJwksUrl !== "" ? html`