Skip to content
Snippets Groups Projects
Commit 076d8297 authored by pkulkark's avatar pkulkark
Browse files

Fix unicode username hints with SSO

Usernames containing unicode characters were
reportedly not showing up correctly in the
registration form when registered with MOE/SAML,
FB and Google.
This change fixes the issue by overriding the
django setting SOCIAL_AUTH_CLEAN_USERNAMES to
disable the default username check that wasn't
allowing non-ascii values.
parent d5cfe35e
Branches
Tags
No related merge requests found
......@@ -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 = [
......
......@@ -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)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment