Fix 500 on unhandled group param type

This commit is contained in:
Jake McDermott 2020-12-11 10:51:18 -05:00
parent a5e54c3858
commit b2341408b9
No known key found for this signature in database
GPG Key ID: 0E56ED990CDFCB4F

View File

@ -445,7 +445,8 @@ class LDAPGroupTypeField(fields.ChoiceField, DependsOnMixin):
default_error_messages = {
'type_error': _('Expected an instance of LDAPGroupType but got {input_type} instead.'),
'missing_parameters': _('Missing required parameters in {dependency}.')
'missing_parameters': _('Missing required parameters in {dependency}.'),
'invalid_parameters': _('Invalid group_type parameters. Expected instance of dict but got {parameters_type} instead.')
}
def __init__(self, choices=None, **kwargs):
@ -465,7 +466,6 @@ class LDAPGroupTypeField(fields.ChoiceField, DependsOnMixin):
if not data:
return None
params = self.get_depends_on() or {}
cls = find_class_in_modules(data)
if not cls:
return None
@ -475,8 +475,16 @@ class LDAPGroupTypeField(fields.ChoiceField, DependsOnMixin):
# Backwords compatability. Before AUTH_LDAP_GROUP_TYPE_PARAMS existed
# MemberDNGroupType was the only group type, of the underlying lib, that
# took a parameter.
params = self.get_depends_on() or {}
params_sanitized = dict()
for attr in inspect.getargspec(cls.__init__).args[1:]:
cls_args = inspect.getargspec(cls.__init__).args[1:]
if cls_args:
if not isinstance(params, dict):
self.fail('invalid_parameters', parameters_type=type(params))
for attr in cls_args:
if attr in params:
params_sanitized[attr] = params[attr]