fixed : when SAML attribute is mapped + present, but has no value
This commit is contained in:
@@ -219,8 +219,12 @@ class EdXSAMLIdentityProvider(SAMLIdentityProvider):
|
||||
another attribute to use.
|
||||
"""
|
||||
key = self.conf.get(conf_key, default_attribute)
|
||||
default = self.conf['attr_defaults'].get(conf_key) or None
|
||||
return attributes[key][0] if key in attributes else default
|
||||
if key in attributes:
|
||||
try:
|
||||
return attributes[key][0]
|
||||
except IndexError:
|
||||
log.warning(u'SAML attribute "%s" value not found.', key)
|
||||
return self.conf['attr_defaults'].get(conf_key) or None
|
||||
|
||||
@property
|
||||
def saml_sp_configuration(self):
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"""Mock data for SAMLIdentityProvider"""
|
||||
|
||||
from social_core.backends.saml import OID_MAIL, OID_GIVEN_NAME, OID_SURNAME, OID_COMMON_NAME, OID_USERID
|
||||
|
||||
expected_user_details = {
|
||||
'username': 'myself',
|
||||
'fullname': 'Me Myself And I',
|
||||
'last_name': None,
|
||||
'first_name': 'Me Myself',
|
||||
'email': 'myself@testshib.org'
|
||||
}
|
||||
|
||||
mock_attributes = {
|
||||
OID_USERID: ['myself'],
|
||||
OID_COMMON_NAME: ['Me Myself And I'],
|
||||
OID_SURNAME: [], # Assume user has not provided Last Name
|
||||
OID_GIVEN_NAME: ['Me Myself'],
|
||||
OID_MAIL: ['myself@testshib.org']
|
||||
}
|
||||
|
||||
mock_conf = {
|
||||
'attr_defaults': {}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ from third_party_auth.models import (
|
||||
SAMLProviderConfig
|
||||
)
|
||||
from third_party_auth.saml import EdXSAMLIdentityProvider, get_saml_idp_class
|
||||
from third_party_auth.tests.data.saml_identity_provider_mock_data import mock_conf, mock_attributes,\
|
||||
expected_user_details
|
||||
|
||||
AUTH_FEATURES_KEY = 'ENABLE_THIRD_PARTY_AUTH'
|
||||
AUTH_FEATURE_ENABLED = AUTH_FEATURES_KEY in settings.FEATURES
|
||||
@@ -225,6 +227,11 @@ class SAMLTestCase(TestCase):
|
||||
)
|
||||
self.assertIs(idp_class, EdXSAMLIdentityProvider)
|
||||
|
||||
def test_get_user_details(self):
|
||||
""" test get_attr and get_user_details of EdXSAMLIdentityProvider"""
|
||||
edx_smal_identity_provider = EdXSAMLIdentityProvider('demo', **mock_conf)
|
||||
self.assertEqual(edx_smal_identity_provider.get_user_details(mock_attributes), expected_user_details)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def simulate_running_pipeline(pipeline_target, backend, email=None, fullname=None, username=None, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user