service == service if host, port and path are euqal. Do not mind url params
authorSebastian Annies <sebastian.annies@googlemail.com>
Mon, 17 Oct 2011 13:26:16 +0000 (15:26 +0200)
committerSebastian Annies <sebastian.annies@googlemail.com>
Mon, 17 Oct 2011 17:12:49 +0000 (19:12 +0200)
testing the now corrected construction of the proxyCallbackUrl

cas_provider/models.py
cas_provider/tests.py
cas_provider/views.py

index 4ec2e85..c13aa32 100644 (file)
@@ -12,7 +12,7 @@ else:
     # Python <2.6 compatibility
     from cgi import parse_qs
 
-__all__ = ['ServiceTicket', 'LoginTicket']
+__all__ = ['ServiceTicket', 'LoginTicket', 'ProxyGrantingTicket', 'ProxyTicket', 'ProxyGrantingTicketIOU']
 
 class BaseTicket(models.Model):
     ticket = models.CharField(_('ticket'), max_length=32)
index 3dd9791..705eef9 100644 (file)
@@ -2,24 +2,32 @@ import StringIO
 import urllib2
 from xml import etree
 from xml.etree import ElementTree
+import cas_provider
 from cas_provider.attribute_formatters import CAS, NSMAP
 from cas_provider.models import ServiceTicket
-from cas_provider.views import _cas2_sucess_response, INVALID_TICKET, _cas2_error_response
-from django.contrib.auth.models import User
+from cas_provider.views import _cas2_sucess_response, INVALID_TICKET, _cas2_error_response, generate_proxy_granting_ticket
+from django.contrib.auth.models import User, UserManager
 from django.core.urlresolvers import reverse
 from django.test import TestCase
-from urlparse import urlparse
+from urlparse import urlparse, parse_qsl, parse_qs
 from django.conf import settings
-import cas_provider
+
+
+
+
+dummy_urlopen_url = None
+
 
 def dummy_urlopen(url):
+    cas_provider.tests.dummy_urlopen_url = url
     pass
 
-
 class ViewsTest(TestCase):
 
     fixtures = ['cas_users', ]
 
+
+
     def setUp(self):
         self.service = 'http://example.com/'
 
@@ -257,6 +265,23 @@ class ViewsTest(TestCase):
             self._validate_cas2(response, False)
 
 
+    def test_generate_proxy_granting_ticket(self):
+        urllib2.urlopen = dummy_urlopen # monkey patching urllib2.urlopen so that the testcase doesnt really opens a url
+        url = 'http://my.call.back/callhere'
+
+        user = User.objects.get(username = 'root')
+        st = ServiceTicket.objects.create(user = user )
+        pgt = generate_proxy_granting_ticket(url, st)
+        self.assertIsNotNone(pgt)
+
+        calledUrl = cas_provider.tests.dummy_urlopen_url
+        parsedUrl = urlparse(calledUrl)
+        params = parse_qs(parsedUrl.query)
+        self.assertIsNotNone(params['pgtId'])
+        self.assertIsNotNone(params['pgtIou'])
+
+
+
     def _fail_login(self, username, password):
         response = self._login_user(username, password)
         self._validate_cas1(response, False)
index 2769e52..2f0386f 100644 (file)
@@ -135,7 +135,10 @@ def ticket_validate(service, ticket_string, pgtUrl):
     except ServiceTicket.DoesNotExist:
         return _cas2_error_response(INVALID_TICKET)
 
-    if ticket.service != service:
+    ticketUrl =  urlparse.urlparse(ticket.service)
+    serviceUrl =  urlparse.urlparse(service)
+
+    if not(ticketUrl.hostname == serviceUrl.hostname and ticketUrl.path == serviceUrl.path and ticketUrl.port == serviceUrl.port):
         return _cas2_error_response(INVALID_SERVICE)
 
     pgtIouId = None
@@ -196,7 +199,7 @@ def generate_proxy_granting_ticket(pgt_url, ticket):
     query = dict(urlparse.parse_qsl(uri[4]))
     query.update(params)
 
-    uri[4] = urlencode(query)
+    uri[3] = urlencode(query)
 
     try:
         response = urllib2.urlopen(urlparse.urlunsplit(uri))