Skip to content

Commit 23934e5

Browse files
committed
fix: count files from clamd daemon log
1 parent 181ad36 commit 23934e5

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

scripts/virus-scan

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ LocalSocket ${runtime_dir}/clamd.sock
6868
FixStaleSocket yes
6969
DatabaseDirectory ${database_dir}
7070
Foreground yes
71+
LogClean yes
7172
PidFile ${runtime_dir}/clamd.pid
7273
ExcludePath (^|/)\.composer-cache(/|$)
7374
ExcludePath (^|/)node_modules_cache(/|$)
@@ -108,7 +109,7 @@ scanned_files="$(
108109
awk '
109110
/: OK$/ || / FOUND$/ { count++ }
110111
END { print count + 0 }
111-
' "${scan_report}"
112+
' "${clamd_log}"
112113
)"
113114

114115
awk -v scanned_files="${scanned_files}" '

tests/test-virus-scan.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ done
8080
8181
cp "${config_file}" "${TEST_STATE}/clamd.conf"
8282
printf '%s\n' "$$" > "${TEST_STATE}/clamd.pid"
83+
84+
case "${FAKE_SCAN_EXIT:-0}" in
85+
0)
86+
printf '%s\n' \
87+
"${TEST_STATE}/work/clean-one.php: OK" \
88+
"${TEST_STATE}/work/clean-two.php: OK"
89+
;;
90+
1)
91+
printf '%s\n' \
92+
"${TEST_STATE}/work/clean.php: OK" \
93+
"${TEST_STATE}/work/infected.php: Eicar-Test-Signature FOUND"
94+
;;
95+
2)
96+
printf '%s\n' \
97+
"${TEST_STATE}/work/unreadable.php: Permission denied. ERROR"
98+
;;
99+
esac
100+
83101
trap 'touch "${TEST_STATE}/clamd.stopped"; exit 0' TERM INT
84102
while :; do
85103
sleep 0.05
@@ -106,16 +124,14 @@ done
106124
case "${FAKE_SCAN_EXIT:-0}" in
107125
0)
108126
printf '%s\n' \
109-
"${TEST_STATE}/work/clean-one.php: OK" \
110-
"${TEST_STATE}/work/clean-two.php: OK" \
127+
"${TEST_STATE}/work: OK" \
111128
'' \
112129
'----------- SCAN SUMMARY -----------' \
113130
'Infected files: 0' \
114131
'Time: 0.010 sec (0 m 0 s)'
115132
;;
116133
1)
117134
printf '%s\n' \
118-
"${TEST_STATE}/work/clean.php: OK" \
119135
"${TEST_STATE}/work/infected.php: Eicar-Test-Signature FOUND" \
120136
'' \
121137
'----------- SCAN SUMMARY -----------' \
@@ -180,6 +196,7 @@ run_scan_case() {
180196
run_scan_case clean 0 success 0
181197
assert_file_contains "${TEST_DIR}/clean/clamdscan.calls" '--multiscan' 'clean scan requests multiscan'
182198
assert_file_not_contains "${TEST_DIR}/clean/clamdscan.calls" '--infected' 'clean scan captures clean results for counting'
199+
assert_file_contains "${TEST_DIR}/clean/clamd.conf" '^LogClean yes$' 'clean file results are enabled in the private daemon log'
183200
assert_file_contains "${TEST_DIR}/clean/clamd.conf" 'ExcludePath .*\\.composer-cache' 'composer cache exclusion is configured for clamd'
184201
assert_file_contains "${TEST_DIR}/clean/clamd.conf" 'ExcludePath .*node_modules_cache' 'node modules cache exclusion is configured for clamd'
185202
assert_file_contains "${TEST_DIR}/clean/output" 'Scanned files: 2' 'clean scan reports the scanned file count'

0 commit comments

Comments
 (0)