Commit 23b76392 by Ed Crewe

fix callback to give a response on success or fail

parent cbfe05d2
...@@ -58,15 +58,15 @@ class TestCAS(unittest.TestCase): ...@@ -58,15 +58,15 @@ class TestCAS(unittest.TestCase):
print 'Test proxy CAS login' print 'Test proxy CAS login'
print '--------------------' print '--------------------'
iou = self.get_proxy_iou() iou = self.get_proxy_iou()
if iou: if iou.startswith('PGT'):
print 'Got IOU:%s' % iou print 'PASS: Got IOU - %s for %s' % (iou, PROXY_URL)
else: else:
print 'Proxy CAS login failed, no IOU' print iou
pgt = self.get_proxy(iou) pgt = self.get_proxy(iou)
if pgt: if pgt.startswith('PGT'):
print 'Got PGT:%s' % pgt print 'PASS: Got PGT - %s' % pgt
else: else:
print 'Proxy CAS login failed, no PGT' print pgt
def get_auth(self): def get_auth(self):
""" Get authentication by passing to this script on the command line """ """ Get authentication by passing to this script on the command line """
...@@ -147,7 +147,9 @@ class TestCAS(unittest.TestCase): ...@@ -147,7 +147,9 @@ class TestCAS(unittest.TestCase):
return return
def get_proxy_iou(self): def get_proxy_iou(self):
""" Use login ticket to get proxy iou """ """ Use login ticket to get proxy iou
NB: SSO server installation may require PROXY_URL/?pgtIou be called at the root
"""
url_args = (CAS_SERVER_URL, self.ticket, APP_URL, PROXY_URL) url_args = (CAS_SERVER_URL, self.ticket, APP_URL, PROXY_URL)
url = '%s/serviceValidate?ticket=%s&service=%s&pgtUrl=%s' % url_args url = '%s/serviceValidate?ticket=%s&service=%s&pgtUrl=%s' % url_args
try: try:
...@@ -162,16 +164,40 @@ class TestCAS(unittest.TestCase): ...@@ -162,16 +164,40 @@ class TestCAS(unittest.TestCase):
if iou_ticket: if iou_ticket:
return iou_ticket return iou_ticket
else: else:
return 'FAIL: PGIOU Empty response from %s' % url if page:
return "FAIL: NO PGIOU\n\n%s" % page
else:
return 'FAIL: PGIOU Empty response from %s' % url
else: else:
return 'FAIL: PGIOU Response failed authentication' return 'FAIL: PGIOU Response failed authentication'
return None return None
def get_proxy(self, iou): def get_proxy_pgt(self, iou):
""" Get the proxy granting ticket from our django database backend
Assume this is not being hammered with requests so just get latest PGT
should of been created by get_proxy_iou callback request
"""
return ''
url_args = (PROXY_URL, PROXY_PATH, iou)
url = '%s%s?pgtIou=%s' % url_args
try:
pgt = self.opener.open(url)
except:
return 'FAIL: PGTURL=%s not found' % url
page = pgt.read()
return page
if page.find('cas:authenticationSuccess') > -1:
pgt_ticket = self.find_in_dom(page,['cas:serviceResponse',
'cas:authenticationSuccess',
'cas:proxyGrantingTicket'])
return pgt_ticket
return None
def get_proxy_pt(self, iou):
""" Use login ticket to get proxy """ """ Use login ticket to get proxy """
return return ''
url_args = (PROXY_URL, iou) url_args = (PROXY_URL, PROXY_PATH, iou)
url = '%s/pgtCallback?pgtIou=%s' % url_args url = '%s%s?pgtIou=%s' % url_args
try: try:
pgt = self.opener.open(url) pgt = self.opener.open(url)
except: except:
......
"""CAS login/logout replacement views""" """CAS login/logout replacement views"""
from datetime import datetime
from urllib import urlencode from urllib import urlencode
from urlparse import urljoin from urlparse import urljoin
...@@ -109,9 +109,11 @@ def logout(request, next_page=None): ...@@ -109,9 +109,11 @@ def logout(request, next_page=None):
def proxy_callback(request): def proxy_callback(request):
"""Handles CAS 2.0+ XML-based proxy callback call. """Handles CAS 2.0+ XML-based proxy callback call.
Stores the proxy granting ticket in the database for Stores the proxy granting ticket in the database for
future use. future use.
NB: Use created and set it in python in case database
has issues with setting up the default timestamp value
""" """
pgtIou = request.GET.get('pgtIou') pgtIou = request.GET.get('pgtIou')
tgt = request.GET.get('pgtId') tgt = request.GET.get('pgtId')
...@@ -119,5 +121,10 @@ def proxy_callback(request): ...@@ -119,5 +121,10 @@ def proxy_callback(request):
if not (pgtIou and tgt): if not (pgtIou and tgt):
return HttpResponse() return HttpResponse()
PgtIOU.objects.create(tgt = tgt, pgtIou = pgtIou) try:
return HttpResponse() PgtIOU.objects.create(tgt = tgt, pgtIou = pgtIou, created = datetime.now())
except:
return HttpResponse('PGT storage failed for %s' % str(request.GET), mimetype="text/plain")
return HttpResponse('Success', mimetype="text/plain")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment