]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add unit test for invalid dnstap entries
authorAydın Mercan <aydin@isc.org>
Thu, 18 Jun 2026 06:45:00 +0000 (09:45 +0300)
committerAydın Mercan <aydin@isc.org>
Tue, 30 Jun 2026 09:08:29 +0000 (12:08 +0300)
Test `dns_dt_parse` against:
- query nanosecond field over a second
- response nanosecond field over a second
- invalid message type field

tests/dns/dnstap_test.c
tests/dns/testdata/dnstap/correct_query_nanosec.dnstap [new file with mode: 0644]
tests/dns/testdata/dnstap/correct_response_nanosec.dnstap [new file with mode: 0644]
tests/dns/testdata/dnstap/invalid_message_type.dnstap [new file with mode: 0644]
tests/dns/testdata/dnstap/query_time_nanosec_big.dnstap [new file with mode: 0644]
tests/dns/testdata/dnstap/response_time_nanosec_big.dnstap [new file with mode: 0644]

index 94d17040ee32d020be45ef730240bf2414d68b6f..b38585a1dc980a7e8075aff9aef996e3bfb5a309 100644 (file)
@@ -30,6 +30,7 @@
 #include <isc/buffer.h>
 #include <isc/file.h>
 #include <isc/lib.h>
+#include <isc/result.h>
 #include <isc/stdio.h>
 #include <isc/types.h>
 #include <isc/util.h>
@@ -39,6 +40,7 @@
 #include <dns/view.h>
 
 #include <tests/dns.h>
+#include <tests/isc.h>
 
 #define TAPFILE TESTS_DIR "/testdata/dnstap/dnstap.file"
 #define TAPSOCK TESTS_DIR "/testdata/dnstap/dnstap.sock"
@@ -367,11 +369,67 @@ ISC_LOOP_TEST_IMPL(dns_dt_totext) {
        isc_loopmgr_shutdown();
 }
 
+static void
+correct_dnstap_parse(const char *path) {
+       isc_result_t result;
+       dns_dtdata_t *dt = NULL;
+       isc_region_t src;
+       uint8_t buf[640];
+       size_t len;
+       FILE *f;
+
+       f = fopen(path, "r");
+       assert_non_null(f);
+       len = fread(buf, 1, sizeof(buf), f);
+       assert_uint_in_range(len, 1, sizeof(buf) - 1);
+       fclose(f);
+
+       src = (isc_region_t){ buf, len };
+       result = dns_dt_parse(isc_g_mctx, &src, &dt);
+       assert_int_equal(result, ISC_R_SUCCESS);
+       dns_dtdata_free(&dt);
+}
+
+static void
+invalid_dnstap_parse(const char *path) {
+       isc_result_t result;
+       dns_dtdata_t *dt = NULL;
+       isc_region_t src;
+       uint8_t buf[640];
+       size_t len;
+       FILE *f;
+
+       f = fopen(path, "r");
+       assert_non_null(f);
+       len = fread(buf, 1, sizeof(buf), f);
+       assert_uint_in_range(len, 1, sizeof(buf) - 1);
+       fclose(f);
+
+       src = (isc_region_t){ buf, len };
+       result = dns_dt_parse(isc_g_mctx, &src, &dt);
+       assert_int_equal(result, DNS_R_BADDNSTAP);
+}
+
+ISC_RUN_TEST_IMPL(dns_dt_parse) {
+       correct_dnstap_parse(
+               TESTS_DIR "/testdata/dnstap/correct_response_nanosec.dnstap");
+       correct_dnstap_parse(TESTS_DIR
+                            "/testdata/dnstap/correct_query_nanosec.dnstap");
+       invalid_dnstap_parse(
+               TESTS_DIR "/testdata/dnstap/response_time_nanosec_big.dnstap");
+       invalid_dnstap_parse(TESTS_DIR
+                            "/testdata/dnstap/query_time_nanosec_big.dnstap");
+
+       invalid_dnstap_parse(TESTS_DIR
+                            "/testdata/dnstap/invalid_message_type.dnstap");
+}
+
 ISC_TEST_LIST_START
 
 ISC_TEST_ENTRY_CUSTOM(dns_dt_create, setup, teardown)
 ISC_TEST_ENTRY_CUSTOM(dns_dt_send, setup, teardown)
 ISC_TEST_ENTRY_CUSTOM(dns_dt_totext, setup, teardown)
+ISC_TEST_ENTRY(dns_dt_parse)
 
 ISC_TEST_LIST_END
 
diff --git a/tests/dns/testdata/dnstap/correct_query_nanosec.dnstap b/tests/dns/testdata/dnstap/correct_query_nanosec.dnstap
new file mode 100644 (file)
index 0000000..8f2cc2e
Binary files /dev/null and b/tests/dns/testdata/dnstap/correct_query_nanosec.dnstap differ
diff --git a/tests/dns/testdata/dnstap/correct_response_nanosec.dnstap b/tests/dns/testdata/dnstap/correct_response_nanosec.dnstap
new file mode 100644 (file)
index 0000000..99a37b7
Binary files /dev/null and b/tests/dns/testdata/dnstap/correct_response_nanosec.dnstap differ
diff --git a/tests/dns/testdata/dnstap/invalid_message_type.dnstap b/tests/dns/testdata/dnstap/invalid_message_type.dnstap
new file mode 100644 (file)
index 0000000..0360428
Binary files /dev/null and b/tests/dns/testdata/dnstap/invalid_message_type.dnstap differ
diff --git a/tests/dns/testdata/dnstap/query_time_nanosec_big.dnstap b/tests/dns/testdata/dnstap/query_time_nanosec_big.dnstap
new file mode 100644 (file)
index 0000000..397f3c8
Binary files /dev/null and b/tests/dns/testdata/dnstap/query_time_nanosec_big.dnstap differ
diff --git a/tests/dns/testdata/dnstap/response_time_nanosec_big.dnstap b/tests/dns/testdata/dnstap/response_time_nanosec_big.dnstap
new file mode 100644 (file)
index 0000000..0dbdc31
Binary files /dev/null and b/tests/dns/testdata/dnstap/response_time_nanosec_big.dnstap differ