Skip to content

Commit

Permalink
fix: correct bug in sapsf country to code mapping (openedx#32675)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnagro authored Jul 6, 2023
1 parent 7d27a66 commit 74e3bb9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 6 additions & 4 deletions common/djangoapps/third_party_auth/saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions common/djangoapps/third_party_auth/tests/specs/test_testshib.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def user_callback(request, _uri, headers):
'lastName': 'Smith',
'defaultFullName': 'John Smith',
'email': '[email protected]',
'country': 'Australia',
'country': 'United States',
}
})
)
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -632,7 +632,7 @@ def user_callback(request, _uri, headers):
'firstName': 'John',
'lastName': 'Smith',
'defaultFullName': 'John Smith',
'country': 'Australia'
'country': 'United States'
}
})
)
Expand Down Expand Up @@ -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/',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 74e3bb9

Please sign in to comment.