srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2024-05-21 22:24:00 +0200
committersrdusr <[email protected]>2024-05-21 22:24:00 +0200
commitfbedc55d5aa861c381701c9f913b34ee7ab57ec4 (patch)
treed34c3648b61d417f2a5d8690e0eb4a76bd64c943 /tests
parente0f4c701028aa81026a17cf9ebfb36112184f4bc (diff)
downloadpacketeer-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')
-rw-r--r--tests/test_mdns.cpp60
-rw-r--r--tests/test_ssh.cpp62
2 files changed, 122 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());
+}
diff --git a/tests/test_ssh.cpp b/tests/test_ssh.cpp
new file mode 100644
index 0000000..7c4e339
--- /dev/null
+++ b/tests/test_ssh.cpp
@@ -0,0 +1,62 @@
+#include <doctest/doctest.h>
+
+#include <vector>
+
+#include "wireframe/l7/ssh.hpp"
+
+using namespace wireframe::net;
+
+namespace {
+
+std::vector<unsigned char> to_bytes(const std::string& s) {
+ return std::vector<unsigned char>(s.begin(), s.end());
+}
+
+} // namespace
+
+TEST_CASE("parse_ssh_banner decodes a CRLF-terminated banner with a comment") {
+ auto banner = parse_ssh_banner(to_bytes("SSH-2.0-OpenSSH_9.6 FreeBSD-20240101\r\n"));
+ REQUIRE(banner.has_value());
+ CHECK(banner->proto_version == "2.0");
+ CHECK(banner->software_version == "OpenSSH_9.6");
+}
+
+TEST_CASE("parse_ssh_banner decodes a banner with no comment") {
+ auto banner = parse_ssh_banner(to_bytes("SSH-2.0-libssh_0.10.6\r\n"));
+ REQUIRE(banner.has_value());
+ CHECK(banner->proto_version == "2.0");
+ CHECK(banner->software_version == "libssh_0.10.6");
+}
+
+TEST_CASE("parse_ssh_banner tolerates a bare LF terminator") {
+ auto banner = parse_ssh_banner(to_bytes("SSH-1.99-OpenSSH_3.9\n"));
+ REQUIRE(banner.has_value());
+ CHECK(banner->proto_version == "1.99");
+ CHECK(banner->software_version == "OpenSSH_3.9");
+}
+
+TEST_CASE("parse_ssh_banner rejects payloads without the SSH- prefix") {
+ CHECK_FALSE(parse_ssh_banner(to_bytes("not an ssh banner\r\n")).has_value());
+}
+
+TEST_CASE("parse_ssh_banner rejects a banner missing the version separator") {
+ CHECK_FALSE(parse_ssh_banner(to_bytes("SSH-nodash\r\n")).has_value());
+}
+
+TEST_CASE("parse_ssh_banner rejects an unterminated line") {
+ CHECK_FALSE(parse_ssh_banner(to_bytes("SSH-2.0-OpenSSH_9.6")).has_value());
+}
+
+TEST_CASE("SshDissector claims port 22 and its summary matches parse_ssh_banner") {
+ SshDissector dissector;
+ CHECK(dissector.port() == kSshPort);
+
+ auto summary = dissector.summarize(to_bytes("SSH-2.0-OpenSSH_9.6\r\n"));
+ REQUIRE(summary.has_value());
+ CHECK(*summary == "SSH 2.0 OpenSSH_9.6");
+}
+
+TEST_CASE("SshDissector::summarize returns nullopt for non-SSH payload") {
+ SshDissector dissector;
+ CHECK_FALSE(dissector.summarize(to_bytes("GET / HTTP/1.1\r\n")).has_value());
+}