diff mbox series

[9/9] sstatetests.py: Add testing for correct sstate permissions

Message ID 20240306162341.2267587-9-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 7d6eb828e97ad3f27d94efdccd920fb2aef36743
Headers show
Series [1/9] qemurunner.py: Fix error on calls to run_monitor | expand

Commit Message

Richard Purdie March 6, 2024, 4:23 p.m. UTC
From: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>

This patch adds to run_test_sstate_creation so that it also tests
that sstate directories don't accidentally pickup umask permissions
from the user upon creation.

[RP: Python style tweaking]
Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/lib/oeqa/selftest/cases/sstatetests.py | 28 ++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/sstatetests.py b/meta/lib/oeqa/selftest/cases/sstatetests.py
index 56dfcdb0f39..031c2266ace 100644
--- a/meta/lib/oeqa/selftest/cases/sstatetests.py
+++ b/meta/lib/oeqa/selftest/cases/sstatetests.py
@@ -79,7 +79,7 @@  class SStateBase(OESelftestTestCase):
                         result.append(f)
         return result
 
-    # Test sstate files creation and their location
+    # Test sstate files creation and their location and directory perms
     def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True):
         self.config_sstate(temp_sstate_location, [self.sstate_path])
 
@@ -88,6 +88,19 @@  class SStateBase(OESelftestTestCase):
         else:
             bitbake(['-ccleansstate'] + targets)
 
+        # We need to test that the env umask have does not effect sstate directory creation
+        # So, first, we'll get the current umask and set it to something we know incorrect
+        # See: sstate_task_postfunc for correct umask of os.umask(0o002)
+        import os
+        def current_umask():
+            current_umask = os.umask(0)
+            os.umask(current_umask)
+            return current_umask
+
+        orig_umask = current_umask()
+        # Set it to a umask we know will be 'wrong'
+        os.umask(0o022)
+
         bitbake(targets)
         file_tracker = []
         results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
@@ -104,6 +117,19 @@  class SStateBase(OESelftestTestCase):
         else:
             self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker)))
 
+        # Now we'll walk the tree to check the mode and see if things are incorrect.
+        badperms = []
+        for root, dirs, files in os.walk(self.sstate_path):
+            for directory in dirs:
+                if (os.stat(os.path.join(root, directory)).st_mode & 0o777) != 0o775:
+                    badperms.append(os.path.join(root, directory))
+
+        # Return to original umask
+        os.umask(orig_umask)
+
+        if should_pass:
+            self.assertTrue(badperms , msg="Found sstate directories with the wrong permissions: %s (found %s)" % (', '.join(map(str, targets)), str(badperms)))
+
     # Test the sstate files deletion part of the do_cleansstate task
     def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
         self.config_sstate(temp_sstate_location, [self.sstate_path])