Skip to content

Commit

Permalink
Fix --insecure option on auth
Browse files Browse the repository at this point in the history
Change-Id: Ibe76d98d6075b84cbdb370b48f3498ab848142ad
  • Loading branch information
notmyname committed Feb 14, 2014
1 parent 19d7e18 commit 79f189a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
16 changes: 9 additions & 7 deletions swiftclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, url, proxy=None, cacert=None, insecure=False,
if self.parsed_url.scheme not in ('http', 'https'):
raise ClientException("Unsupported scheme")
self.requests_args['verify'] = not insecure
if cacert:
if cacert and not insecure:
# verify requests parameter is used to pass the CA_BUNDLE file
# see: http://docs.python-requests.org/en/latest/user/advanced/
self.requests_args['verify'] = cacert
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -1101,8 +1103,8 @@ def __init__(self, authurl=None, user=None, key=None, retries=5,
:param os_options: The OpenStack options which can have tenant_id,
auth_token, service_type, endpoint_type,
tenant_name, object_storage_url, region_name
:param insecure: Allow to access insecure keystone server.
The keystone's certificate will not be verified.
:param insecure: Allow to access servers without checking SSL certs.
The server's certificate will not be verified.
:param ssl_compression: Whether to enable compression at the SSL layer.
If set to 'False' and the pyOpenSSL library is
present an attempt to disable SSL compression
Expand Down
23 changes: 20 additions & 3 deletions tests/test_swiftclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def wrapper(url, proxy=None, cacert=None, insecure=False,
def request(method, url, *args, **kwargs):
if query_string:
self.assertTrue(url.endswith('?' + query_string))
if url.endswith('invalid_cert') and not insecure:
from swiftclient import client as c
raise c.ClientException("invalid_certificate")
return
conn.request = request

Expand Down Expand Up @@ -223,11 +226,25 @@ def test_invalid_auth(self):
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)
url, token = c.get_auth('http://www.test.com/invalid_cert',
'asdf', 'asdf',
auth_version='1.0',
insecure=True)
self.assertEqual(url, 'storageURL')
self.assertEqual(token, 'someauthtoken')

self.assertRaises(c.ClientException, c.get_auth,
'http://www.test.com/invalid_cert',
'asdf', 'asdf',
auth_version='1.0')

def test_auth_v2(self):
os_options = {'tenant_name': 'asdf'}
Expand Down
4 changes: 4 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def getheaders(self):
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):
Expand Down

0 comments on commit 79f189a

Please sign in to comment.