summaryrefslogtreecommitdiff
path: root/tests/test_swiftclient.py
diff options
context:
space:
mode:
authorChmouel Boudjnah <chmouel@chmouel.com>2012-07-04 21:46:02 +0200
committerChmouel Boudjnah <chmouel@chmouel.com>2012-07-06 18:40:45 +0000
commitc8163f4112bbf5fb438a7fe04bcd9c6ab244768a (patch)
tree847dcb073d832594a51904f1ed04efa7de3b4179 /tests/test_swiftclient.py
parentc2a3fc56fc32b55f06798012fa5e74891acb533a (diff)
downloadpython-swiftclient-c8163f4112bbf5fb438a7fe04bcd9c6ab244768a.tar.gz
Use keystoneclient for authentication.
- This allows us to delegate all 2.0 authentication directly to the library without reimplementing ourselves. - Support reusing a token / storage-url without re-authenticating every time via the switch os_storage_url os_auth_token. - Allow auth via tenant_id instead of just tenant_name via the switch os_tenant_id. - Refactor a bit to make it easier in the future to add new OS features (i.e: region). - Implements blueprint use-keystoneclient-for-swiftclient. - Fixes bug 1016641. Change-Id: I532f38a68af884de25326aaac05a2050f5ffa1c7
Diffstat (limited to 'tests/test_swiftclient.py')
-rw-r--r--tests/test_swiftclient.py43
1 files changed, 17 insertions, 26 deletions
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py
index b165dee..29233e0 100644
--- a/tests/test_swiftclient.py
+++ b/tests/test_swiftclient.py
@@ -19,7 +19,7 @@ import unittest
from urlparse import urlparse
# TODO: mock http connection class with more control over headers
-from utils import fake_http_connect
+from utils import fake_http_connect, fake_get_keystoneclient_2_0
from swiftclient import client as c
@@ -175,42 +175,33 @@ class TestGetAuth(MockHttpTest):
self.assertEquals(token, None)
def test_auth_v2(self):
- def read(*args, **kwargs):
- acct_url = 'http://127.0.01/AUTH_FOO'
- body = {'access': {'serviceCatalog':
- [{u'endpoints': [{'publicURL': acct_url}],
- 'type': 'object-store'}],
- 'token': {'id': 'XXXXXXX'}}}
- return c.json_dumps(body)
- c.http_connection = self.fake_http_connection(200, return_read=read)
+ c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
- tenant_name='asdf', auth_version="2.0")
+ os_options={'tenant_name': 'asdf'},
+ auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
def test_auth_v2_no_tenant_name(self):
- def read(*args, **kwargs):
- acct_url = 'http://127.0.01/AUTH_FOO'
- body = {'access': {'serviceCatalog':
- [{u'endpoints': [{'publicURL': acct_url}],
- 'type': 'object-store'}],
- 'token': {'id': 'XXXXXXX'}}}
- return c.json_dumps(body)
- c.http_connection = self.fake_http_connection(200, return_read=read)
+ c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0
self.assertRaises(c.ClientException, c.get_auth,
'http://www.tests.com', 'asdf', 'asdf',
+ os_options={},
auth_version='2.0')
def test_auth_v2_with_tenant_user_in_user(self):
- def read(*args, **kwargs):
- acct_url = 'http://127.0.01/AUTH_FOO'
- body = {'access': {'serviceCatalog':
- [{u'endpoints': [{'publicURL': acct_url}],
- 'type': 'object-store'}],
- 'token': {'id': 'XXXXXXX'}}}
- return c.json_dumps(body)
- c.http_connection = self.fake_http_connection(200, return_read=read)
+ c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0
url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf',
+ os_options={},
+ auth_version="2.0")
+ self.assertTrue(url.startswith("http"))
+ self.assertTrue(token)
+
+ def test_auth_v2_tenant_name_no_os_options(self):
+ c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0
+ url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
+ tenant_name='asdf',
+ os_options={},
auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)