+ def test_cas2_success_validate(self):
+ response = self._login_user('root', '123')
+ response = self._validate_cas2(response, True)
+ user = User.objects.get(username=self.username)
+ self.assertEqual(response.content, _cas2_sucess_response(user).content)
+
+ def test_cas2_custom_attrs(self):
+ settings.CAS_CUSTOM_ATTRIBUTES_CALLBACK = cas_mapping
+ response = self._login_user('editor', '123')
+
+ response = self._validate_cas2(response, True)
+ self.assertEqual(response.content, '''<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:group>editor</cas:group>'''
+ '''<cas:is_staff>True</cas:is_staff>'''
+ '''<cas:is_active>True</cas:is_active>'''
+ '''<cas:email>editor@exapmle.com</cas:email>'''
+ '''</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, '''<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">'''
+ '''<cas:authenticationSuccess>'''
+ '''<cas:user>editor</cas:user>'''
+ '''<cas:attraStyle>RubyCAS</cas:attraStyle>'''
+ '''<cas:group>editor</cas:group>'''
+ '''<cas:is_staff>True</cas:is_staff>'''
+ '''<cas:is_active>True</cas:is_active>'''
+ '''<cas:email>editor@exapmle.com</cas:email>'''
+ '''</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, '''<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="group" value="editor"/>'''
+ '''<cas:attribute name="is_staff" value="True"/>'''
+ '''<cas:attribute name="is_active" value="True"/>'''
+ '''<cas:attribute name="email" value="editor@exapmle.com"/>'''
+ '''</cas:authenticationSuccess>'''
+ '''</cas:serviceResponse>''')
+
+
+ def test_cas2_fail_validate(self):
+ for user, pwd in (('root', '321'), ('notroot', '123'), ('nonactive', '123')):
+ response = self._login_user(user, pwd)
+ self._validate_cas2(response, False)
+