File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222import os
2323import sys
2424import typing as ty
25+ import urllib .parse
2526
2627from openstack import exceptions as sdk_exceptions
2728from openstack .image import image_signer
@@ -1744,6 +1745,12 @@ def take_action(self, parsed_args):
17441745 "'--method=web-download'"
17451746 )
17461747 raise exceptions .CommandError (msg )
1748+ _parsed = urllib .parse .urlparse (parsed_args .uri )
1749+ if not all ({_parsed .scheme , _parsed .netloc }):
1750+ msg = _ ("'%(uri)s' is not a valid url" )
1751+ raise exceptions .CommandError (
1752+ msg % {'uri' : parsed_args .uri },
1753+ )
17471754 else :
17481755 if parsed_args .uri :
17491756 msg = _ (
Original file line number Diff line number Diff line change @@ -2039,6 +2039,36 @@ def test_import_image__web_download_invalid_options(self):
20392039
20402040 self .image_client .import_image .assert_not_called ()
20412041
2042+ def test_import_image__web_download_invalid_url (self ):
2043+ arglist = [
2044+ self .image .name ,
2045+ '--method' ,
2046+ 'web-download' ,
2047+ '--uri' ,
2048+ 'invalid:1234' ,
2049+ ]
2050+
2051+ verifylist = [
2052+ ('image' , self .image .name ),
2053+ ('import_method' , 'web-download' ),
2054+ ('uri' , 'invalid:1234' ),
2055+ ]
2056+
2057+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
2058+
2059+ exc = self .assertRaises (
2060+ exceptions .CommandError ,
2061+ self .cmd .take_action ,
2062+ parsed_args ,
2063+ )
2064+
2065+ self .assertIn (
2066+ "'invalid:1234' is not a valid url" ,
2067+ str (exc ),
2068+ )
2069+
2070+ self .image_client .import_image .assert_not_called ()
2071+
20422072 def test_import_image__web_download_invalid_image_state (self ):
20432073 self .image .status = 'uploading' # != 'queued'
20442074 arglist = [
You can’t perform that action at this time.
0 commit comments