add unit test for mishandling access(3)
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 5 Jul 2018 08:50:23 +0000 (10:50 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Sat, 1 Feb 2020 14:14:06 +0000 (15:14 +0100)
Replace os.access() with a dummy to check deltatar behavior
against racey file system checks.

runtests.py
testing/test_deltatar.py

index 5f4a83e..7da7b7c 100755 (executable)
@@ -86,7 +86,8 @@ from testing.test_encryption import EncryptionTest
 from testing.test_deltatar import (DeltaTarTest, DeltaTar2Test,
     DeltaTarStreamTest, DeltaTarGzipTest, DeltaTarGzipStreamTest,
     DeltaTarGzipConcatTest, DeltaTarGzipAes128ConcatTest,
-    DeltaTarAes128ConcatTest
+    DeltaTarAes128ConcatTest,
+    DeltaTarFilesystemHandlingTest
     )
 from testing.test_compression_level import suite
 
index f16208d..9a0b7d6 100644 (file)
@@ -52,6 +52,9 @@ class DeltaTarTest(BaseTest):
 
     GIT_DIR = '.git'
 
+    FSTEST = None
+    FSAPI_SAVED = []
+
     def setUp(self):
         '''
         Create base test data
@@ -79,10 +82,16 @@ class DeltaTarTest(BaseTest):
             if not os.path.isdir(self.GIT_DIR):
                 raise Exception('No input directory found: ' + self.GIT_DIR)
 
+        if self.FSTEST is not None:
+            self.FSTEST ()
+
     def tearDown(self):
         '''
-        Remove temporal files created by unit tests and reset globals.
+        Remove temporary files created by unit tests and restore the API
+        functions in *os*.
         '''
+        for att, val in self.FSAPI_SAVED:
+            setattr (os, att, val)
         os.chdir(self.pwd)
         os.system("rm -rf source_dir target_dir source_dir* backup_dir* huge")
         _ = crypto._testing_set_PDTCRYPT_MAX_OBJ_SIZE \
@@ -1868,6 +1877,16 @@ class DeltaTarTest(BaseTest):
         fullpath = os.path.join("source_dir", testpath)
         assert not os.path.exists(fullpath)
 
+
+def fsapi_access_true (self):
+    """
+    Chicanery for testing improper use of the *os* module.
+    """
+    def yes (*_a, **_ka): return True
+    self.FSAPI_SAVED.append (("access", getattr (os, "access")))
+    setattr (os, "access", yes)
+
+
 class DeltaTar2Test(DeltaTarTest):
     '''
     Same as DeltaTar but with specific ":" mode
@@ -1941,3 +1960,9 @@ class DeltaTarAes128ConcatTest(DeltaTarTest):
     ENCRYPTION = ('some magic key', 1)
 
 
+class DeltaTarFilesystemHandlingTest(DeltaTarGzipTest):
+    '''
+    Mess with filesystem APIs.
+    '''
+    FSTEST = fsapi_access_true
+