Statistics
| Branch: | Tag: | Revision:

root / api / tests_auth.py @ 462c7e47

History | View | Annotate | Download (2 kB)

1
#
2
# Unit Tests for api
3
#
4
# Provides automated tests for api module
5
#
6
# Copyright 2011 Greek Research and Technology Network
7
#
8

    
9
from django.test import TestCase
10
from django.test.client import Client
11

    
12
class AuthTestCase(TestCase):
13
    fixtures = ['auth_test_data']
14
    apibase = '/api/v1.0'
15

    
16
    def setUp(self):
17
        self.client = Client()
18

    
19
    def register_sibbolleth_user(self):
20
        """ test registration of sibboleth user upon new incoming request
21
        """
22
        response = self.client.get( self.apibase + '/servers', {},
23
                                   **{'X-givenName':'notme',
24
                                      'X-sn':'0xdeadbabe'})
25
        
26

    
27
    def test_auth_sibbolleth(self):
28
        """ test whether the authentication mechanism sets the correct headers
29
        """
30

    
31
    def test_auth_headers(self):
32
        """ test whether the authentication mechanism sets the correct headers
33
        """
34
        #Check with non-existing user
35
        response = self.client.get( self.apibase + '/servers', {},
36
                                   **{'X-Auth-User':'notme',
37
                                      'X-Auth-Key':'0xdeadbabe'})
38
        self.assertEquals(response.status_code, 401)
39

    
40
        #Check with existing user
41
        response = self.client.get( self.apibase + '/', {},
42
                                   **{'X-Auth-User':'testuser',
43
                                      'X-Auth-Key':'testuserpasswd'})
44
        self.assertEquals(response.status_code, 204)
45
        self.assertNotEqual(response['X-Auth-Token'], None)
46
        self.assertEquals(response['X-Server-Management-Url'], '')
47
        self.assertEquals(response['X-Storage-Url'], '')
48
        self.assertEquals(response['X-CDN-Management-Url'], '')
49

    
50
        #Check access now that we do have an auth token
51
        token = response['X-Auth-Token']
52
        response = self.client.get (self.apibase + '/servers/detail', {},
53
                                   **{'X-Auth-Token': token})
54
        self.assertEquals(response.status_code, 200)