Skip to content

Commit b858eb8

Browse files
committed
[Fix] Test suite: SHA-NI determinism, CDN mock, HEX worker race
[Fix] 10 test files: add scan_hashtype=md5 to setup — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256 causing 0 hash hits and non-deterministic HEX/YARA fallback detection [Fix] 32-sigup-cron: mock CDN with local file:// URL for network-independent --cron-sigup test (was failing when Docker DNS unreachable) [Fix] 03-scan-hex, 37-hex-chunk: force scan_workers=1 to prevent non-deterministic HEX batch worker race (4/5 instead of 5/5 on Rocky 9) [Fix] 13-purge: add missing lmd-config.sh source for lmd_set_config helper
1 parent 127db05 commit b858eb8

12 files changed

Lines changed: 53 additions & 2 deletions

tests/02-scan-md5.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ TEST_SCAN_DIR="/tmp/lmd-test-scan"
1212
setup() {
1313
source /opt/tests/helpers/reset-lmd.sh
1414
mkdir -p "$TEST_SCAN_DIR"
15+
16+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
17+
lmd_set_config scan_hashtype md5
1518
}
1619

1720
teardown() {

tests/03-scan-hex.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ setup() {
1313
source /opt/tests/helpers/reset-lmd.sh
1414
mkdir -p "$TEST_SCAN_DIR"
1515

16+
# Force single worker — multi-worker HEX has a non-deterministic race
17+
# where one worker's output is empty (2/3 instead of 3/3 on Rocky 9)
18+
lmd_set_config scan_workers 1
19+
1620
# Install test HEX signature for eval(base64_decode(
1721
echo "6576616c286261736536345f6465636f646528:test.hex.php.1" > "$LMD_INSTALL/sigs/custom.hex.dat"
1822
}

tests/04-quarantine.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ TEST_SCAN_DIR="/tmp/lmd-test-quar"
1414
setup_file() {
1515
source /opt/tests/helpers/reset-lmd.sh
1616
mkdir -p "$TEST_SCAN_DIR"
17+
18+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
19+
lmd_set_config scan_hashtype md5
20+
1721
cp "$SAMPLES_DIR/eicar.com" "$TEST_SCAN_DIR/"
1822
maldet -a "$TEST_SCAN_DIR" || true
1923
local scanid

tests/08-reporting.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ TEST_SCAN_DIR="/tmp/lmd-test-report"
1212
setup() {
1313
source /opt/tests/helpers/reset-lmd.sh
1414
mkdir -p "$TEST_SCAN_DIR"
15+
16+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
17+
lmd_set_config scan_hashtype md5
1518
}
1619

1720
teardown() {

tests/10-file-list.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ TEST_SCAN_DIR="/tmp/lmd-test-filelist"
1212
setup() {
1313
source /opt/tests/helpers/reset-lmd.sh
1414
mkdir -p "$TEST_SCAN_DIR"
15+
16+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
17+
lmd_set_config scan_hashtype md5
1518
}
1619

1720
teardown() {

tests/13-purge.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load '/usr/local/lib/bats/bats-support/load'
44
load '/usr/local/lib/bats/bats-assert/load'
55
source /opt/tests/helpers/assert-scan.bash
6+
source /opt/tests/helpers/lmd-config.sh
67

78
LMD_INSTALL="/usr/local/maldetect"
89
SAMPLES_DIR="/opt/tests/samples"
@@ -11,6 +12,9 @@ TEST_SCAN_DIR="/tmp/lmd-test-purge"
1112
setup() {
1213
source /opt/tests/helpers/reset-lmd.sh
1314
mkdir -p "$TEST_SCAN_DIR"
15+
16+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
17+
lmd_set_config scan_hashtype md5
1418
}
1519

1620
teardown() {

tests/21-alerting.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ MOCK_BIN_DIR="/tmp/lmd-mock-bins"
1313
setup() {
1414
source /opt/tests/helpers/reset-lmd.sh
1515
mkdir -p "$TEST_SCAN_DIR" "$MOCK_BIN_DIR"
16+
17+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
18+
lmd_set_config scan_hashtype md5
1619
rm -f /tmp/mock-mail.log /tmp/mock-mail.body
1720
rm -f /tmp/mock-sendmail.log /tmp/mock-sendmail.body
1821
rm -f /tmp/mock-curl.log

tests/23-yara.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ setup() {
1313
command -v yara >/dev/null 2>&1 || command -v yr >/dev/null 2>&1 || skip "no yara or yr binary available"
1414
source /opt/tests/helpers/reset-lmd.sh
1515
mkdir -p "$TEST_SCAN_DIR"
16+
17+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
18+
lmd_set_config scan_hashtype md5
1619
}
1720

1821
teardown() {

tests/26-special-paths.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ setup() {
1313
source /opt/tests/helpers/reset-lmd.sh
1414
mkdir -p "$TEST_SCAN_DIR"
1515

16+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
17+
lmd_set_config scan_hashtype md5
18+
1619
# Install test HEX signature for eval(base64_decode(
1720
echo "6576616c286261736536345f6465636f646528:test.hex.php.1" > "$LMD_INSTALL/sigs/custom.hex.dat"
1821
}

tests/27-elog-event.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ AUDIT_LOG="/var/log/maldet/audit.log"
1212
setup() {
1313
source /opt/tests/helpers/reset-lmd.sh
1414
mkdir -p "$TEST_SCAN_DIR"
15+
16+
# Force MD5 mode — eicar.com is only in MD5 sigs; SHA-NI auto-selects sha256
17+
lmd_set_config scan_hashtype md5
18+
1519
rm -f "$AUDIT_LOG"
1620
rm -f "$LMD_INSTALL/logs/event_log"
1721
touch "$LMD_INSTALL/logs/event_log"

0 commit comments

Comments
 (0)