@@ -42,6 +42,16 @@ assert_file_contains() {
4242 fi
4343}
4444
45+ assert_file_not_contains () {
46+ local file=" $1 "
47+ local pattern=" $2 "
48+ local description=" $3 "
49+
50+ if [[ ! -f " ${file} " ]] || grep -Eq -- " ${pattern} " " ${file} " ; then
51+ fail " ${description} "
52+ fi
53+ }
54+
4555create_fake_binaries () {
4656 local bin_dir=" $1 "
4757
@@ -93,6 +103,39 @@ for argument in "$@"; do
93103 fi
94104done
95105
106+ case "${FAKE_SCAN_EXIT:-0}" in
107+ 0)
108+ printf '%s\n' \
109+ "${TEST_STATE}/work/clean-one.php: OK" \
110+ "${TEST_STATE}/work/clean-two.php: OK" \
111+ '' \
112+ '----------- SCAN SUMMARY -----------' \
113+ 'Infected files: 0' \
114+ 'Time: 0.010 sec (0 m 0 s)'
115+ ;;
116+ 1)
117+ printf '%s\n' \
118+ "${TEST_STATE}/work/clean.php: OK" \
119+ "${TEST_STATE}/work/infected.php: Eicar-Test-Signature FOUND" \
120+ '' \
121+ '----------- SCAN SUMMARY -----------' \
122+ 'Infected files: 1' \
123+ 'Time: 0.010 sec (0 m 0 s)'
124+ ;;
125+ 2)
126+ printf '%s\n' \
127+ "${TEST_STATE}/work/unreadable.php: File path check failure: Permission denied. ERROR" \
128+ '' \
129+ '----------- SCAN SUMMARY -----------' \
130+ 'Infected files: 0' \
131+ 'Total errors: 1' \
132+ 'Time: 0.010 sec (0 m 0 s)'
133+ ;;
134+ 3)
135+ printf '%s\n' 'ERROR: Could not connect to clamd.'
136+ ;;
137+ esac
138+
96139exit "${FAKE_SCAN_EXIT:-0}"
97140EOF
98141
@@ -136,20 +179,33 @@ run_scan_case() {
136179
137180run_scan_case clean 0 success 0
138181assert_file_contains " ${TEST_DIR} /clean/clamdscan.calls" ' --multiscan' ' clean scan requests multiscan'
139- assert_file_contains " ${TEST_DIR} /clean/clamdscan.calls" ' --infected' ' clean scan only reports infected files '
182+ assert_file_not_contains " ${TEST_DIR} /clean/clamdscan.calls" ' --infected' ' clean scan captures clean results for counting '
140183assert_file_contains " ${TEST_DIR} /clean/clamd.conf" ' ExcludePath .*\\.composer-cache' ' composer cache exclusion is configured for clamd'
141184assert_file_contains " ${TEST_DIR} /clean/clamd.conf" ' ExcludePath .*node_modules_cache' ' node modules cache exclusion is configured for clamd'
185+ assert_file_contains " ${TEST_DIR} /clean/output" ' Scanned files: 2' ' clean scan reports the scanned file count'
186+ assert_file_not_contains " ${TEST_DIR} /clean/output" ' clean-(one|two)\.php: OK' ' clean scan suppresses clean file paths'
142187assert_file_contains " ${TEST_DIR} /clean/output" ' Clean - no viruses found' ' clean scan reports success'
143188[[ -f " ${TEST_DIR} /clean/clamd.stopped" ]] || fail ' clean scan stops the temporary daemon'
144189
145190run_scan_case infected 1 success 1
191+ assert_file_contains " ${TEST_DIR} /infected/output" ' Scanned files: 2' ' infected scan reports the scanned file count'
192+ assert_file_contains " ${TEST_DIR} /infected/output" ' infected\.php: Eicar-Test-Signature FOUND' ' infected scan reports the infected file'
193+ assert_file_not_contains " ${TEST_DIR} /infected/output" ' clean\.php: OK' ' infected scan suppresses clean file paths'
146194assert_file_contains " ${TEST_DIR} /infected/output" ' INFECTED FILE FOUND' ' infected scan reports malware'
147195[[ -f " ${TEST_DIR} /infected/clamd.stopped" ]] || fail ' infected scan stops the temporary daemon'
148196
149197run_scan_case scan_error 2 success 0
198+ assert_file_contains " ${TEST_DIR} /scan_error/output" ' Scanned files: 0' ' scan errors report zero successful file scans'
199+ assert_file_contains " ${TEST_DIR} /scan_error/output" ' unreadable\.php: .* ERROR' ' scan errors remain visible'
150200assert_file_contains " ${TEST_DIR} /scan_error/output" ' Virus scanner internal error' ' scan errors remain fail-open'
151201[[ -f " ${TEST_DIR} /scan_error/clamd.stopped" ]] || fail ' scan errors stop the temporary daemon'
152202
203+ run_scan_case scan_error_without_summary 3 success 0
204+ assert_file_contains " ${TEST_DIR} /scan_error_without_summary/output" ' Scanned files: 0' ' scan errors without a summary report zero successful file scans'
205+ assert_file_contains " ${TEST_DIR} /scan_error_without_summary/output" ' ERROR: Could not connect to clamd' ' scan errors without a summary remain visible'
206+ assert_file_contains " ${TEST_DIR} /scan_error_without_summary/output" ' Virus scanner internal error' ' scan errors without a summary remain fail-open'
207+ [[ -f " ${TEST_DIR} /scan_error_without_summary/clamd.stopped" ]] || fail ' scan errors without a summary stop the temporary daemon'
208+
153209run_scan_case startup_error 0 failure 0
154210assert_file_contains " ${TEST_DIR} /startup_error/output" ' Virus scanner internal error' ' daemon startup errors remain fail-open'
155211
0 commit comments