Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-cas
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-cas
Commits
f10b4e83
Commit
f10b4e83
authored
Dec 08, 2010
by
Ed Crewe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add direct test of app as a proxy client
parent
45975de9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
26 deletions
+48
-26
django_cas/backends.py
+9
-7
django_cas/tests/cas_tests.py
+39
-19
No files found.
django_cas/backends.py
View file @
f10b4e83
...
@@ -117,13 +117,15 @@ class CASBackend(object):
...
@@ -117,13 +117,15 @@ class CASBackend(object):
"""CAS authentication backend"""
"""CAS authentication backend"""
def
authenticate
(
self
,
ticket
,
service
):
def
authenticate
(
self
,
ticket
,
service
):
"""Verifies CAS ticket and gets or creates User object"""
"""Verifies CAS ticket and gets or creates User object
if
ticket
.
startswith
(
'PT'
):
NB: Use of PT to identify proxy
authdict
=
verify_proxy_ticket
(
ticket
,
service
)
"""
if
authdict
:
#if ticket.startswith('PT'):
username
=
authdict
.
get
(
'username'
,
''
)
# authdict = verify_proxy_ticket(ticket, service)
else
:
# if authdict:
username
=
_verify
(
ticket
,
service
)
# username = authdict.get('username','')
#else:
username
=
_verify
(
ticket
,
service
)
if
not
username
:
if
not
username
:
return
None
return
None
try
:
try
:
...
...
django_cas/tests/cas_tests.py
View file @
f10b4e83
...
@@ -43,8 +43,8 @@ class TestCAS(unittest.TestCase):
...
@@ -43,8 +43,8 @@ class TestCAS(unittest.TestCase):
urls
=
{}
urls
=
{}
def
setUp
(
self
):
def
setUp
(
self
):
cj
=
cookielib
.
CookieJar
()
self
.
cj
=
cookielib
.
CookieJar
()
opener
=
urllib2
.
build_opener
(
urllib2
.
HTTPCookieProcessor
(
cj
))
opener
=
urllib2
.
build_opener
(
urllib2
.
HTTPCookieProcessor
(
self
.
cj
))
urllib2
.
install_opener
(
opener
)
urllib2
.
install_opener
(
opener
)
self
.
opener
=
opener
self
.
opener
=
opener
self
.
get_auth
()
self
.
get_auth
()
...
@@ -78,8 +78,8 @@ class TestCAS(unittest.TestCase):
...
@@ -78,8 +78,8 @@ class TestCAS(unittest.TestCase):
self
.
logout
()
self
.
logout
()
print
''
print
''
print
'Test
proxy CAS login
'
print
'Test
get proxy ticket
'
print
'--------------------'
print
'--------------------
-
'
self
.
ticket
=
self
.
login
()
self
.
ticket
=
self
.
login
()
iou
=
self
.
proxy1_iou
()
iou
=
self
.
proxy1_iou
()
if
iou
.
startswith
(
'PGT'
):
if
iou
.
startswith
(
'PGT'
):
...
@@ -99,14 +99,18 @@ class TestCAS(unittest.TestCase):
...
@@ -99,14 +99,18 @@ class TestCAS(unittest.TestCase):
else
:
else
:
print
pt
print
pt
print
''
print
'Test SSO server login with proxy ticket'
print
'---------------------------------------'
proxy
=
self
.
proxy4_login
(
pt
)
proxy
=
self
.
proxy4_login
(
pt
)
if
proxy
:
if
proxy
:
print
'PASS:
Logged in successfully to
%
s via
%
s'
%
(
self
.
urls
[
'app'
],
proxy
)
print
'PASS:
Got Success response for app
%
s using proxy
%
s'
%
(
self
.
urls
[
'app'
],
proxy
)
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
'Test direct proxy login'
print
'-----------------------'
self
.
proxy5_login
(
pt
)
self
.
proxy5_login
(
pt
)
...
@@ -119,13 +123,16 @@ class TestCAS(unittest.TestCase):
...
@@ -119,13 +123,16 @@ class TestCAS(unittest.TestCase):
self
.
auth
[
'password'
]
=
getpass
.
getpass
(
'CAS Password for user
%
s:'
%
AUTH
[
'username'
])
self
.
auth
[
'password'
]
=
getpass
.
getpass
(
'CAS Password for user
%
s:'
%
AUTH
[
'username'
])
return
return
def
get_token
(
self
,
url
,
token
=
TOKEN
):
def
get_token
(
self
,
url
=
None
,
token
=
TOKEN
,
page
=
''
):
""" Get CSRF token """
""" Get CSRF token """
try
:
if
url
:
r
=
self
.
opener
.
open
(
url
)
try
:
except
:
r
=
self
.
opener
.
open
(
url
)
return
'FAIL: URL not found
%
s'
%
url
except
:
page
=
r
.
read
()
return
'FAIL: URL not found
%
s'
%
url
page
=
r
.
read
()
if
not
page
:
return
'FAIL: Page is empty'
starts
=
[
'<input type="hidden" name="
%
s"'
%
token
,
starts
=
[
'<input type="hidden" name="
%
s"'
%
token
,
'value="'
]
'value="'
]
return
self
.
find_in_page
(
page
,
starts
,
'"'
)
return
self
.
find_in_page
(
page
,
starts
,
'"'
)
...
@@ -202,21 +209,32 @@ class TestCAS(unittest.TestCase):
...
@@ -202,21 +209,32 @@ class TestCAS(unittest.TestCase):
url
=
'
%
slogout'
%
self
.
urls
[
'cas'
]
url
=
'
%
slogout'
%
self
.
urls
[
'cas'
]
app_resp
=
self
.
opener
.
open
(
url
)
app_resp
=
self
.
opener
.
open
(
url
)
app_resp
.
close
()
app_resp
.
close
()
self
.
cj
.
clear
()
print
'Logged out'
print
'Logged out'
return
return
def
get_restricted
(
self
,
ticket
=
''
):
def
get_restricted
(
self
,
ticket
=
''
,
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
ie. success for get_token is a fail for get restricted
"""
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
)
app_resp
=
self
.
opener
.
open
(
url
)
app_resp
=
self
.
opener
.
open
(
url
)
ok
=
app_resp
.
code
==
200
ok
=
app_resp
.
code
==
200
app_resp
.
close
()
page
=
app_resp
.
read
()
if
ok
:
if
ok
:
print
'PASS: logged in to restricted app at
%
s'
%
url
token
=
self
.
get_token
(
page
=
page
)
if
token
and
not
token
.
startswith
(
'FAIL'
):
print
'FAIL: couldnt log in to restricted app at
%
s'
%
url
else
:
print
'PASS: logged in to restricted app at
%
s'
%
url
else
:
else
:
print
'FAIL: couldnt log in to restricted app at
%
s'
%
url
print
'FAIL: couldnt log in to restricted app at
%
s'
%
url
if
print_page
:
print
page
app_resp
.
close
()
def
proxy1_iou
(
self
):
def
proxy1_iou
(
self
):
""" Use login ticket to get proxy iou
""" Use login ticket to get proxy iou
...
@@ -278,7 +296,7 @@ class TestCAS(unittest.TestCase):
...
@@ -278,7 +296,7 @@ class TestCAS(unittest.TestCase):
def
proxy4_login
(
self
,
pt
):
def
proxy4_login
(
self
,
pt
):
"""
Use proxy ticket to login
"""
"""
Check proxy ticket for service
"""
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
:
...
@@ -290,10 +308,12 @@ class TestCAS(unittest.TestCase):
...
@@ -290,10 +308,12 @@ class TestCAS(unittest.TestCase):
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
):
"""
Check if service redirects to proxy login if given a PT-ticket
"""
"""
Use proxy ticket to login directly to app
"""
return
self
.
get_restricted
(
pt
)
return
self
.
get_restricted
(
pt
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment