diff mbox series

[4/4] btrfs-progs: misc-tests: add a test case for filename sanitization

Message ID 47cb2c90e2786db2830fe6ef5042f6c9b2e97278.1720415116.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: fix the filename sanitization of btrfs-image | expand

Commit Message

Qu Wenruo July 8, 2024, 5:14 a.m. UTC
This test case checks:

- If a regular btrfs-image dump has the unsanitized filenames
- If a sanitized btrfs-image dump has filenames properly censored

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/misc-tests/065-image-filename/test.sh | 33 +++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100755 tests/misc-tests/065-image-filename/test.sh
diff mbox series

Patch

diff --git a/tests/misc-tests/065-image-filename/test.sh b/tests/misc-tests/065-image-filename/test.sh
new file mode 100755
index 000000000000..a9567ad672ef
--- /dev/null
+++ b/tests/misc-tests/065-image-filename/test.sh
@@ -0,0 +1,33 @@ 
+#!/bin/bash
+# Verify "btrfs-image -s" sanitize the filenames correctly
+
+source "$TEST_TOP/common" || exit
+source "$TEST_TOP/common.convert" || exit
+
+setup_root_helper
+prepare_test_dev
+
+tmp=$(mktemp --tmpdir btrfs-progs-image-filename.XXXXXX)
+
+run_check_mkfs_test_dev
+run_check_mount_test_dev
+run_check $SUDO_HELPER touch "$TEST_MNT/top_secret_filename"
+run_check $SUDO_HELPER touch "$TEST_MNT/secret_filename"
+run_check $SUDO_HELPER touch "$TEST_MNT/confidential_filename"
+run_check_umount_test_dev
+
+run_check "$TOP/btrfs-image" "$TEST_DEV" "$tmp"
+echo "strings found inside the regular dump:" >> "$RESULTS"
+strings "$tmp" >> "$RESULTS"
+if ! strings "$tmp" | grep -q _filename "$tmp"; then
+	rm -f -- "$tmp"
+	_fail "regular dump sanitized the filenames"
+fi
+run_check "$TOP/btrfs-image" -s "$TEST_DEV" "$tmp"
+echo "strings found inside the sanitized dump:" >> "$RESULTS"
+strings "$tmp" >> "$RESULTS"
+if strings "$tmp" | grep -q _filename "$tmp"; then
+	rm -f -- "$tmp"
+	_fail "filenames not properly sanitized"
+fi
+rm -f -- "$tmp"