diff --git a/common/djangoapps/third_party_auth/settings.py b/common/djangoapps/third_party_auth/settings.py index 2f2c0230d2..aee8467278 100644 --- a/common/djangoapps/third_party_auth/settings.py +++ b/common/djangoapps/third_party_auth/settings.py @@ -11,7 +11,7 @@ If true, it: """ from __future__ import absolute_import - +from django.conf import settings from openedx.features.enterprise_support.api import insert_enterprise_pipeline_elements @@ -42,6 +42,9 @@ def apply_settings(django_settings): # Adding extra key value pair in the url query string for microsoft as per request django_settings.SOCIAL_AUTH_AZUREAD_OAUTH2_AUTH_EXTRA_ARGUMENTS = {'msafed': 0} + # Avoid default username check to allow non-ascii characters + django_settings.SOCIAL_AUTH_CLEAN_USERNAMES = not settings.FEATURES.get("ENABLE_UNICODE_USERNAME") + # Inject our customized auth pipeline. All auth backends must work with # this pipeline. django_settings.SOCIAL_AUTH_PIPELINE = [ diff --git a/common/djangoapps/third_party_auth/tests/test_settings.py b/common/djangoapps/third_party_auth/tests/test_settings.py index 8353814e4f..e442280d39 100644 --- a/common/djangoapps/third_party_auth/tests/test_settings.py +++ b/common/djangoapps/third_party_auth/tests/test_settings.py @@ -4,6 +4,7 @@ from __future__ import absolute_import import unittest +from mock import patch from third_party_auth import provider, settings from third_party_auth.tests import testutil @@ -58,3 +59,12 @@ class SettingsUnitTest(testutil.TestCase): def test_apply_settings_turns_off_redirect_sanitization(self): settings.apply_settings(self.settings) self.assertFalse(self.settings.SOCIAL_AUTH_SANITIZE_REDIRECTS) + + def test_apply_settings_avoids_default_username_check(self): + # Avoid the default username check where non-ascii characters are not + # allowed when unicode username is enabled + settings.apply_settings(self.settings) + self.assertTrue(self.settings.SOCIAL_AUTH_CLEAN_USERNAMES) # verify default behavior + with patch.dict('django.conf.settings.FEATURES', {'ENABLE_UNICODE_USERNAME': True}): + settings.apply_settings(self.settings) + self.assertFalse(self.settings.SOCIAL_AUTH_CLEAN_USERNAMES)