From 64794b20d32525016dd718f2242dc84342ee7fa6 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 4 May 2021 17:08:01 +0200 Subject: [PATCH] test/util_path: add basic utility function test --- test/mod/test_util_path.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/mod/test_util_path.py diff --git a/test/mod/test_util_path.py b/test/mod/test_util_path.py new file mode 100644 index 00000000..537b0375 --- /dev/null +++ b/test/mod/test_util_path.py @@ -0,0 +1,20 @@ +# +# Tests for the 'osbuild.util.path' module +# +import os + +from osbuild.util import path + +def test_in_tree(): + cases = { + ("/tmp/file", "/tmp", False): True, # Simple, non-existent + ("/etc", "/", True): True, # Simple, should exist + ("/tmp/../../file", "/tmp", False): False, # Relative path escape + ("/very/fake/directory/and/file", "/very", False): True, # non-existent, OK + ("/very/fake/directory/and/file", "/very", True): False, # non-existent, not-OK + ("../..", os.path.abspath("."), False): False, # Relative path escape from cwd + (".", os.path.abspath("../.."), False): True, # cwd inside parent of parent + } + + for args, expected in cases.items(): + assert path.in_tree(*args) == expected, args