ENT-619 Clean usernames coming from identity providers

Since we have started integrating with more clients, we have found that the usernames
that get passed are not compatible with our username restrictions. This PR introduces
a function to clean usernames to make them compatible, particularly in the auto registration
case.
This commit is contained in:
Brittney Exline
2017-08-30 13:34:52 -04:00
parent e56966c147
commit f844510b71
2 changed files with 20 additions and 9 deletions

View File

@@ -1070,14 +1070,19 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
)
@ddt.data(
('pk', 'PK'),
('Pk', 'PK'),
('pK', 'PK'),
('PK', 'PK'),
('us', 'US'),
('pk', 'PK', 'Bob123', 'Bob123'),
('Pk', 'PK', 'Bob123', 'Bob123'),
('pK', 'PK', 'Bob123@edx.org', 'Bob123_edx_org'),
('PK', 'PK', 'Bob123123123123123123123123123123123123', 'Bob123123123123123123123123123'),
('us', 'US', 'Bob-1231231&23123+1231(2312312312@3123123123', 'Bob-1231231_23123_1231_2312312'),
)
@ddt.unpack
def test_register_form_third_party_auth_running_google(self, input_country_code, expected_country_code):
def test_register_form_third_party_auth_running_google(
self,
input_country_code,
expected_country_code,
input_username,
expected_username):
no_extra_fields_setting = {}
country_options = (
[
@@ -1101,7 +1106,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
"openedx.core.djangoapps.user_api.api.third_party_auth.pipeline", "google-oauth2",
email="bob@example.com",
fullname="Bob",
username="Bob123",
username=input_username,
country=input_country_code
):
self._assert_password_field_hidden(no_extra_fields_setting)
@@ -1147,7 +1152,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
no_extra_fields_setting,
{
u"name": u"username",
u"defaultValue": u"Bob123",
u"defaultValue": expected_username,
u"type": u"text",
u"required": True,
u"label": u"Public Username",