Commit f67f71ed authored by Kirill Smelkov's avatar Kirill Smelkov

Don't crash on URLs with %20 inside

Without the fix configparser complains about bad interpolation:

    configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%20Latest%20Stable/2.0.10/zabbix-2.0.10.tar.gz'
parent dbba5cde
...@@ -78,14 +78,14 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo ...@@ -78,14 +78,14 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo
recipe = part['recipe'] recipe = part['recipe']
if recipe == 'slapos.recipe.cmmi': if recipe == 'slapos.recipe.cmmi':
addbom(part['url'], '') # XXX detect kind? addbom(geturl(part), '') # XXX detect kind?
elif recipe == 'slapos.recipe.build': elif recipe == 'slapos.recipe.build':
# slapos.recipe.build is often used in creative ways to actually # slapos.recipe.build is often used in creative ways to actually
# run python code during the build. Let's detect this via lack of # run python code during the build. Let's detect this via lack of
# `url`, but be careful and explicitly list name of such sections # `url`, but be careful and explicitly list name of such sections
# not to miss a normal part. # not to miss a normal part.
url = part.get('url', None) url = geturl(part, None)
if url is None: if url is None:
# [gcc] is generic section to either use system gcc, or install one via slapos # [gcc] is generic section to either use system gcc, or install one via slapos
# the one installed via slapos will come in its own section # the one installed via slapos will come in its own section
...@@ -102,7 +102,7 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo ...@@ -102,7 +102,7 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo
elif recipe == 'slapos.recipe.build:download': elif recipe == 'slapos.recipe.build:download':
# slapos.recipe.build:download is often used to download .conf files, but sometimes it is used to download e.g. binaries # slapos.recipe.build:download is often used to download .conf files, but sometimes it is used to download e.g. binaries
# skip the part, if we can detect that downloaded item is a configuration file # skip the part, if we can detect that downloaded item is a configuration file
url = part['url'] url = geturl(part)
if isconf(url): if isconf(url):
continue continue
...@@ -111,9 +111,9 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo ...@@ -111,9 +111,9 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo
elif recipe.startswith('slapos.recipe.template'): elif recipe.startswith('slapos.recipe.template'):
url = part.get('url', None) url = geturl(part, None)
if url is not None: if url is not None:
if isconf(part['url']): if isconf(url):
continue continue
# NOTE binary is not expected with slapos.recipe.template # NOTE binary is not expected with slapos.recipe.template
raise ValueError('%s uses %s with url that does not look like a .conf file: %s' % (s, recipe, url)) raise ValueError('%s uses %s with url that does not look like a .conf file: %s' % (s, recipe, url))
...@@ -151,6 +151,17 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo ...@@ -151,6 +151,17 @@ def bom_software(installed_software_path): # -> {} name -> PkgInfo
return bom return bom
# geturl returns value of part:url
_missing = object()
def geturl(part, default=_missing):
url = part.get('url', raw=True) # raw because e.g. .../ZABBIX%20Latest%20Stable/...
if url is None:
if default is not _missing:
return default
raise KeyError('section %s has no url' % part)
return url
def bom_node(XXX): def bom_node(XXX):
1/0 1/0
# TODO bom_node should: # TODO bom_node should:
......
...@@ -104,6 +104,15 @@ lxml 4.9.1 https://pypi.org/project/lxml/4.9.1/ ...@@ -104,6 +104,15 @@ lxml 4.9.1 https://pypi.org/project/lxml/4.9.1/
pycurl 7.43.0 https://pypi.org/project/pycurl/7.43.0/ pycurl 7.43.0 https://pypi.org/project/pycurl/7.43.0/
""") """)
# %20 in URL
case1("""\
[zabbix-agent]
recipe = slapos.recipe.cmmi
url = http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.10/zabbix-2.0.10.tar.gz
""", """\
zabbix 2.0.10 http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.10/zabbix-2.0.10.tar.gz
""")
@pytest.mark.parametrize('build,bomok', testv) @pytest.mark.parametrize('build,bomok', testv)
def test_bom_software(tmpdir, build, bomok): def test_bom_software(tmpdir, build, bomok):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment