def test_service_validate_view(self): """ When called with no parameters, a validation failure should be returned. """ request = self.rf.get(reverse('cas_service_validate')) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'INVALID_REQUEST')
def test_service_validate_view_invalid_service(self): """ When called with an invalid service identifier, a validation failure should be returned. """ request = self.rf.get(reverse('cas_service_validate'), {'service': self.url2, 'ticket': self.st.ticket}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'INVALID_SERVICE')
def test_service_validate_view_invalid_service_url(self): """ When ``MAMA_CAS_VALID_SERVICES`` is defined, a validation failure should be returned if the service URL does not match. """ request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': self.st.ticket}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'INVALID_SERVICE')
def test_service_validate_view_user_attributes(self): """ When ``MAMA_CAS_USER_ATTRIBUTES`` is defined, the validation success should include the custom attribute block. """ request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': self.st.ticket}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'attributes')
def test_service_validate_view_invalid_ticket(self): """ When the provided ticket cannot be found, a validation failure should be returned. """ st_str = ServiceTicket.objects.create_ticket_str() request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': st_str}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'INVALID_TICKET')
def test_service_validate_view_pgturl_http(self): """ When called with valid parameters and an invalid ``pgtUrl``, the validation success should have no ``ProxyGrantingTicket``. """ request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': self.st.ticket, 'pgtUrl': self.url}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'authenticationSuccess') self.assertNotContains(response, 'proxyGrantingTicket')
def test_service_validate_view_attribute_callbacks(self): """ When a custom callback is defined, a validation success should include the returned attributes. """ request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': self.st.ticket}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'attributes') self.assertContains(response, '<cas:username>ellen</cas:username>')
def test_service_validate_view_exception_callbacks(self): """ When an attribute callback raises a ValidationError, the exception should be handled and cause an authentication failure. """ st = ServiceTicketFactory(service='exception') request = self.rf.get(reverse('cas_service_validate'), {'service': 'exception', 'ticket': st.ticket}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'INTERNAL_ERROR') self.assertContains(response, 'Error in attribute callback')
def test_service_validate_view_pgturl(self): """ When called with valid parameters and a ``pgtUrl``, the validation success should include a ``ProxyGrantingTicket``. """ request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': self.st.ticket, 'pgtUrl': self.url2}) with patch('requests.get') as mock: mock.return_value.status_code = 200 response = ServiceValidateView.as_view()(request) self.assertContains(response, 'authenticationSuccess') self.assertContains(response, 'proxyGrantingTicket')
def test_service_validate_view_proxy_ticket(self): """ When a proxy ticket is provided, the validation failure should indicate that it was because a proxy ticket was provided. """ pt_str = ProxyTicket.objects.create_ticket_str() request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': pt_str}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'INVALID_TICKET') self.assertContains(response, 'Proxy tickets cannot be validated' ' with /serviceValidate')
def test_service_validate_view_user_attributes(self): """ When ``MAMA_CAS_USER_ATTRIBUTES`` is defined, the validation success should include the custom attribute block. """ request = self.rf.get(reverse('cas_service_validate'), { 'service': self.url, 'ticket': self.st.ticket }) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'attributes')
def test_service_validate_view_success(self): """ When called with valid parameters, a validation success should be returned. The provided ticket should then be consumed. """ request = self.rf.get(reverse('cas_service_validate'), {'service': self.url, 'ticket': self.st.ticket}) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'authenticationSuccess') self.assertEqual(response.get('Content-Type'), 'text/xml') st = ServiceTicket.objects.get(ticket=self.st.ticket) self.assertTrue(st.is_consumed())
def test_service_validate_view_exception_callbacks(self): """ When an attribute callback raises a ValidationError, the exception should be handled and cause an authentication failure. """ st = ServiceTicketFactory(service='exception') request = self.rf.get(reverse('cas_service_validate'), { 'service': 'exception', 'ticket': st.ticket }) response = ServiceValidateView.as_view()(request) self.assertContains(response, 'INTERNAL_ERROR') self.assertContains(response, 'Error in attribute callback')
from mama_cas.views import LoginView from mama_cas.views import LogoutView from mama_cas.views import ValidateView from mama_cas.views import ServiceValidateView from mama_cas.views import ProxyValidateView from mama_cas.views import ProxyView from mama_cas.views import WarnView from mama_cas.views import SamlValidateView urlpatterns = [ url(r'^login/?$', LoginView.as_view(), name='cas_login'), url(r'^logout/?$', LogoutView.as_view(), name='cas_logout'), url(r'^validate/?$', ValidateView.as_view(), name='cas_validate'), url(r'^serviceValidate/?$', ServiceValidateView.as_view(), name='cas_service_validate'), url(r'^proxyValidate/?$', ProxyValidateView.as_view(), name='cas_proxy_validate'), url(r'^proxy/?$', ProxyView.as_view(), name='cas_proxy'), url(r'^p3/serviceValidate/?$', ServiceValidateView.as_view(), name='cas_p3_service_validate'), url(r'^p3/proxyValidate/?$', ProxyValidateView.as_view(), name='cas_p3_proxy_validate'), url(r'^warn/?$', WarnView.as_view(), name='cas_warn'), url(r'^samlValidate/?$', SamlValidateView.as_view(), name='cas_saml_validate'),
from mama_cas.views import WarnView from mama_cas.views import SamlValidateView urlpatterns = patterns('', url(r'^login/?$', LoginView.as_view(), name='cas_login'), url(r'^logout/?$', LogoutView.as_view(), name='cas_logout'), url(r'^validate/?$', ValidateView.as_view(), name='cas_validate'), url(r'^serviceValidate/?$', ServiceValidateView.as_view(), name='cas_service_validate'), url(r'^proxyValidate/?$', ProxyValidateView.as_view(), name='cas_proxy_validate'), url(r'^proxy/?$', ProxyView.as_view(), name='cas_proxy'), url(r'^p3/serviceValidate/?$', ServiceValidateView.as_view(), name='cas_p3_service_validate'), url(r'^p3/proxyValidate/?$', ProxyValidateView.as_view(), name='cas_p3_proxy_validate'), url(r'^warn/?$', WarnView.as_view(),
""" (2) CAS server URIs as described in the CAS protocol. """ from django.conf.urls import url from mama_cas.views import LoginView from mama_cas.views import LogoutView from mama_cas.views import ValidateView from mama_cas.views import ServiceValidateView from mama_cas.views import ProxyValidateView from mama_cas.views import ProxyView from mama_cas.views import WarnView from mama_cas.views import SamlValidateView urlpatterns = [ url(r'^login/?$', LoginView.as_view(), name='cas_login'), url(r'^logout/?$', LogoutView.as_view(), name='cas_logout'), url(r'^validate/?$', ValidateView.as_view(), name='cas_validate'), url(r'^serviceValidate/?$', ServiceValidateView.as_view(), name='cas_service_validate'), url(r'^proxyValidate/?$', ProxyValidateView.as_view(), name='cas_proxy_validate'), url(r'^proxy/?$', ProxyView.as_view(), name='cas_proxy'), url(r'^p3/serviceValidate/?$', ServiceValidateView.as_view(), name='cas_p3_service_validate'), url(r'^p3/proxyValidate/?$', ProxyValidateView.as_view(), name='cas_p3_proxy_validate'), url(r'^warn/?$', WarnView.as_view(), name='cas_warn'), url(r'^samlValidate/?$', SamlValidateView.as_view(), name='cas_saml_validate'), ]
""" URLconf for CAS server URIs as described in the CAS protocol. """ from django.conf.urls import patterns from django.conf.urls import url from mama_cas.views import LoginView from mama_cas.views import LogoutView from mama_cas.views import ValidateView from mama_cas.views import ServiceValidateView from mama_cas.views import ProxyValidateView from mama_cas.views import ProxyView from mama_cas.views import WarnView urlpatterns = patterns( "", url(r"^login/?$", LoginView.as_view(), name="cas_login"), url(r"^logout/?$", LogoutView.as_view(), name="cas_logout"), url(r"^validate/?$", ValidateView.as_view(), name="cas_validate"), url(r"^serviceValidate/?$", ServiceValidateView.as_view(), name="cas_service_validate"), url(r"^proxyValidate/?$", ProxyValidateView.as_view(), name="cas_proxy_validate"), url(r"^proxy/?$", ProxyView.as_view(), name="cas_proxy"), url(r"^warn/?$", WarnView.as_view(), name="cas_warn"), )