From b2341408b9f1464d15367e8eb90098da62b2fb17 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Fri, 11 Dec 2020 10:51:18 -0500 Subject: [PATCH] Fix 500 on unhandled group param type --- awx/sso/fields.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/awx/sso/fields.py b/awx/sso/fields.py index e430a0a367..38d8bde0d4 100644 --- a/awx/sso/fields.py +++ b/awx/sso/fields.py @@ -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]