providers/proxy: fix being able to set empty internal_host

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-09 00:07:34 +02:00
parent 5ac6a6910e
commit 5cad59a9f8
3 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,8 @@
"""ProxyProvider API Views"""
from typing import Any
from drf_yasg.utils import swagger_serializer_method
from rest_framework.exceptions import ValidationError
from rest_framework.fields import CharField, ListField, SerializerMethodField
from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
@ -30,6 +33,17 @@ class OpenIDConnectConfigurationSerializer(PassiveSerializer):
class ProxyProviderSerializer(ProviderSerializer):
"""ProxyProvider Serializer"""
def validate(self, attrs) -> dict[Any, str]:
"""Check that internal_host is set when forward_auth_mode is disabled"""
if (
not attrs.get("forward_auth_mode", False)
and attrs.get("internal_host", "") == ""
):
raise ValidationError(
"Internal host cannot be empty when forward auth is disabled."
)
return attrs
def create(self, validated_data):
instance: ProxyProvider = super().create(validated_data)
instance.set_oauth_defaults()

View File

@ -19,7 +19,7 @@ class BaseLDAPSynchronizer:
def __init__(self, source: LDAPSource):
self._source = source
self._logger = get_logger().bind(source=source)
self._logger = get_logger().bind(source=source, syncer=self.__class__.__name__)
@property
def base_dn_users(self) -> str:

View File

@ -89,7 +89,7 @@ export class ProviderListPage extends TablePage<Provider> {
</ak-forms-modal>
<ak-forms-delete
.obj=${item}
objectLabel=${t`Source`}
objectLabel=${t`Provider`}
.delete=${() => {
return new ProvidersApi(DEFAULT_CONFIG).providersAllDelete({
id: item.pk || 0