aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2024-05-10 22:57:11 +0200
committerPádraig Brady <P@draigBrady.com>2024-05-11 11:27:30 +0100
commitb5ce9fb177b87e20c51f062e466b46b5283d02e9 (patch)
tree0746cdde2c362cd1e6983a80bd787295fd4793e4 /tests
parentwc: increase I/O size from 16 KiB to 256KiB (diff)
downloadcoreutils-b5ce9fb177b87e20c51f062e466b46b5283d02e9.tar.gz
coreutils-b5ce9fb177b87e20c51f062e466b46b5283d02e9.zip
tests: cksum: add incorrect data to verify --check & --strict
* tests/cksum/cksum-c.sh: Add test cases.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/cksum/cksum-c.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/cksum/cksum-c.sh b/tests/cksum/cksum-c.sh
index aad626607..1cb5e645f 100755
--- a/tests/cksum/cksum-c.sh
+++ b/tests/cksum/cksum-c.sh
@@ -56,4 +56,33 @@ returns_ 1 cksum -a crc -c CHECKSUMS || fail=1
cksum -a crc 'input' > CHECKSUMS.crc || fail=1
returns_ 1 cksum -c CHECKSUMS.crc || fail=1
+# Check for the error mgmt
+echo 'invalid line' >> CHECKSUMS
+# Exit code is 0 in this case
+cksum --check CHECKSUMS >out 2>&1 || fail=1
+grep '1 line is improperly formatted' out || fail=1
+# But not with --strict
+cksum --strict --check CHECKSUMS >out 2>&1 && fail=1
+grep '1 line is improperly formatted' out || fail=1
+echo "invalid line" >> CHECKSUMS
+# plurial checks
+cksum --strict --check CHECKSUMS >out 2>&1 && fail=1
+grep '2 lines are improperly formatted' out || fail=1
+
+# Inject an incorrect checksum
+invalid_sum='aaaaaaaaaaaaaaaaaaaaaaaaaaaaafdb57c725157cb40b5aee8d937b8351477e'
+echo "SM3 (input) = $invalid_sum" >> CHECKSUMS
+cksum --check CHECKSUMS >out 2>&1 && fail=1
+# with --strict (won't change the result)
+grep '1 computed checksum did NOT match' out || fail=1
+grep 'input: FAILED' out || fail=1
+cksum --check --strict CHECKSUMS >out 2>&1 && fail=1
+
+# With a non existing file
+echo "SM3 (input2) = $invalid_sum" >> CHECKSUMS2
+cksum --check CHECKSUMS2 >out 2>&1 && fail=1
+grep 'input2: FAILED open or read' out || fail=1
+grep '1 listed file could not be read' out || fail=1
+# with --strict (won't change the result)
+cksum --check --strict CHECKSUMS2 >out 2>&1 && fail=1
Exit $fail