Repository navigation
Detection Testing and Fixtures
Last reviewed: 2026-11-28 (worked example: canary lab CI run 46219831976, 20 of 20 fixtures matched)
Prerequisites: Detection Engineering index ยท Rule lifecycle ยท Wazuh + Suricata canary lab.
How to build fixtures that prove a rule both fires and stays silent, how to replay them through the real engine, and how to record the result so another person can check it. The Wazuh + Suricata canary lab is the worked example throughout.
Defines four fixture kinds, the PCAP and log replay methods the lab uses, the expectation and evidence manifest formats, and how the tests are wired into CI.
Each rule has at least a positive and a near-miss negative fixture, run by the pinned engine in CI, with an evidence manifest that records the engine version and the hash of every input.
- Adding fixtures for a new or changed rule.
- Adding a new engine or lab to CI.
- Reading a lab's evidence and deciding what it supports.
| Kind | Design rule | Lab example |
|---|---|---|
| Positive | The smallest input that should match, with every field the rule checks |
suricata-http-positive: full TCP handshake, GET /lab-canary-7f3a, Host example.test โ sid 1007001 |
| Negative (near miss) | One small change from the positive, so a loose anchor or a missing field check is caught |
suricata-http-negative uses /lab-canary-7f3b; suricata-dns-negative uses canary-7f3a.example.test.invalid, which fails endswith
|
| Malformed | Input or rule the engine should reject or not match, so error handling is visible | Bad TCP checksum replayed with -k all; a truncated EVE line; a Sigma condition that names a missing identifier; a YARA rule that references an undefined pattern (CompileError E025) |
| Duplicate | The same activity twice, to prove thresholding, frequency or match counting | Two canary flows โ one Suricata alert (threshold: type limit, track by_src, count 1); the same EVE line twice in one logtest session โ 100601 then 100603; two markers โ one YARA-X rule match with $marker matched twice |
Use only synthetic, benign content: RFC 5737 addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24) and names under example.test or .invalid.
A negative fixture for a child rule should still reach the parent. In the lab, wazuh-negative-other-sid carries sid 1007099, and the expected result is built-in rule 86601 at level 3 with no lab rule. That proves the lab rule's own condition rejected it, not that the event never reached Wazuh.
-
Generate, don't capture. The lab's
tools/gen_pcaps.pyis a pure-stdlib, deterministic writer.python3 tools/gen_pcaps.pywrites the PCAPs andpython3 tools/gen_pcaps.py --checkcompares the files on disk with what it would generate. The repository.gitignoreexcludes*.pcap, so the SHA-256 of each generated file is pinned inmanifest.jsoninstead. -
Build complete flows. Stream
midstreamdefaults to false in Suricata 8.0.8, so include SYN, SYN-ACK and ACK. The lab's HTTP flows also carry the response and a FIN/ACK teardown. -
Load only the rule under test. The lab replays with
-r <pcap> -c /etc/suricata/suricata.yaml -S <rules> -l <dir> -k all --runmode single.-Sloads the file exclusively, ignoring the rule files in the YAML, and-k allforces checksum checks so the malformed fixture means something. -
Read alerts from EVE. Compare
alert.signature_idvalues ineve.jsonwith the expected list. An empty list is an expectation too.
Offline replay guidance for real captures stays in Suricata + Zeek.
-
Use the logtest socket or CLI, not a live agent. The lab sends framed JSON requests to
/var/ossec/queue/sockets/logtestinside awazuh/wazuh-manager:4.14.11container that publishes no ports. Each message has a 4-byte little-endian length header, as in upstreamwazuh_logtest.py. -
One line per event. Each EVE fixture line must be one JSON object; the Wazuh
jsondecoder prematch is^{\s*". -
Sessions carry state. Events sent with the same session token share frequency state. The lab's duplicate fixture depends on this: the second identical event in one session fired 100603 (
frequency="2"). Start a new session for independent events. -
Check the type you compare. Logtest returned
output.rule.idas a JSON string (observed), so compare"100601", not100601. -
Chain engines.
chain-suricata-http-to-wazuhfeeds the realeve.jsonalert line that Suricata wrote for the positive PCAP into logtest. This tests the field names Suricata actually emits, not hand-written ones.
The manual CLI procedure for the Kismet, nzyme and honeypot rules is in Wazuh synthetic rule validation.
The expectation manifest is written before the run and never edited to match a result. The lab's manifest.json records:
-
engines: the version, package or image digest, and the exact replay flags; -
rule_filesandlab_rule_ids; -
fixtures: one object per case withid,engine,kind,input,descriptionandexpect; -
sha256: the pinned hash of every rule and fixture file, including the generated PCAPs.
expect is engine specific:
| Engine |
expect keys used |
|---|---|
| Suricata |
returncode, alert_sids
|
| Wazuh |
events: a list of rule_id, level, alert, decoder, or rule_id_not_in for the malformed case |
| Sigma |
returncode, plus stdout (exact golden query) or output_contains
|
| YARA-X |
matching_rules and pattern_match_counts, or compile_error and error_code
|
run_lab.py writes the evidence manifest with --evidence <path> and refuses to overwrite an existing file. The committed evidence/ci-run-46219831976.json has these top-level keys:
| Key | Content |
|---|---|
evidence_origin |
ci-observed only when GITHUB_RUN_ID was set; local runs are local-observed
|
scope_statement |
What the evidence does not cover |
git_commit, ci_run_url, generated_at
|
Where and when the run happened |
runner, engines_selected, engines
|
Python and platform; engine versions, suricata -T result, Wazuh image ID and digest, wazuh-control info, rule-file hash match |
inputs |
One entry per input file: path, observed sha256, expected_sha256 and match
|
results |
Per fixture: expected, observed, status (pass, fail, error or not-run) and problems
|
summary |
Counts, input_hashes_match, complete and overall
|
--require-complete makes the run fail if any fixture was not run, so a missing engine cannot produce a partial pass.
| Piece | Where | Notes |
|---|---|---|
| Offline contract tests | tools/tests/test_detection_lab.py |
Runs in the normal tools/tests discovery. It also fails if the lab README's observed rows disagree with the committed evidence |
| Engine run | .github/workflows/detection-lab.yml |
runs-on: ubuntu-24.04 (ubuntu-latest now resolves to 26.04), pinned action SHAs, permissions: contents: read, path filters on the lab directory |
| Wazuh rule contract | tools/tests/test_wazuh_rule_contracts.py |
Add new rule XML to FILES
|
Put new unit tests in tools/tests/. Tests placed only under IncidentResponse/DetectionEngineering/ are not discovered by guide-tests.yml or make tests. CI does not parse .jsonl files, so fixture JSONL needs its own test.
- Suricata 8.0.8, with only the lab rules loaded, alerts on the two positive PCAPs and stays silent on the near-miss and bad-checksum PCAPs. The threshold
limitsetting turned two canary flows into one alert. - Wazuh 4.14.11 logtest maps the hand-written HTTP and DNS EVE fixture lines to rules 100601 and 100602 at level 10, and the real
eve.jsonalert line Suricata wrote for the HTTP positive PCAP to 100601. The DNS alert is not chained from Suricata output. It fires 100603 on a repeat within one session and does not attribute a truncated line to any Suricata rule. - sigma-cli 4.0.1 accepts the valid rule, rejects the malformed one, refuses to convert for Splunk without a pipeline, and produces the exact golden query with the
sysmonandsplunk_windowspipelines. - YARA-X 1.25.0 matches the canary text, ignores the near miss, counts duplicate pattern matches and rejects the malformed rule.
- The rule file loaded in the container matched the committed file, and every input matched its pinned hash.
- Sensor placement, packet capture on a live network, or packet loss handling.
- Wazuh agents,
<localfile>collection, Filebeat, the indexer, the dashboard or the REST API. - That the converted Splunk query runs or matches anything; no SIEM executes it.
- Behavior on real traffic or real endpoints, or false-positive rates.
- Every malformed-input case; there is one per engine.
- Anything about Zeek, which the lab does not run.
- README.md - Detection Engineering index
- labs/wazuh-suricata/README.md - layout, local run steps and observed results
- labs/wazuh-suricata/manifest.json - expectation manifest
โฌ ๏ธ Detection Engineering index | Master Index | ๐ฏ Role Navigation | Legal Notice
๐ Source: IncidentResponse/DetectionEngineering/testing-and-fixtures.md | โ๏ธ Suggest an edit | โฌ
๏ธ Back to Incident Response
- ๐บ๏ธ Browse by Topic
- ๐ All Repository Files
- ๐งญ Learning Paths
- ๐ Master Guide
- ๐ค Glossary
- โ๏ธ Legal & Disclaimer
๐ Foundations & Learning
๐ก๏ธ Defense & Investigations
- Incident Response
- Open Source Intelligence (OSINT)
- Reverse Engineering
- Operations Security (OPSEC)
- Compliance
โ๏ธ Platforms & Infrastructure
๐ก Hardware, Wireless & Field Projects
- PNWC Cyberdeck
- Hardware Testing
- Hardware Hacking
- Software-Defined Radio
- Wardriving
- uConsole
- Space Security
๐งฐ Assessment & Field Reference
๐ฆ Downloads & Project Resources
๐๏ธ Additional Topics