diff mbox series

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

Message ID 4b2c2392baefe7c41b0841c7ca41a7fb708e88ce.1721341885.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 18, 2024, 10:33 p.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 | 38 +++++++++++++++++++++
 1 file changed, 38 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..0c53cc2f6f72
--- /dev/null
+++ b/tests/misc-tests/065-image-filename/test.sh
@@ -0,0 +1,38 @@ 
+#!/bin/bash
+# Verify "btrfs-image -s" sanitizes the filenames correctly
+
+source "$TEST_TOP/common" || exit
+source "$TEST_TOP/common.convert" || exit
+
+setup_root_helper
+prepare_test_dev
+
+declare -a filenames=("%%top_secret%%" "@@secret@@" "||confidential||")
+tmp=$(_mktemp "image-filename")
+
+run_check_mkfs_test_dev
+run_check_mount_test_dev
+for i in ${filenames[@]}; do
+	run_check $SUDO_HELPER touch "$TEST_MNT/$i"
+done
+run_check_umount_test_dev
+
+run_check "$TOP/btrfs-image" "$TEST_DEV" "$tmp"
+_log "strings found inside the regular dump:"
+strings "$tmp" >> "$RESULTS"
+for i in ${filenames[@]}; do
+	if ! grep -q "$i" "$tmp"; then
+		rm -f -- "$tmp"
+		_fail "regular dump sanitized the filenames"
+	fi
+done
+run_check "$TOP/btrfs-image" -s "$TEST_DEV" "$tmp"
+_log "strings found inside the sanitize dump:"
+strings "$tmp" >> "$RESULTS"
+for i in ${filenames[@]}; do
+	if grep -q "$i" "$tmp"; then
+		rm -f -- "$tmp"
+		_fail "filenames not properly sanitized"
+	fi
+done
+rm -f -- "$tmp"