Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
bf00c997
Commit
bf00c997
authored
Mar 31, 2011
by
Georgios Gousios
Browse files
Tests for auth api headers
parent
83969d4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
auth/tests.py
0 → 100644
View file @
bf00c997
#
# Unit Tests for auth api
#
# Provides automated tests for api module
#
# Copyright 2011 Greek Research and Technology Network
#
from
django.test
import
TestCase
from
django.test.client
import
Client
class
AuthTestCase
(
TestCase
):
apibase
=
'/api/v1.0'
def
setUp
(
self
):
self
.
client
=
Client
()
def
test_auth_headers
(
self
):
""" test whether the authentication mechanism sets the correct headers
"""
#Check with non-existing user
response
=
self
.
client
.
get
(
self
.
apibase
+
'/servers'
,
{},
**
{
'X-Auth-User'
:
'notme'
,
'X-Auth-Key'
:
'0xdeadbabe'
})
self
.
assertEquals
(
response
.
status_code
,
401
)
#Check with existing user
response
=
self
.
client
.
get
(
self
.
apibase
+
'/'
,
{},
**
{
'X-Auth-User'
:
'testuser'
,
'X-Auth-Key'
:
'testuserpasswd'
})
self
.
assertEquals
(
response
.
status_code
,
204
)
self
.
assertNotEqual
(
response
[
'X-Auth-Token'
],
None
)
self
.
assertEquals
(
response
[
'X-Server-Management-Url'
],
''
)
self
.
assertEquals
(
response
[
'X-Storage-Url'
],
''
)
self
.
assertEquals
(
response
[
'X-CDN-Management-Url'
],
''
)
#Check access now that we do have an auth token
token
=
response
[
'X-Auth-Token'
]
response
=
self
.
client
.
get
(
self
.
apibase
+
'/servers/detail'
,
{},
**
{
'X-Auth-Token'
:
token
})
self
.
assertEquals
(
response
.
status_code
,
200
)
\ No newline at end of file
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