Commit fdc4f9c5 by Ed Crewe

fixed test to use different openers for the proxied app logins

parent 37fa9dbe
...@@ -74,7 +74,7 @@ class TestCAS(unittest.TestCase): ...@@ -74,7 +74,7 @@ class TestCAS(unittest.TestCase):
print 'Test ordinary CAS login' print 'Test ordinary CAS login'
print '-----------------------' print '-----------------------'
self.ticket = self.login() self.ticket = self.login()
self.get_restricted() self.get_restricted(opener=self.opener)
self.logout() self.logout()
print '' print ''
...@@ -99,7 +99,9 @@ class TestCAS(unittest.TestCase): ...@@ -99,7 +99,9 @@ class TestCAS(unittest.TestCase):
else: else:
print pt print pt
# self.logout() # NB: Dont logout proxy app, but test proxy auth with new openers
# for the tests to be valid...
print '' print ''
print 'Test SSO server login with proxy ticket' print 'Test SSO server login with proxy ticket'
print '---------------------------------------' print '---------------------------------------'
...@@ -109,11 +111,11 @@ class TestCAS(unittest.TestCase): ...@@ -109,11 +111,11 @@ class TestCAS(unittest.TestCase):
else: else:
print 'FAIL: The proxy login to %s via %s has failed' % (self.urls['app'], self.urls['proxy']) print 'FAIL: The proxy login to %s via %s has failed' % (self.urls['app'], self.urls['proxy'])
self.logout()
print '' print ''
print 'Test direct proxy login' print 'Test direct proxy login'
print '-----------------------' print '-----------------------'
self.proxy5_login(pt) new_pt = self.proxy3_pt(pgt)
self.proxy5_login(new_pt)
return return
...@@ -216,7 +218,7 @@ class TestCAS(unittest.TestCase): ...@@ -216,7 +218,7 @@ class TestCAS(unittest.TestCase):
print 'Logged out' print 'Logged out'
return return
def get_restricted(self, ticket='', print_page=False): def get_restricted(self, ticket='', opener=None, print_page=False):
""" Access a restricted URL and see if its accessible """ Access a restricted URL and see if its accessible
Use token to check if this page has redirected to SSO login Use token to check if this page has redirected to SSO login
ie. success for get_token is a fail for get restricted ie. success for get_token is a fail for get restricted
...@@ -224,10 +226,8 @@ class TestCAS(unittest.TestCase): ...@@ -224,10 +226,8 @@ class TestCAS(unittest.TestCase):
url = '%s%s' % (self.urls['app'], APP_RESTRICTED) url = '%s%s' % (self.urls['app'], APP_RESTRICTED)
if ticket: if ticket:
url = '%s?ticket=%s' % (url, ticket) url = '%s?ticket=%s' % (url, ticket)
print url
return
try: try:
app_resp = self.opener.open(url) app_resp = opener.open(url)
ok = app_resp.code == 200 ok = app_resp.code == 200
except: except:
print 'FAIL: couldnt log in to restricted app at %s' % url print 'FAIL: couldnt log in to restricted app at %s' % url
...@@ -305,25 +305,30 @@ class TestCAS(unittest.TestCase): ...@@ -305,25 +305,30 @@ class TestCAS(unittest.TestCase):
def proxy4_login(self, pt): def proxy4_login(self, pt):
""" Check proxy ticket for service """ """ Check proxy ticket for service
Use a new opener so its not got any cookies / auth already
"""
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
url_args = (self.urls['cas'], self.urls['app'], pt) url_args = (self.urls['cas'], self.urls['app'], pt)
url = '%sproxyValidate?service=%s&ticket=%s' % url_args url = '%sproxyValidate?service=%s&ticket=%s' % url_args
try: try:
login = self.opener.open(url) login = opener.open(url)
except: except:
return 'FAIL: PTURL=%s not found' % url return 'FAIL: PTURL=%s not found' % url
page = login.read() page = login.read()
print page
if page.find('cas:authenticationSuccess') > -1: if page.find('cas:authenticationSuccess') > -1:
proxy = self.find_in_dom(page,['cas:proxies', proxy = self.find_in_dom(page,['cas:proxies',
'cas:proxy']) 'cas:proxy'])
return proxy return proxy
else:
print page
return None return None
def proxy5_login(self, pt): def proxy5_login(self, pt):
""" Use proxy ticket to login directly to app """ """ Use proxy ticket to login directly to app
return self.get_restricted(pt) Use a new opener so its not got any cookies / auth already
"""
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
return self.get_restricted(ticket=pt, opener=opener)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
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