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
837ce8c9
Commit
837ce8c9
authored
Oct 26, 2011
by
Sebastian Annies
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
corrected failure that pgtiou is not created and added test ensuring exactly that
parent
9801cb06
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
django_cas/backends.py
+1
-1
django_cas/tests.py
+21
-5
No files found.
django_cas/backends.py
View file @
837ce8c9
...
...
@@ -59,7 +59,7 @@ def _verify_cas2(ticket, service):
if
tree
.
find
(
CAS
+
'authenticationSuccess'
,
namespaces
=
NSMAP
):
username
=
tree
.
find
(
CAS
+
'authenticationSuccess/'
+
CAS
+
'user'
,
namespaces
=
NSMAP
)
.
text
pgtIouIdElement
=
tree
.
find
(
CAS
+
'authenticationSuccess/'
+
CAS
+
'proxyGrantingTicket'
,
namespaces
=
NSMAP
);
pgtIouId
=
pgtIouIdElement
.
text
if
pgtIouIdElement
else
None
pgtIouId
=
pgtIouIdElement
.
text
if
pgtIouIdElement
is
not
None
else
None
if
pgtIouId
:
pgtIou
=
PgtIOU
.
objects
.
get
(
pgtIou
=
pgtIouId
)
...
...
django_cas/tests.py
View file @
837ce8c9
from
StringIO
import
StringIO
from
unittest.case
import
TestCase
import
urllib
from
django.conf
import
settings
from
django.utils.unittest.case
import
TestCase
from
django_cas.backends
import
_verify_cas2
from
django_cas.models
import
PgtIOU
,
Tgt
__author__
=
'sannies'
def
dummyUrlOpenNoProxyGrantingTicket
(
url
):
return
StringIO
(
'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas"><cas:authenticationSuccess><cas:user>sannies</cas:user><cas:attributes><cas:attraStyle>Jasig</cas:attraStyle><cas:merchant>sannies</cas:merchant><cas:userServerUrl>http://localhost:8080/user-authorization-adapter/</cas:userServerUrl><cas:firstname></cas:firstname><cas:lastname></cas:lastname><cas:is_superuser>True</cas:is_superuser><cas:is_staff>True</cas:is_staff><cas:ROLES>ROLE_SUPERUSER</cas:ROLES><cas:ROLES>ROLE_STAFF</cas:ROLES><cas:ROLES>ROLE_USER</cas:ROLES><cas:ROLES>ROLE_MERCHANT</cas:ROLES><cas:playReadyLicenseAcquisitionUiUrl>http://www.drmtoday.com/</cas:playReadyLicenseAcquisitionUiUrl><cas:email>Sebastian.Annies@castlabs.com</cas:email></cas:attributes></cas:authenticationSuccess></cas:serviceResponse>'
)
return
StringIO
(
'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas"><cas:authenticationSuccess><cas:user>sannies</cas:user><cas:attributes><cas:attraStyle>Jasig</cas:attraStyle><cas:merchant>sannies</cas:merchant><cas:userServerUrl>http://localhost:8080/user-authorization-adapter/</cas:userServerUrl><cas:firstname></cas:firstname><cas:lastname></cas:lastname><cas:is_superuser>True</cas:is_superuser><cas:is_staff>True</cas:is_staff><cas:ROLES>ROLE_SUPERUSER</cas:ROLES><cas:ROLES>ROLE_STAFF</cas:ROLES><cas:ROLES>ROLE_USER</cas:ROLES><cas:ROLES>ROLE_MERCHANT</cas:ROLES><cas:playReadyLicenseAcquisitionUiUrl>http://www.drmtoday.com/</cas:playReadyLicenseAcquisitionUiUrl><cas:email>Sebastian.Annies@castlabs.com</cas:email></cas:attributes></cas:authenticationSuccess></cas:serviceResponse>'
)
def
dummyUrlOpenWithProxyGrantingTikcet
(
url
):
return
StringIO
(
'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas"><cas:authenticationSuccess><cas:user>sannies</cas:user><cas:attribute name="attraStyle" value="Name-Value"/><cas:attribute name="is_staff" value="True"/><cas:attribute name="is_active" value="True"/><cas:attribute name="email" value="root@example.com"/><cas:proxyGrantingTicket>PGTIOU-NUYny6RiAfHBsuWq270m3l1kgPTjEOCexpowQV9ZJDrh8cGKzb</cas:proxyGrantingTicket></cas:authenticationSuccess></cas:serviceResponse>'
)
class
backendTest
(
TestCase
):
def
test_verify_cas2
(
self
):
def
test_verify_cas2
_no_pgt
(
self
):
urllib
.
urlopen
=
dummyUrlOpenNoProxyGrantingTicket
settings
.
CAS_PROXY_CALLBACK
=
None
user
=
_verify_cas2
(
'ST-jkadfhjksdhjkfh'
,
'http://dummy'
)
self
.
assertEqual
(
'sannies'
,
user
)
\ No newline at end of file
def
test_verify_cas2_with_pgt
(
self
):
urllib
.
urlopen
=
dummyUrlOpenWithProxyGrantingTikcet
#st = ServiceTicket.objects.create();
tgt
=
Tgt
.
objects
.
create
(
username
=
'sannies'
);
PgtIOU
.
objects
.
create
(
tgt
=
tgt
,
pgtIou
=
'PGTIOU-NUYny6RiAfHBsuWq270m3l1kgPTjEOCexpowQV9ZJDrh8cGKzb'
)
settings
.
CAS_PROXY_CALLBACK
=
"http://dummy2"
prior
=
PgtIOU
.
objects
.
count
()
user
=
_verify_cas2
(
'ST-jkadfhjksdhjkfh'
,
'http://dummy'
)
self
.
assertEqual
(
prior
-
1
,
PgtIOU
.
objects
.
count
())
# the pgtiou should be used up and deleted
self
.
assertEqual
(
'sannies'
,
user
)
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