From cc552d6edf23f6b7910ced1aa2ac7fdf616e0cee Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 5 Jul 2018 10:50:23 +0200 Subject: [PATCH] add unit test for mishandling access(3) Replace os.access() with a dummy to check deltatar behavior against racey file system checks. --- runtests.py | 3 ++- testing/test_deltatar.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/runtests.py b/runtests.py index 5f4a83e..7da7b7c 100755 --- a/runtests.py +++ b/runtests.py @@ -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 diff --git a/testing/test_deltatar.py b/testing/test_deltatar.py index f16208d..9a0b7d6 100644 --- a/testing/test_deltatar.py +++ b/testing/test_deltatar.py @@ -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 + -- 1.7.1