root / api / tests_auth.py @ 1be508e9
History | View | Annotate | Download (1.5 kB)
1 | 5fb55fba | Georgios Gousios | #
|
---|---|---|---|
2 | 5fb55fba | Georgios Gousios | # Unit Tests for api
|
3 | 5fb55fba | Georgios Gousios | #
|
4 | 5fb55fba | Georgios Gousios | # Provides automated tests for api module
|
5 | 5fb55fba | Georgios Gousios | #
|
6 | 5fb55fba | Georgios Gousios | # Copyright 2011 Greek Research and Technology Network
|
7 | 5fb55fba | Georgios Gousios | #
|
8 | 5fb55fba | Georgios Gousios | |
9 | 5fb55fba | Georgios Gousios | from django.test import TestCase |
10 | 5fb55fba | Georgios Gousios | from django.test.client import Client |
11 | 5fb55fba | Georgios Gousios | |
12 | 5fb55fba | Georgios Gousios | class AuthTestCase(TestCase): |
13 | 5fb55fba | Georgios Gousios | fixtures = ['auth_test_data']
|
14 | 5fb55fba | Georgios Gousios | apibase = '/api/v1.0'
|
15 | 5fb55fba | Georgios Gousios | |
16 | 5fb55fba | Georgios Gousios | def setUp(self): |
17 | 5fb55fba | Georgios Gousios | self.client = Client()
|
18 | 5fb55fba | Georgios Gousios | |
19 | 5fb55fba | Georgios Gousios | def test_auth_headers(self): |
20 | 5fb55fba | Georgios Gousios | """ test whether the authentication mechanism sets the correct headers
|
21 | 5fb55fba | Georgios Gousios | """
|
22 | 5fb55fba | Georgios Gousios | #Check with non-existing user
|
23 | 5fb55fba | Georgios Gousios | response = self.client.get( self.apibase + '/servers', {}, |
24 | 5fb55fba | Georgios Gousios | **{'X-Auth-User':'notme', |
25 | 5fb55fba | Georgios Gousios | 'X-Auth-Key':'0xdeadbabe'}) |
26 | 5fb55fba | Georgios Gousios | self.assertEquals(response.status_code, 401) |
27 | 5fb55fba | Georgios Gousios | |
28 | 5fb55fba | Georgios Gousios | #Check with existing user
|
29 | 5fb55fba | Georgios Gousios | response = self.client.get( self.apibase + '/', {}, |
30 | 5fb55fba | Georgios Gousios | **{'X-Auth-User':'testuser', |
31 | 5fb55fba | Georgios Gousios | 'X-Auth-Key':'testuserpasswd'}) |
32 | 5fb55fba | Georgios Gousios | self.assertEquals(response.status_code, 204) |
33 | 5fb55fba | Georgios Gousios | self.assertNotEqual(response['X-Auth-Token'], None) |
34 | 5fb55fba | Georgios Gousios | self.assertEquals(response['X-Server-Management-Url'], '') |
35 | 5fb55fba | Georgios Gousios | self.assertEquals(response['X-Storage-Url'], '') |
36 | 5fb55fba | Georgios Gousios | self.assertEquals(response['X-CDN-Management-Url'], '') |
37 | 5fb55fba | Georgios Gousios | |
38 | 5fb55fba | Georgios Gousios | #Check access now that we do have an auth token
|
39 | 5fb55fba | Georgios Gousios | token = response['X-Auth-Token']
|
40 | 5fb55fba | Georgios Gousios | response = self.client.get (self.apibase + '/servers/detail', {}, |
41 | 5fb55fba | Georgios Gousios | **{'X-Auth-Token': token})
|
42 | 5fb55fba | Georgios Gousios | self.assertEquals(response.status_code, 200) |