Revision dd53338a api/tests_auth.py
b/api/tests_auth.py | ||
---|---|---|
9 | 9 |
from django.test import TestCase |
10 | 10 |
from django.test.client import Client |
11 | 11 |
|
12 |
from synnefo.logic.shibboleth import Tokens |
|
13 |
from synnefo.db.models import SynnefoUser |
|
14 |
|
|
12 | 15 |
class AuthTestCase(TestCase): |
13 |
fixtures = ['auth_test_data']
|
|
14 |
apibase = '/api/v1.0'
|
|
16 |
fixtures = ['api_test_data']
|
|
17 |
apibase = '/api/v1.1'
|
|
15 | 18 |
|
16 | 19 |
def setUp(self): |
17 | 20 |
self.client = Client() |
18 | 21 |
|
19 |
def register_sibbolleth_user(self):
|
|
20 |
""" test registration of sibboleth user upon new incoming request
|
|
22 |
def test_auth_shibboleth(self):
|
|
23 |
""" test redirect to shibboleth page
|
|
21 | 24 |
""" |
22 |
response = self.client.get( self.apibase + '/servers', {}, |
|
23 |
**{'X-givenName':'notme', |
|
24 |
'X-sn':'0xdeadbabe'}) |
|
25 |
|
|
25 |
response = self.client.get(self.apibase + '/servers') |
|
26 |
self.assertEquals(response.status_code, 302) |
|
26 | 27 |
|
27 |
def test_auth_sibbolleth(self):
|
|
28 |
""" test whether the authentication mechanism sets the correct headers
|
|
28 |
def test_register_shibboleth_user(self):
|
|
29 |
""" test registration of sibboleth user upon new incoming request
|
|
29 | 30 |
""" |
31 |
response = self.client.get(self.apibase + '/servers', {}, |
|
32 |
**{Tokens.SIB_GIVEN_NAME: 'Jimmy', |
|
33 |
Tokens.SIB_EDU_PERSON_PRINCIPAL_NAME: 'jh@gmail.com', |
|
34 |
Tokens.SIB_DISPLAY_NAME: 'Jimmy Hendrix'}) |
|
35 |
|
|
36 |
user = None |
|
37 |
try: |
|
38 |
user = SynnefoUser.objects.get(uniq = "jh@gmail.com") |
|
39 |
except SynnefoUser.DoesNotExist: |
|
40 |
self.assertNotEqual(user, None) |
|
41 |
self.assertNotEqual(user, None) |
|
30 | 42 |
|
31 | 43 |
def test_auth_headers(self): |
32 | 44 |
""" test whether the authentication mechanism sets the correct headers |
33 | 45 |
""" |
34 | 46 |
#Check with non-existing user |
35 |
response = self.client.get( self.apibase + '/servers', {},
|
|
36 |
**{'X-Auth-User':'notme', |
|
37 |
'X-Auth-Key':'0xdeadbabe'}) |
|
47 |
response = self.client.get(self.apibase + '/servers', {}, |
|
48 |
**{'X-Auth-User': 'notme',
|
|
49 |
'X-Auth-Key': '0xdeadbabe'})
|
|
38 | 50 |
self.assertEquals(response.status_code, 401) |
39 | 51 |
|
40 | 52 |
#Check with existing user |
41 |
response = self.client.get( self.apibase + '/', {},
|
|
42 |
**{'X-Auth-User':'testuser', |
|
43 |
'X-Auth-Key':'testuserpasswd'}) |
|
53 |
response = self.client.get(self.apibase + '/', {}, |
|
54 |
**{'X-Auth-User': 'testuser',
|
|
55 |
'X-Auth-Key': 'testuserpasswd'})
|
|
44 | 56 |
self.assertEquals(response.status_code, 204) |
45 | 57 |
self.assertNotEqual(response['X-Auth-Token'], None) |
46 | 58 |
self.assertEquals(response['X-Server-Management-Url'], '') |
... | ... | |
49 | 61 |
|
50 | 62 |
#Check access now that we do have an auth token |
51 | 63 |
token = response['X-Auth-Token'] |
52 |
response = self.client.get (self.apibase + '/servers/detail', {},
|
|
64 |
response = self.client.get(self.apibase + '/servers/detail', {}, |
|
53 | 65 |
**{'X-Auth-Token': token}) |
54 | 66 |
self.assertEquals(response.status_code, 200) |
Also available in: Unified diff