Commit f5e24ad4 authored by Georgios Gousios's avatar Georgios Gousios
Browse files

Move authentication tests and code to logic

parent e1c185f8
#
# 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):
fixtures = ['api_test_data', 'auth_test_data']
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
......@@ -99,3 +99,35 @@ class DebitAccountTestCase(TestCase):
s_user = SynnefoUser.objects.get(pk=30000)
self.assertEqual(0, s_user.credit, 'SynnefoUser (pk=30000) should have zero credits (%d)' % ( s_user.credit, ))
class AuthTestCase(TestCase):
fixtures = ['api_test_data', 'auth_test_data']
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment