diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-11-27 15:45:29 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-11-27 15:45:29 +0000 |
commit | e56962c2af7e2e944dc6a30959df8de8fdb922df (patch) | |
tree | 5f1b4b18875a6c9faf4d0518216435a9905bf9af | |
parent | 74df6a7be308076ed977f9c0f16a6de6e61e64c6 (diff) | |
parent | dddb6f3357f1b9bbe52759b3bd1f3056aafcb168 (diff) | |
download | glance_store-stable/kilo.tar.gz |
Merge "Catch InvalidURL when requesting store size" into stable/kilokilo-eolstable/kilo
-rw-r--r-- | glance_store/_drivers/http.py | 9 | ||||
-rw-r--r-- | tests/unit/test_http_store.py | 21 |
2 files changed, 30 insertions, 0 deletions
diff --git a/glance_store/_drivers/http.py b/glance_store/_drivers/http.py index a2073de..754ed71 100644 --- a/glance_store/_drivers/http.py +++ b/glance_store/_drivers/http.py @@ -89,6 +89,15 @@ class StoreLocation(glance_store.location.StoreLocation): if netloc == '': LOG.info(_("No address specified in HTTP URL")) raise exceptions.BadStoreUri(uri=uri) + else: + # IPv6 address has the following format [1223:0:0:..]:<some_port> + # we need to be sure that we are validating port in both IPv4,IPv6 + delimiter = "]:" if netloc.count(":") > 1 else ":" + host, dlm, port = netloc.partition(delimiter) + # if port is present in location then validate port format + if port and not port.isdigit(): + raise exceptions.BadStoreUri(uri=uri) + self.netloc = netloc self.path = path diff --git a/tests/unit/test_http_store.py b/tests/unit/test_http_store.py index 5204f61..66fe23f 100644 --- a/tests/unit/test_http_store.py +++ b/tests/unit/test_http_store.py @@ -150,6 +150,27 @@ class TestHttpStore(base.StoreBaseTest, loc = location.get_location_from_uri(uri, conf=self.conf) self.assertRaises(exceptions.NotFound, self.store.get_size, loc) + def test_http_store_location_initialization(self): + """Test store location initialization from valid uris""" + uris = [ + "http://127.0.0.1:8000/ubuntu.iso", + "http://openstack.com:80/ubuntu.iso", + "http://[1080::8:800:200C:417A]:80/ubuntu.iso" + ] + for uri in uris: + location.get_location_from_uri(uri) + + def test_http_store_location_initialization_with_invalid_url(self): + """Test store location initialization from incorrect uris.""" + incorrect_uris = [ + "http://127.0.0.1:~/ubuntu.iso", + "http://openstack.com:some_text/ubuntu.iso", + "http://[1080::8:800:200C:417A]:some_text/ubuntu.iso" + ] + for uri in incorrect_uris: + self.assertRaises(exceptions.BadStoreUri, + location.get_location_from_uri, uri) + def test_http_get_raises_remote_service_unavailable(self): """Test http store raises RemoteServiceUnavailable.""" uri = "http://netloc/path/to/file.tar.gz" |