From 74e3bb9fd4f331159f442b00cffb5d14da8b6da1 Mon Sep 17 00:00:00 2001 From: John Nagro Date: Thu, 6 Jul 2023 16:28:38 -0400 Subject: [PATCH] fix: correct bug in sapsf country to code mapping (#32675) --- common/djangoapps/third_party_auth/saml.py | 10 ++++++---- .../third_party_auth/tests/specs/test_testshib.py | 14 +++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/djangoapps/third_party_auth/saml.py b/common/djangoapps/third_party_auth/saml.py index 1b67fe5efd8c..8e78f9e36fc9 100644 --- a/common/djangoapps/third_party_auth/saml.py +++ b/common/djangoapps/third_party_auth/saml.py @@ -283,16 +283,18 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider): # Define a simple mapping to relate SAPSF values to Open edX-compatible values for # any given field. By default, this only contains the Country field, as SAPSF supplies # a country name, which has to be translated to a country code. - default_value_mapping = { - 'country': {name: code for code, name in countries} - } + country_mapping = {name: code for code, name in countries} # Unfortunately, not everything has a 1:1 name mapping between Open edX and SAPSF, so # we need some overrides. TODO: Fill in necessary mappings - default_value_mapping.update({ + country_mapping.update({ 'United States': 'US', }) + default_value_mapping = { + 'country': country_mapping + } + def get_registration_fields(self, response): """ Get a dictionary mapping registration field names to default values. diff --git a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py index 76305871ed9f..ec3efd8286e7 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py @@ -534,7 +534,7 @@ def user_callback(request, _uri, headers): 'lastName': 'Smith', 'defaultFullName': 'John Smith', 'email': 'john@smith.com', - 'country': 'Australia', + 'country': 'United States', } }) ) @@ -589,7 +589,7 @@ def test_register_sapsf_metadata_present(self): what we're looking for, and when an empty override is provided (expected behavior is that existing value maps will be left alone). """ - expected_country = 'AU' + expected_country = 'US' provider_settings = { 'sapsf_oauth_root_url': 'http://successfactors.com/oauth/', 'sapsf_private_key': 'fake_private_key_here', @@ -632,7 +632,7 @@ def user_callback(request, _uri, headers): 'firstName': 'John', 'lastName': 'Smith', 'defaultFullName': 'John Smith', - 'country': 'Australia' + 'country': 'United States' } }) ) @@ -666,7 +666,7 @@ def test_register_sapsf_metadata_present_override_relevant_value(self): what we're looking for, and when an empty override is provided (expected behavior is that existing value maps will be left alone). """ - value_map = {'country': {'Australia': 'NZ'}} + value_map = {'country': {'United States': 'NZ'}} expected_country = 'NZ' provider_settings = { 'sapsf_oauth_root_url': 'http://successfactors.com/oauth/', @@ -695,8 +695,8 @@ def test_register_sapsf_metadata_present_override_other_value(self): what we're looking for, and when an empty override is provided (expected behavior is that existing value maps will be left alone). """ - value_map = {'country': {'United States': 'blahfake'}} - expected_country = 'AU' + value_map = {'country': {'Australia': 'blahfake'}} + expected_country = 'US' provider_settings = { 'sapsf_oauth_root_url': 'http://successfactors.com/oauth/', 'sapsf_private_key': 'fake_private_key_here', @@ -726,7 +726,7 @@ def test_register_sapsf_metadata_present_empty_value_override(self): """ value_map = {'country': {}} - expected_country = 'AU' + expected_country = 'US' provider_settings = { 'sapsf_oauth_root_url': 'http://successfactors.com/oauth/', 'sapsf_private_key': 'fake_private_key_here',