diff --git a/glance_store/_drivers/http.py b/glance_store/_drivers/http.py index f5399056..20a5d222 100644 --- a/glance_store/_drivers/http.py +++ b/glance_store/_drivers/http.py @@ -90,6 +90,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:..]: + # 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/glance_store/tests/unit/test_http_store.py b/glance_store/tests/unit/test_http_store.py index 6ab4db62..4edf8933 100644 --- a/glance_store/tests/unit/test_http_store.py +++ b/glance_store/tests/unit/test_http_store.py @@ -152,6 +152,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"