aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb/tests/utils.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-04-17 15:26:59 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-04-19 13:37:12 +0100
commit56cddeb9e1e4d249f84ccd6ef65db245636e38ea (patch)
treef6ed3b832a0cdf2ddfe3255cb78537dc3bf992ad /lib/bb/tests/utils.py
parent3b8a656d3ccb543c32696229184ebf12237ad38e (diff)
downloadbitbake-56cddeb9e1e4d249f84ccd6ef65db245636e38ea.tar.gz
lib/bb/utils: add safeguard against recursively deleting things we shouldn't
Add some very basic safeguard against recursively deleting paths such as / and /home in the event of bugs or user mistakes. Addresses [YOCTO #7620]. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/tests/utils.py')
-rw-r--r--lib/bb/tests/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/bb/tests/utils.py b/lib/bb/tests/utils.py
index 507de2de3..6e09858e5 100644
--- a/lib/bb/tests/utils.py
+++ b/lib/bb/tests/utils.py
@@ -21,6 +21,7 @@
import unittest
import bb
+import os
class VerCmpString(unittest.TestCase):
@@ -88,3 +89,19 @@ class VerCmpString(unittest.TestCase):
# Check that clearly invalid operator raises an exception
self.assertRaises(bb.utils.VersionStringException, bb.utils.vercmp_string_op, '0', '0', '$')
+
+
+class Path(unittest.TestCase):
+ def test_unsafe_delete_path(self):
+ checkitems = [('/', True),
+ ('//', True),
+ ('///', True),
+ (os.getcwd().count(os.sep) * ('..' + os.sep), True),
+ (os.environ.get('HOME', '/home/test'), True),
+ ('/home/someone', True),
+ ('/home/other/', True),
+ ('/home/other/subdir', False),
+ ('', False)]
+ for arg1, correctresult in checkitems:
+ result = bb.utils._check_unsafe_delete_path(arg1)
+ self.assertEqual(result, correctresult, '_check_unsafe_delete_path("%s") != %s' % (arg1, correctresult))