diff options
| author | srdusr <[email protected]> | 2024-05-21 22:24:00 +0200 |
|---|---|---|
| committer | srdusr <[email protected]> | 2024-05-21 22:24:00 +0200 |
| commit | fbedc55d5aa861c381701c9f913b34ee7ab57ec4 (patch) | |
| tree | d34c3648b61d417f2a5d8690e0eb4a76bd64c943 /tests/test_mdns.cpp | |
| parent | e0f4c701028aa81026a17cf9ebfb36112184f4bc (diff) | |
| download | packeteer-fbedc55d5aa861c381701c9f913b34ee7ab57ec4.tar.gz packeteer-fbedc55d5aa861c381701c9f913b34ee7ab57ec4.zip | |
Add GUI parity for -c/-a, mDNS/SSH dissectors, and two new fuzz harnesses
GUI parity: checksum_status()/reassembled_http_status() moved out of
main.cpp into a shared wireframe/packet_diagnostics.hpp so the GUI can
show the same -c/-a diagnostics for the selected packet without
duplicating the Ethernet/IPv4/TCP walk. Visually verified under Xvfb
with the same split-segment scenario used to verify -a on the CLI.
Two new L7 dissectors: mDNS (reuses parse_dns outright - RFC 6762
keeps DNS's wire format, just a different port) and SSH's cleartext
identification banner. Live-verified against this machine's real
sshd and a real DNS-wire-format packet sent to port 5353.
Two new fuzz harnesses (fuzz_checksum, fuzz_tcp_reassembly) covering
code added here that the original nine harnesses never
touched. All 12 run clean across ~90M executions with no crashes.
NAMES.md and PLAN.md updated with this round's decisions and naming
candidates.
Diffstat (limited to 'tests/test_mdns.cpp')
| -rw-r--r-- | tests/test_mdns.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_mdns.cpp b/tests/test_mdns.cpp new file mode 100644 index 0000000..cad77e7 --- /dev/null +++ b/tests/test_mdns.cpp @@ -0,0 +1,60 @@ +#include <doctest/doctest.h> + +#include <vector> + +#include "wireframe/l7/mdns.hpp" + +using namespace wireframe::net; + +namespace { + +// A typical mDNS query for a ".local" hostname, id=0 per RFC 6762 +// 18.1's convention for multicast queries. +std::vector<unsigned char> mdns_query() { + return { + 0x00, 0x00, // id = 0 + 0x00, 0x00, // flags: query + 0x00, 0x01, // qdcount = 1 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 6, 'm', 'y', 'h', 'o', 's', 't', 5, 'l', 'o', 'c', 'a', 'l', 0, + 0x00, 0x01, // qtype = A + 0x00, 0x01, // qclass = IN + }; +} + +} // namespace + +TEST_CASE("MdnsDissector claims port 5353") { + MdnsDissector dissector; + CHECK(dissector.port() == kMdnsPort); +} + +TEST_CASE("MdnsDissector summarizes a query without an id= field") { + MdnsDissector dissector; + auto summary = dissector.summarize(mdns_query()); + REQUIRE(summary.has_value()); + CHECK(summary->substr(0, 10) == "mDNS query"); + CHECK(summary->find("myhost.local") != std::string::npos); + CHECK(summary->find("id=") == std::string::npos); +} + +TEST_CASE("MdnsDissector summarizes a response with ancount") { + MdnsDissector dissector; + std::vector<unsigned char> bytes = { + 0x00, 0x00, + 0x84, 0x00, // flags: QR=1 (response), AA=1 + 0x00, 0x00, // qdcount = 0 (typical for an mDNS response) + 0x00, 0x01, // ancount = 1 + 0x00, 0x00, 0x00, 0x00, + }; + auto summary = dissector.summarize(bytes); + REQUIRE(summary.has_value()); + CHECK(summary->substr(0, 13) == "mDNS response"); + CHECK(summary->find("ancount=1") != std::string::npos); +} + +TEST_CASE("MdnsDissector::summarize returns nullopt for a truncated payload") { + MdnsDissector dissector; + std::vector<unsigned char> bytes(5, 0); + CHECK_FALSE(dissector.summarize(bytes).has_value()); +} |