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
1ab31f42
Commit
1ab31f42
authored
Dec 03, 2010
by
Ed Crewe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed retrieval of PGT
parent
23b76392
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
24 deletions
+33
-24
django_cas/tests/cas_tests.py
+17
-24
django_cas/tests/get_pgt.py
+16
-0
No files found.
django_cas/tests/cas_tests.py
View file @
1ab31f42
...
...
@@ -9,6 +9,7 @@
import
unittest
import
sys
import
commands
import
getpass
import
urllib2
import
urllib
...
...
@@ -32,6 +33,7 @@ except:
'password'
:
''
,
# password field name
'submit'
:
'Login'
# login submit button
}
SCRIPT
=
'manage.py shell --plain < get_pgt.py'
class
TestCAS
(
unittest
.
TestCase
):
""" A class for testing a CAS setup both for standard and proxy authentication """
...
...
@@ -62,7 +64,7 @@ class TestCAS(unittest.TestCase):
print
'PASS: Got IOU -
%
s for
%
s'
%
(
iou
,
PROXY_URL
)
else
:
print
iou
pgt
=
self
.
get_proxy
(
iou
)
pgt
=
self
.
get_proxy
_pgt
(
iou
)
if
pgt
.
startswith
(
'PGT'
):
print
'PASS: Got PGT -
%
s'
%
pgt
else
:
...
...
@@ -107,7 +109,10 @@ class TestCAS(unittest.TestCase):
"""
end
=
page
.
find
(
starts
[
0
])
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
]
return
found
.
strip
()
...
...
@@ -174,34 +179,22 @@ class TestCAS(unittest.TestCase):
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
Fire off shell script to django shell environment so this test class is
independent of CAS implementation - can substitute this function
to get proxy ticket from Java CAS instead of django-cas for example
"""
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
out
=
commands
.
getoutput
(
SCRIPT
)
pgt
=
self
.
find_in_page
(
out
,
[
'>>>'
,
'PGT'
],
' '
)
return
'PGT
%
s'
%
pgt
def
get_proxy_pt
(
self
,
iou
):
def
get_proxy_pt
(
self
,
pgt
):
""" Use login ticket to get proxy """
return
''
url_args
=
(
PROXY_URL
,
PROXY_PATH
,
iou
)
url
=
'
%
s
%
s?pgtIou=
%
s'
%
url_args
url_args
=
(
CAS_SERVER_URL
,
APP_URL
,
pgt
)
url
=
'
%
s?targetService=
%
s&pgt=
%
s'
%
url_args
try
:
pgt
=
self
.
opener
.
open
(
url
)
except
:
return
'FAIL: P
G
TURL=
%
s not found'
%
url
return
'FAIL: PTURL=
%
s not found'
%
url
page
=
pgt
.
read
()
return
page
if
page
.
find
(
'cas:authenticationSuccess'
)
>
-
1
:
...
...
django_cas/tests/get_pgt.py
0 → 100644
View file @
1ab31f42
# 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'
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