use crypto.py to split test archive in test_encryption.py
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Mon, 24 Apr 2017 10:06:46 +0000 (12:06 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
This again verifies individual decryptability of objects in the
PDT archive.

deltatar/crypto.py
testing/test_encryption.py

index 3339878..cec61e0 100755 (executable)
@@ -757,6 +757,7 @@ PDTCRYPT_SPLITNAME = "pdtcrypt-object-%d.bin"
 
 PDTCRYPT_VERBOSE   = False
 PDTCRYPT_STRICTIVS = False
+PDTCRYPT_OVERWRITE = False
 PDTCRYPT_BLOCKSIZE = 1 << 12
 PDTCRYPT_SINK      = 0
 PDTCRYPT_SOURCE    = 1
@@ -843,8 +844,12 @@ def depdtcrypt (mode, pw, ins, outs):
             assert total_obj > 0
             fname = PDTCRYPT_SPLITNAME % total_obj
             try:
-                outfd = os.open (fname, os.O_CREAT | os.O_EXCL | os.O_WRONLY,
-                                 0o600, dir_fd=outs)
+                oflags = os.O_CREAT | os.O_WRONLY
+                if PDTCRYPT_OVERWRITE is True:
+                    oflags |= os.O_TRUNC
+                else:
+                    oflags |= os.O_EXCL
+                outfd = os.open (fname, oflags, 0o600, dir_fd=outs)
                 if PDTCRYPT_VERBOSE is True:
                     noise ("PDT: new output file %s → %d" % (fname, outfd))
             except FileExistsError as exn:
@@ -1039,6 +1044,10 @@ def parse_argv (argv):
         elif arg in [ "-o", "--out", "--dest", "--sink" ]:
             outsspec = next (argvi)
             if PDTCRYPT_VERBOSE is True: noise ("PDT: decrypt to %s" % outsspec)
+        elif arg in [ "-f", "--force" ]:
+            global PDTCRYPT_OVERWRITE
+            PDTCRYPT_OVERWRITE = True
+            if PDTCRYPT_VERBOSE is True: noise ("PDT: overwrite existing files")
         elif arg in [ "-S", "--split" ]:
             mode |= PDTCRYPT_SPLIT
             if PDTCRYPT_VERBOSE is True: noise ("PDT: split files")
index 5088ab2..9dafdc1 100644 (file)
@@ -85,8 +85,8 @@ class EncryptionTest(BaseTest):
     def test_cli_multiple_files_decrypt(self):
         """
         Create a tar file with multiple files inside, using concat
-        compression and encryption mode. Then decrypt with ``crypto.py``,
-        decompress it with zcat and untar it with gnu tar.
+        compression and encryption mode. Then decrypt and split with
+        ``crypto.py``, decompress it with zcat and untar it with gnu tar.
         """
 
         # create sample data
@@ -115,11 +115,14 @@ class EncryptionTest(BaseTest):
             os.unlink(k)
 
         assert os.path.exists("sample.tar.gz.pdtcrypt")
-        ret = os.system("python3 -s ./deltatar/crypto.py key <sample.tar.gz.pdtcrypt >sample.tar.gz")
+        ret = os.system("python3 -s ./deltatar/crypto.py key --split "
+                        "-i sample.tar.gz.pdtcrypt -o .")
         assert ret == 0
-        assert os.path.exists("sample.tar.gz")
-        os.system("zcat sample.tar.gz 2>/dev/null > sample.tar")
-        os.system("tar xf sample.tar")
+        for i in range (len (hash)):
+            fname = "pdtcrypt-object-%d.bin" % (i + 1)
+            assert os.path.exists(fname)
+            os.system("zcat '%s' 2>/dev/null > sample.tar" % fname)
+            os.system("tar xf sample.tar")
 
         for key, value in hash.items():
             assert os.path.exists(key)