[PATCH 2/2] fetch2/tests: add test for fixperms option

[email protected]
Newsgroups org.openembedded.lists.bitbake-devel
Message-ID <[email protected]>
From: "sh0127.shin" <[email protected]>

Add a unit test for the 'fixperms' SRC_URI parameter introduced
in FetchMethod.unpack().

The test creates a tar.gz archive containing a directory with
restrictive permissions (0o644, no execute bit), then verifies
that unpacking with fixperms=1:

  1. Successfully extracts files inside the restrictive directory.
  2. Restores the execute bit on the directory via chmod -R +X.

Signed-off-by: sh0127.shin <[email protected]>
---
 lib/bb/tests/fetch.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index a1e4b45f8..0bf6e6983 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -876,6 +876,37 @@ class FetcherLocalTest(FetcherTest):
             with self.subTest(striplevel=repr(value)):
                 self.assertInvalidStriplevel(value)
 
+    def test_local_fixperms(self):
+        """Test that fixperms=1 allows extraction of archives with restrictive directory permissions"""
+        import tarfile
+        import stat
+
+        # Create a tar archive with a directory having restrictive permissions (drw-r--r--)
+        archive_path = os.path.join(self.localsrcdir, 'archive_fixperms.tar.gz')
+        with tarfile.open(archive_path, 'w:gz') as tar:
+            # Add a directory with no execute bit (0o644)
+            dirinfo = tarfile.TarInfo(name='restrictive_dir')
+            dirinfo.type = tarfile.DIRTYPE
+            dirinfo.mode = 0o644
+            tar.addfile(dirinfo)
+            # Add a file inside the restrictive directory
+            import io
+            content = b'test content'
+            fileinfo = tarfile.TarInfo(name='restrictive_dir/testfile.txt')
+            fileinfo.size = len(content)
+            fileinfo.mode = 0o644
+            tar.addfile(fileinfo, io.BytesIO(content))
+
+        # Without fixperms, extraction may fail or leave inaccessible dirs
+        # With fixperms=1, chmod -R +X is applied after extraction
+        tree = self.fetchUnpack(['file://archive_fixperms.tar.gz;fixperms=1'])
+        self.assertIn('restrictive_dir/testfile.txt', tree)
+
+        # Verify directory is traversable after fixperms
+        dirpath = os.path.join(self.unpackdir, 'restrictive_dir')
+        dirstat = os.stat(dirpath)
+        self.assertTrue(dirstat.st_mode & stat.S_IXUSR, "Directory should have execute bit after fixperms")
+
     def dummyGitTest(self, suffix):
         # Create dummy local Git repo
         src_dir = tempfile.mkdtemp(dir=self.tempdir,
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.