Added unit tests for swift_auth_url @property. It was broken. startwith('swift+http') matches swift+https first

This commit is contained in:
jaypipes@gmail.com 2011-07-28 13:04:20 -04:00
parent 70b9389377
commit a4fe58efec
2 changed files with 9 additions and 15 deletions

View File

@ -142,14 +142,10 @@ class StoreLocation(glance.store.location.StoreLocation):
try:
self.obj = path_parts.pop()
self.container = path_parts.pop()
if self.scheme == 'swift+http':
self.authurl = 'http://'
else:
self.authurl = '' # default is https anyway
if not netloc.startswith('http'):
# push hostname back into the remaining to build full authurl
path_parts.insert(0, netloc)
self.authurl += '/'.join(path_parts)
self.authurl = '/'.join(path_parts)
except IndexError:
reason = "Badly formed Swift URI"
raise exception.BadStoreUri(uri, reason)
@ -163,16 +159,10 @@ class StoreLocation(glance.store.location.StoreLocation):
HTTPS is assumed, unless 'swift+http' is specified.
"""
if self.scheme.startswith('swift+http'):
auth_scheme = 'http://'
elif self.scheme.startswith('swift+https'):
auth_scheme = 'https://'
elif self.scheme.startswith('swift'):
if self.scheme in ('swift+https', 'swift'):
auth_scheme = 'https://'
else:
logger.warn("Unrecognized scheme '%s', defaulting auth url"
" to https", self.scheme)
auth_scheme = 'https://'
auth_scheme = 'http://'
full_url = ''.join([auth_scheme, self.authurl])
return full_url

View File

@ -138,6 +138,7 @@ class TestStoreLocation(unittest.TestCase):
self.assertEqual("swift", loc.scheme)
self.assertEqual("example.com", loc.authurl)
self.assertEqual("https://example.com", loc.swift_auth_url)
self.assertEqual("images", loc.container)
self.assertEqual("1", loc.obj)
self.assertEqual(None, loc.user)
@ -148,6 +149,7 @@ class TestStoreLocation(unittest.TestCase):
self.assertEqual("swift+https", loc.scheme)
self.assertEqual("authurl.com", loc.authurl)
self.assertEqual("https://authurl.com", loc.swift_auth_url)
self.assertEqual("images", loc.container)
self.assertEqual("1", loc.obj)
self.assertEqual("user", loc.user)
@ -159,17 +161,19 @@ class TestStoreLocation(unittest.TestCase):
self.assertEqual("swift+https", loc.scheme)
self.assertEqual("authurl.com/v1", loc.authurl)
self.assertEqual("https://authurl.com/v1", loc.swift_auth_url)
self.assertEqual("container", loc.container)
self.assertEqual("12345", loc.obj)
self.assertEqual("user", loc.user)
self.assertEqual("pass", loc.key)
self.assertEqual(uri, loc.get_uri())
uri = 'swift://account:user:pass@authurl.com/v1/container/12345'
uri = 'swift+http://account:user:pass@authurl.com/v1/container/12345'
loc.parse_uri(uri)
self.assertEqual("swift", loc.scheme)
self.assertEqual("swift+http", loc.scheme)
self.assertEqual("authurl.com/v1", loc.authurl)
self.assertEqual("http://authurl.com/v1", loc.swift_auth_url)
self.assertEqual("container", loc.container)
self.assertEqual("12345", loc.obj)
self.assertEqual("account:user", loc.user)