Skip to content

tests: verify pcap_filename on alert and flow events - v2#2932

Closed
oferda4 wants to merge 1 commit intoOISF:masterfrom
oferda4:test/eve-pcap-filename-alert-and-flow
Closed

tests: verify pcap_filename on alert and flow events - v2#2932
oferda4 wants to merge 1 commit intoOISF:masterfrom
oferda4:test/eve-pcap-filename-alert-and-flow

Conversation

@oferda4
Copy link
Copy Markdown

@oferda4 oferda4 commented Feb 21, 2026

Add a regression test that checks the pcap_filename field is present and correct in EVE JSON output for both alert events (packet-based) and flow events (non-packet-based).

These two code paths use different sources for the filename in OutputJsonBuilderBuffer: per-packet pfv->filename when a packet is available, and the global PcapFileGetFilename() fallback for flow/netflow events where no packet exists.

Previous PR: #2927

v2:
- Fix recursive test and readme.

Redmine ticket: https://redmine.openinfosecfoundation.org/issues/5255
Suricata PR: OISF/suricata#15116

match:
event_type: alert
alert.signature_id: 2200005
pcap_filename.__endswith: "ip_secopt.pcap"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What else could we get since there is only one pcap in this test ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what you mean. We want to test the field shows the correct value. If you mean as why using _endswith it's because the field contains the absolute path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test pcap-filename-recursive has 2 packs, so I see we can be wrong for pcap_filename

But how could we be wrong when there is only one pcap like in this test ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is just a sanity the filename is properly added. Do you think the test is redundant?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe indeed. What does it cover that pcap-filename-recursive does not cover ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So regarding code paths it doesn't add any more coverage. It's just giving a simpler test for the basic functionality (that works even from older versions) to be easier to debug rather the complex recursive test.
But I don't mind to remove the test entirely if we are trying to be more strict on tests usage.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I would say let's keep it, thanks

Add three suricata-verify tests that together cover all code paths in
the pcap_filename output for pcap-file mode:

pcap-filename-alert-and-flow: single pcap, verifies pcap_filename is
present in alert events (p != NULL path in OutputJsonBuilderBuffer) and
flow events (p == NULL, falls back to FlowGetPcapFileVars).

pcap-filename-pseudo-pkts: verifies pcap_filename is present in fileinfo
events generated by stream pseudo-packets (PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH),
which carry pcap_v.pfv propagated from the flow.

pcap-filename-recursive: two pcap files fed with --pcap-file-recursive.
alert.pcap is processed first; http.pcap is processed last. Verifies that
the flow event for the alert.pcap connection still reports alert.pcap
(via the per-flow pfv), not the stale global that has advanced to http.pcap.
This is the primary race-condition regression test for #5255.

Ticket: #5255
@oferda4 oferda4 force-pushed the test/eve-pcap-filename-alert-and-flow branch from f9b8f46 to 69bdcb6 Compare March 27, 2026 12:29
count: 1
match:
event_type: flow
pcap_filename.__endswith: "http.pcap"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the stats event as well ?

Copy link
Copy Markdown
Author

@oferda4 oferda4 Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - I've added stats coverage to the single-pcap test (pcap-filename-alert-and-flow). Stats events hit the p == NULL, f == NULL global fallback path in OutputJsonBuilderBuffer, which was the only path without test coverage. With one pcap the global is unambiguous so it's a clean verification.

- --pcap-file-recursive

checks:
# Race-condition regression: alert.pcap is processed FIRST; http.pcap is
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is alert processed first ? Alphabetical order ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in source-pcap-file-directory-helper.c sorts by modification time (CompareTimes), not alphabetically. After a git checkout, both alert.pcap and http.pcap get the same mtime (I verified they're identical), so the order is actually determined by readdir() - which is filesystem-dependent and not guaranteed.

However, the test assertions are order-independent: they just verify that each event has the correct pcap_filename regardless of which pcap was processed first. The comment here is misleading because it claims a specific processing order. I'll update the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires suricata pr Depends on a PR in Suricata

Development

Successfully merging this pull request may close these issues.

2 participants