Skip to content

Commit

Permalink
HP-1915 Fix server error when ADFS doesn't return unique_name
Browse files Browse the repository at this point in the history
clean_attributes function tried to call split function on None.

That was because if "unique_name" was not in attrs_in the attribute
mapping would set attrs['last_first_name'] to None and the following
code only checked that the key exists in the dict before using
attrs['last_first_name'] as a string.
  • Loading branch information
mikkokeskinen committed May 25, 2023
1 parent ddab7ee commit 22efe32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions auth_backends/adfs/helsinki.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def clean_attributes(self, attrs_in):
attrs[out_name] = val
attrs[out_name] = val

if 'last_first_name' in attrs:
if attrs['last_first_name'] and isinstance(attrs['last_first_name'], str):
names = attrs['last_first_name'].split(' ')
if 'first_name' not in attrs:
attrs['first_name'] = [names[0]]
if 'last_name' not in attrs:
attrs['last_name'] = [' '.join(names[1:])]
del attrs['last_first_name']
del attrs['last_first_name']

return attrs
4 changes: 2 additions & 2 deletions auth_backends/adfs/helsinki_library_asko.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def clean_attributes(self, attrs_in):
logger.debug(f"'{in_name}' not found in data")
attrs[out_name] = val

if 'last_first_name' in attrs:
if attrs['last_first_name'] and isinstance(attrs['last_first_name'], str):
names = attrs['last_first_name'].split(' ')
if 'first_name' not in attrs:
attrs['first_name'] = [names[0]]
if 'last_name' not in attrs:
attrs['last_name'] = [' '.join(names[1:])]
del attrs['last_first_name']
del attrs['last_first_name']

return attrs

0 comments on commit 22efe32

Please sign in to comment.