test recovery behavior with traling data
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 11 Aug 2017 09:39:42 +0000 (11:39 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:09 +0000 (13:34 +0200)
runtests.py
testing/test_recover.py

index 6e25aba..d8128b8 100755 (executable)
@@ -31,7 +31,10 @@ from testing.test_recover import \
     , RecoverCorruptHeaderGZAESTest \
     , RecoverCorruptEntireHeaderTest \
     , RecoverCorruptEntireHeaderGZTest \
-    , RecoverCorruptEntireHeaderGZAESTest
+    , RecoverCorruptEntireHeaderGZAESTest \
+    , RecoverCorruptTrailingDataTest \
+    , RecoverCorruptTrailingDataGZTest \
+    , RecoverCorruptTrailingDataGZAESTest
 from testing.test_rescue_tar import RescueTarTest
 from testing.test_encryption import EncryptionTest
 from testing.test_deltatar import (DeltaTarTest, DeltaTar2Test,
@@ -75,6 +78,9 @@ if __name__ == "__main__":
                          , RecoverCorruptEntireHeaderTest
                          , RecoverCorruptEntireHeaderGZTest
                          , RecoverCorruptEntireHeaderGZAESTest
+                         , RecoverCorruptTrailingDataTest
+                         , RecoverCorruptTrailingDataGZTest
+                         , RecoverCorruptTrailingDataGZAESTest
                          ]:
                 try:
                     t = group (n)
index 8d7d5b9..e062980 100644 (file)
@@ -118,6 +118,15 @@ def corrupt_payload_start (_, fname, compress, encrypt):
         flip_bits (fname, tarfile.BLOCKSIZE + 1)
 
 
+def corrupt_trailing_data (_, fname, compress, encrypt):
+    """
+    Modify the byte following the object header structure of the format.
+    """
+    junk = os.urandom (42)
+    fd = os.open (fname, os.O_WRONLY | os.O_APPEND)
+    os.write (fd, junk)
+    os.close (fd)
+
 
 ###############################################################################
 ## tests                                                                     ##
@@ -326,3 +335,32 @@ class RecoverCorruptEntireHeaderGZAESTest (RecoverTest):
     CORRUPT     = corrupt_entire_header
     MISMATCHES  = 0
 
+
+class RecoverCorruptTrailingDataTest (RecoverTest):
+    # plain Tar is indifferent against traling data and the results
+    # are consistent
+    COMPRESSION = None
+    PASSWORD    = None
+    FAILURES    = 0
+    CORRUPT     = corrupt_trailing_data
+    MISMATCHES  = 0
+
+
+class RecoverCorruptTrailingDataGZTest (RecoverTest):
+    # reading past the final object will cause decompression failure;
+    # all objects except for the last survive unharmed though
+    COMPRESSION = "#gz"
+    PASSWORD    = None
+    FAILURES    = 1
+    CORRUPT     = corrupt_trailing_data
+    MISMATCHES  = 0
+
+
+class RecoverCorruptTrailingDataGZAESTest (RecoverTest):
+    COMPRESSION = "#gz"
+    PASSWORD    = TEST_PASSWORD
+    FAILURES    = 0
+    CORRUPT     = corrupt_trailing_data
+    MISMATCHES  = 0
+
+