Skip to content

Instantly share code, notes, and snippets.

@notmyname
Created February 14, 2014 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notmyname/e6b422b230072091ef06 to your computer and use it in GitHub Desktop.
Save notmyname/e6b422b230072091ef06 to your computer and use it in GitHub Desktop.
diff --git a/swiftclient/client.py b/swiftclient/client.py
index ee80769..275c6b7 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -219,8 +219,9 @@ def http_connection(*arg, **kwarg):
return conn.parsed_url, conn
-def get_auth_1_0(url, user, key, snet):
- parsed, conn = http_connection(url)
+def get_auth_1_0(url, user, key, snet, **kwargs):
+ insecure = kwargs.get('insecure', False)
+ parsed, conn = http_connection(url, insecure=insecure)
method = 'GET'
conn.request(method, parsed.path, '',
{'X-Auth-User': user, 'X-Auth-Key': key})
@@ -307,11 +308,13 @@ def get_auth(auth_url, user, key, **kwargs):
os_options = kwargs.get('os_options', {})
storage_url, token = None, None
+ insecure = kwargs.get('insecure', False)
if auth_version in ['1.0', '1', 1]:
storage_url, token = get_auth_1_0(auth_url,
user,
key,
- kwargs.get('snet'))
+ kwargs.get('snet'),
+ insecure=insecure)
elif auth_version in ['2.0', '2', 2]:
# We are allowing to specify a token/storage-url to re-use
# without having to re-authenticate.
@@ -335,7 +338,6 @@ def get_auth(auth_url, user, key, **kwargs):
if (not 'tenant_name' in os_options):
raise ClientException('No tenant specified')
- insecure = kwargs.get('insecure', False)
cacert = kwargs.get('cacert', None)
storage_url, token = get_keystoneclient_2_0(auth_url, user,
key, os_options,
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py
index 7a9f1f0..c2128f4 100644
--- a/tests/test_swiftclient.py
+++ b/tests/test_swiftclient.py
@@ -223,11 +223,35 @@ class TestGetAuth(MockHttpTest):
auth_version="foo")
def test_auth_v1(self):
- c.http_connection = self.fake_http_connection(200)
+ c.http_connection = self.fake_http_connection(200, auth_v1=True)
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
auth_version="1.0")
- self.assertEqual(url, None)
- self.assertEqual(token, None)
+ self.assertEqual(url, 'storageURL')
+ self.assertEqual(token, 'someauthtoken')
+
+ def test_auth_v1_insecure(self):
+ c.http_connection = self.fake_http_connection(200, auth_v1=True)
+ auth_url_secure = 'https://www.tests.com'
+ auth_url_insecure = 'https://www.tests.com/invalid-certificate'
+
+ url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf',
+ auth_version='1.0')
+ self.assertEqual(url, 'storageURL')
+ self.assertEqual(token, 'someauthtoken')
+
+ url, token = c.get_auth(auth_url_insecure, 'asdf', 'asdf',
+ auth_version='1.0',
+ insecure=True)
+ self.assertEqual(url, 'storageURL')
+ self.assertEqual(token, 'someauthtoken')
+
+ self.assertRaises(c.ClientException, c.get_auth,
+ auth_url_insecure, 'asdf', 'asdf',
+ auth_version='1.0')
+ self.assertRaises(c.ClientException, c.get_auth,
+ auth_url_insecure, 'asdf', 'asdf',
+ auth_version='1.0',
+ insecure=False)
def test_auth_v2(self):
os_options = {'tenant_name': 'asdf'}
diff --git a/tests/utils.py b/tests/utils.py
index ff2834a..dcaca9e 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -100,6 +100,10 @@ def fake_http_connect(*code_iter, **kwargs):
headers['content-length'] = '4'
if 'headers' in kwargs:
headers.update(kwargs['headers'])
+ if 'auth_v1' in kwargs:
+ headers.update(
+ {'x-storage-url': 'storageURL',
+ 'x-auth-token': 'someauthtoken'})
return headers.items()
def read(self, amt=None):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment