Merge pull request #15929 from edx/bexline/clean_saml_usernames

ENT-619 Clean usernames coming from identity providers
This commit is contained in:
Brittney Exline
2017-08-31 13:09:42 -04:00
committed by GitHub
2 changed files with 20 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ from __future__ import absolute_import
import json
import logging
import re
from config_models.models import ConfigurationModel, cache
from django.conf import settings
@@ -65,6 +66,11 @@ def clean_json(value, of_type):
return json.dumps(value_python, indent=4)
def clean_username(username=''):
""" Simple helper method to ensure a username is compatible with our system requirements. """
return re.sub(r'[^-\w]+', '_', username)[:30]
class AuthNotConfigured(SocialAuthBaseException):
""" Exception when SAMLProviderData or other required info is missing """
def __init__(self, provider_name):
@@ -259,7 +265,7 @@ class ProviderConfig(ConfigurationModel):
# technically a data race between the creation of this value and the
# creation of the user object, so it is still possible for users to get
# an error on submit.
registration_form_data['username'] = pipeline_kwargs.get('username')
registration_form_data['username'] = clean_username(pipeline_kwargs.get('username') or '')
# Any other values that are present in the details dict should be copied
# into the registration form details. This may include details that do