Skip to content

Commit

Permalink
Add regression test for --plain-text-names
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Jun 12, 2023
1 parent 7972382 commit 9dc5167
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
Binary file added test/reference/4-plain-text-names/abcdef/364.bin
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions test/reference/4-plain-text-names/ä.bin
@@ -0,0 +1,2 @@
�G��� KE��(�T����Y�W��g�!U�92�7>�N�'�\�6C]s�
�@�
1 change: 1 addition & 0 deletions test/reference/4-plain-text-names/empty.txt
@@ -0,0 +1 @@
�������v��i
Binary file not shown.
71 changes: 47 additions & 24 deletions test/simple_test.py
Expand Up @@ -563,6 +563,30 @@ def test_time(self):
)


def _compare_directory(self: unittest.TestCase, dir1: str, dir2: str):
listing1 = list_dir_recursive(dir1, relpath=True)
listing2 = list_dir_recursive(dir2, relpath=True)

self.assertEqual(
listing1,
listing2,
f"{dir1} and {dir2} differ in file names",
)

for fn in listing1:
fn1 = os.path.join(dir1, fn)
fn2 = os.path.join(dir2, fn)

if os.path.isdir(fn1) and os.path.isdir(fn2):
continue

with open(fn1, "rb") as f:
data1 = f.read()
with open(fn2, "rb") as f:
data2 = f.read()
self.assertEqual(data1, data2, f"{fn1} and {fn2} differ in contents")


@parametrize(
tuple(itertools.product(range(1, 5), ALL_PBKDFS, SecretInputMode, [False, True]))
)
Expand Down Expand Up @@ -591,36 +615,35 @@ def test_regression(self):
config_filename=config_filename,
)
try:
self.compare_directory(
os.path.join(reference_data_dir, "plain"), mount_point
_compare_directory(
self, os.path.join(reference_data_dir, "plain"), mount_point
)
finally:
securefs_unmount(p, mount_point)

def compare_directory(self, dir1, dir2):
listing1 = list_dir_recursive(dir1, relpath=True)
listing2 = list_dir_recursive(dir2, relpath=True)

self.assertEqual(
listing1,
listing2,
f"{dir1} and {dir2} differ in file names",
)

for fn in listing1:
fn1 = os.path.join(dir1, fn)
fn2 = os.path.join(dir2, fn)

if os.path.isdir(fn1) and os.path.isdir(fn2):
continue
return RegressionTestBase

with open(fn1, "rb") as f:
data1 = f.read()
with open(fn2, "rb") as f:
data2 = f.read()
self.assertEqual(data1, data2, f"{fn1} and {fn2} differ in contents")

return RegressionTestBase
class PlainTextNamesRegressionTestCase(unittest.TestCase):
def test_regression(self):
mount_point = get_mount_point()
config_filename = os.path.join(
reference_data_dir, "4", ".securefs.argon2id.KEYFILE2.json"
)
p = securefs_mount(
os.path.join(reference_data_dir, "4-plain-text-names"),
mount_point,
password=None,
keyfile=os.path.join(reference_data_dir, "keyfile"),
config_filename=config_filename,
plain_text_names=True,
)
try:
_compare_directory(
self, os.path.join(reference_data_dir, "plain"), mount_point
)
finally:
securefs_unmount(p, mount_point)


def list_dir_recursive(dirname: str, relpath=False) -> Set[str]:
Expand Down

0 comments on commit 9dc5167

Please sign in to comment.