Example #1
0
    def test_cas2_custom_attrs(self):
        cas_collect_custom_attributes.connect(cas_mapping)
        response = self._login_user('editor', '123')
        self.maxDiff=None

        response = self._validate_cas2(response, True)
        self.assertEqual(response.content.decode('utf-8'),
                                           '''<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">'''
                                           '''<cas:authenticationSuccess>'''
                                           '''<cas:user>editor</cas:user>'''
                                           '''<cas:attributes>'''
                                           '''<cas:attraStyle>Jasig</cas:attraStyle>'''
                                           '''<cas:email>[email protected]</cas:email>'''
                                           '''<cas:group>editor</cas:group>'''
                                           '''<cas:is_active>True</cas:is_active>'''
                                           '''<cas:is_staff>True</cas:is_staff>'''
                                           '''</cas:attributes>'''
                                           '''</cas:authenticationSuccess>'''
                                           '''</cas:serviceResponse>''')

        self._cas_logout()
        response = self._login_user('editor', '123')
        settings.CAS_CUSTOM_ATTRIBUTES_FORMATER = 'cas_provider.attribute_formatters.ruby_cas'
        response = self._validate_cas2(response, True)
        self.assertEqual(response.content.decode('utf-8'),
                                           '''<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">'''
                                           '''<cas:authenticationSuccess>'''
                                           '''<cas:user>editor</cas:user>'''
                                           '''<cas:attraStyle>RubyCAS</cas:attraStyle>'''
                                           '''<cas:email>[email protected]</cas:email>'''
                                           '''<cas:group>editor</cas:group>'''
                                           '''<cas:is_active>True</cas:is_active>'''
                                           '''<cas:is_staff>True</cas:is_staff>'''
                                           '''</cas:authenticationSuccess>'''
                                           '''</cas:serviceResponse>''')

        self._cas_logout()
        response = self._login_user('editor', '123')
        settings.CAS_CUSTOM_ATTRIBUTES_FORMATER = 'cas_provider.attribute_formatters.name_value'
        response = self._validate_cas2(response, True)
        self.assertEqual(response.content.decode('utf-8'),
                                           '''<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">'''
                                           '''<cas:authenticationSuccess>'''
                                           '''<cas:user>editor</cas:user>'''
                                           '''<cas:attribute name="attraStyle" value="Name-Value"/>'''
                                           '''<cas:attribute name="email" value="*****@*****.**"/>'''
                                           '''<cas:attribute name="group" value="editor"/>'''
                                           '''<cas:attribute name="is_active" value="True"/>'''
                                           '''<cas:attribute name="is_staff" value="True"/>'''
                                           '''</cas:authenticationSuccess>'''
                                           '''</cas:serviceResponse>''')
Example #2
0
File: models.py Project: fnp/cas
from cas_provider.signals import cas_collect_custom_attributes


def user_attributes(sender, user, **kwargs):
    return {
        'firstname': user.first_name,
        'lastname': user.last_name,
        'cn': ' '.join((user.first_name, user.last_name)),
        'email': user.email,
    }
cas_collect_custom_attributes.connect(user_attributes)