Commit 1ab31f42 by Ed Crewe

fixed retrieval of PGT

parent 23b76392
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
import unittest import unittest
import sys import sys
import commands
import getpass import getpass
import urllib2 import urllib2
import urllib import urllib
...@@ -32,6 +33,7 @@ except: ...@@ -32,6 +33,7 @@ except:
'password' : '', # password field name 'password' : '', # password field name
'submit' : 'Login' # login submit button 'submit' : 'Login' # login submit button
} }
SCRIPT = 'manage.py shell --plain < get_pgt.py'
class TestCAS(unittest.TestCase): class TestCAS(unittest.TestCase):
""" A class for testing a CAS setup both for standard and proxy authentication """ """ A class for testing a CAS setup both for standard and proxy authentication """
...@@ -62,7 +64,7 @@ class TestCAS(unittest.TestCase): ...@@ -62,7 +64,7 @@ class TestCAS(unittest.TestCase):
print 'PASS: Got IOU - %s for %s' % (iou, PROXY_URL) print 'PASS: Got IOU - %s for %s' % (iou, PROXY_URL)
else: else:
print iou print iou
pgt = self.get_proxy(iou) pgt = self.get_proxy_pgt(iou)
if pgt.startswith('PGT'): if pgt.startswith('PGT'):
print 'PASS: Got PGT - %s' % pgt print 'PASS: Got PGT - %s' % pgt
else: else:
...@@ -107,7 +109,10 @@ class TestCAS(unittest.TestCase): ...@@ -107,7 +109,10 @@ class TestCAS(unittest.TestCase):
""" """
end = page.find(starts[0]) end = page.find(starts[0])
start = end + page[end:].find(starts[1]) + len(starts[1]) start = end + page[end:].find(starts[1]) + len(starts[1])
end = start + page[start:].find(stop) endnum = page[start:].find(stop)
if endnum == -1:
endnum = len(page[start:])
end = start + endnum
found = page[start:end] found = page[start:end]
return found.strip() return found.strip()
...@@ -174,34 +179,22 @@ class TestCAS(unittest.TestCase): ...@@ -174,34 +179,22 @@ class TestCAS(unittest.TestCase):
def get_proxy_pgt(self, iou): def get_proxy_pgt(self, iou):
""" Get the proxy granting ticket from our django database backend """ Get the proxy granting ticket from our django database backend
Assume this is not being hammered with requests so just get latest PGT Fire off shell script to django shell environment so this test class is
should of been created by get_proxy_iou callback request independent of CAS implementation - can substitute this function
to get proxy ticket from Java CAS instead of django-cas for example
""" """
return '' out = commands.getoutput(SCRIPT)
url_args = (PROXY_URL, PROXY_PATH, iou) pgt = self.find_in_page(out, ['>>>','PGT'], ' ')
url = '%s%s?pgtIou=%s' % url_args return 'PGT%s' % pgt
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): def get_proxy_pt(self, pgt):
""" Use login ticket to get proxy """ """ Use login ticket to get proxy """
return '' url_args = (CAS_SERVER_URL, APP_URL, pgt)
url_args = (PROXY_URL, PROXY_PATH, iou) url = '%s?targetService=%s&pgt=%s' % url_args
url = '%s%s?pgtIou=%s' % url_args
try: try:
pgt = self.opener.open(url) pgt = self.opener.open(url)
except: except:
return 'FAIL: PGTURL=%s not found' % url return 'FAIL: PTURL=%s not found' % url
page = pgt.read() page = pgt.read()
return page return page
if page.find('cas:authenticationSuccess') > -1: if page.find('cas:authenticationSuccess') > -1:
......
# Run via bin/django shell --plain < get_pgt.py
# to pick up all the django environment
# Allows main test class to be independent of CAS implementation platform
# TODO: pass in iou - if cant take args write to file and read here
import atexit
from django_cas.models import PgtIOU
@atexit.register
def lookup_pgt():
pgt = PgtIOU.objects.latest('created')
if pgt:
print pgt.tgt
else:
print 'FAIL'
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