Skip to content
Snippets Groups Projects
Commit a48b59c2 authored by Hammad Ahmad Waqas's avatar Hammad Ahmad Waqas
Browse files

fixed : when SAML attribute is mapped + present, but has no value

parent 7da2308b
No related merge requests found
......@@ -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):
......
"""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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment