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
535f28d9
Commit
535f28d9
authored
Nov 26, 2010
by
Ed Crewe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
got proxy ticket
parent
dfcfde5c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
17 deletions
+33
-17
django_cas/tests/cas_tests.py
+33
-17
No files found.
django_cas/tests/cas_tests.py
View file @
535f28d9
...
...
@@ -41,23 +41,36 @@ def get_auth():
print
'python proxy_test.py username password'
def
get_token
(
opener
,
url
,
token
=
TOKEN
):
""" Get CSRF token
- make this less ugly and more generic with regex
"""
""" Get CSRF token """
r
=
opener
.
open
(
url
)
page
=
r
.
read
()
end
=
page
.
find
(
'<input type="hidden" name="
%
s"'
%
token
)
start
=
end
+
page
[
end
:]
.
find
(
'value="'
)
+
len
(
'value="'
)
end
=
start
+
page
[
start
:]
.
find
(
'"'
)
token
=
page
[
start
:
end
]
return
token
starts
=
[
'<input type="hidden" name="
%
s"'
%
token
,
'value="'
]
return
find_in_page
(
page
,
starts
,
'"'
)
def
get_ticket
(
page
,
app_url
):
""" Get CSRF token """
starts
=
[
app_url
,
'?ticket='
]
return
find_in_page
(
page
,
starts
,
'"'
)
def
find_in_page
(
page
,
starts
,
stop
):
""" make this less ugly and more generic with regex """
end
=
page
.
find
(
starts
[
0
])
start
=
end
+
page
[
end
:]
.
find
(
starts
[
1
])
+
len
(
starts
[
1
])
end
=
start
+
page
[
start
:]
.
find
(
stop
)
found
=
page
[
start
:
end
]
return
found
def
login
(
opener
,
auth
):
""" Login to CAS server """
url
=
'
%
s/login?service=
%
s'
%
(
CAS_SERVER_URL
,
APP_URL
)
ticket
=
''
token
=
get_token
(
opener
,
url
)
if
token
:
auth
[
TOKEN
]
=
token
else
:
return
'FAILED CSRF Token could not be found on page'
print
'FAILED CSRF Token could not be found on page'
return
ticket
auth
[
'service'
]
=
APP_URL
data
=
urllib
.
urlencode
(
auth
)
sso_resp
=
opener
.
open
(
url
,
data
)
...
...
@@ -65,10 +78,11 @@ def login(opener, auth):
found
=
sso_page
.
find
(
CAS_SUCCESS
)
>
-
1
sso_resp
.
close
()
if
found
:
return
'PASS CAS logged in to
%
s'
%
url
ticket
=
get_ticket
(
sso_page
,
APP_URL
)
print
'PASS CAS logged in to
%
s'
%
url
else
:
return
'FAILED CAS login to
%
s'
%
url
print
'FAILED CAS login to
%
s'
%
url
return
ticket
def
get_restricted
(
opener
):
""" Access a restricted URL and see if its accessible """
...
...
@@ -77,16 +91,17 @@ def get_restricted(opener):
ok
=
app_resp
.
code
==
200
app_resp
.
close
()
if
ok
:
return
'PASS logged in to restricted app at
%
s'
%
url
print
'PASS logged in to restricted app at
%
s'
%
url
else
:
return
'FAILED to log in to restricted app at
%
s'
%
url
print
'FAILED to log in to restricted app at
%
s'
%
url
return
def
get_proxy
(
ticket
):
def
get_proxy
(
opener
,
ticket
):
""" Use login ticket to get proxy """
url_args
=
(
CAS_SERVER_URL
,
ticket
,
APP_URL
,
PROXY_URL
)
iou_url
=
'
%
s/serviceValidate?ticket=
%
s&service=
%
s&pgtUrl=
%
s'
iou_url
=
'
%
s/serviceValidate?ticket=
%
s&service=
%
s&pgtUrl=
%
s'
%
url_args
iou
=
opener
.
open
(
iou_url
)
print
iou
print
iou
.
read
()
cj
=
cookielib
.
CookieJar
()
opener
=
urllib2
.
build_opener
(
urllib2
.
HTTPCookieProcessor
(
cj
))
...
...
@@ -94,8 +109,9 @@ urllib2.install_opener(opener)
auth
=
get_auth
()
print
'Test ordinary CAS login'
print
'-----------------------'
print
login
(
opener
,
auth
)
print
get_restricted
(
opener
)
ticket
=
login
(
opener
,
auth
)
get_restricted
(
opener
)
print
''
print
'Test proxy CAS login'
print
'--------------------'
get_proxy
(
opener
,
ticket
)
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