From 4537001ff6d7f2e76234c249157b88e3ed43f2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 3 Oct 2018 09:45:14 +0200 Subject: [PATCH] fus: Strip protocol from repo path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only local paths are supported currently. As such, `file://` can be stripped, and for anything else we should raise an exception. JIRA: COMPOSE-2996 Signed-off-by: Lubomír Sedlář --- pungi/wrappers/fus.py | 15 +++++++++++++-- tests/test_fus_wrapper.py | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pungi/wrappers/fus.py b/pungi/wrappers/fus.py index 28a03442..3711d192 100644 --- a/pungi/wrappers/fus.py +++ b/pungi/wrappers/fus.py @@ -37,9 +37,9 @@ def get_cmd( cmd = ["fus", "--verbose", "--arch", arch] for idx, repo in enumerate(repos): - cmd.append("--repo=repo-%s,repo,%s" % (idx, repo)) + cmd.append("--repo=repo-%s,repo,%s" % (idx, _prep_path(repo))) for idx, repo in enumerate(lookasides): - cmd.append("--repo=lookaside-%s,lookaside,%s" % (idx, repo)) + cmd.append("--repo=lookaside-%s,lookaside,%s" % (idx, _prep_path(repo))) if platform: cmd.append("--platform=%s" % platform) @@ -52,6 +52,17 @@ def get_cmd( return cmd +def _prep_path(path): + """Strip file:// from the path if present or raise exception for other + protocols. + """ + if "://" in path: + proto, path = path.split("://", 2) + if proto != "file": + raise ValueError("Only repositories on local filesystem are supported.") + return path + + def parse_output(output): """Read output of fus from the given filepath, and return a set of tuples (NVR, arch, flags) and a set of module NSVCs. diff --git a/tests/test_fus_wrapper.py b/tests/test_fus_wrapper.py index c8170110..c62c6478 100644 --- a/tests/test_fus_wrapper.py +++ b/tests/test_fus_wrapper.py @@ -47,6 +47,27 @@ class TestGetCmd(unittest.TestCase): ], ) + def test_strip_file_protocol(self): + cmd = fus.get_cmd("x86_64", ["file:///tmp"], [], [], [], []) + self.assertEqual( + cmd, ["fus", "--verbose", "--arch", "x86_64", "--repo=repo-0,repo,/tmp"] + ) + + def test_fail_on_http_repo(self): + with self.assertRaises(ValueError): + fus.get_cmd("x86_64", ["http:///tmp"], [], [], [], []) + + def test_strip_file_protocol_lookaside(self): + cmd = fus.get_cmd("x86_64", [], ["file:///r"], [], [], []) + self.assertEqual( + cmd, + ["fus", "--verbose", "--arch", "x86_64", "--repo=lookaside-0,lookaside,/r"] + ) + + def test_fail_on_http_repo_lookaside(self): + with self.assertRaises(ValueError): + fus.get_cmd("x86_64", [], ["http:///tmp"], [], [], []) + class TestParseOutput(unittest.TestCase): def setUp(self):