summaryrefslogtreecommitdiffstats
path: root/src/test/test_dnstap.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-01-14 15:03:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-01-14 15:03:48 +0000
commitbe956cd27353a4bb585b1a648e8469cf7adb5edf (patch)
treea473793c3fd59ace461f23a8d75d9ca29a82b4ff /src/test/test_dnstap.c
parentInitial commit. (diff)
downloaddnswire-be956cd27353a4bb585b1a648e8469cf7adb5edf.tar.xz
dnswire-be956cd27353a4bb585b1a648e8469cf7adb5edf.zip
Adding upstream version 0.2.0.upstream/0.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test_dnstap.c')
-rw-r--r--src/test/test_dnstap.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/test_dnstap.c b/src/test/test_dnstap.c
new file mode 100644
index 0000000..fd199f8
--- /dev/null
+++ b/src/test/test_dnstap.c
@@ -0,0 +1,60 @@
+#include <dnswire/dnstap.h>
+
+#include <assert.h>
+
+#include "create_dnstap.c"
+
+int main(void)
+{
+ uint8_t buf[256 * 1024];
+ size_t s;
+ struct dnstap d = DNSTAP_INITIALIZER;
+ struct dnstap u = DNSTAP_INITIALIZER;
+
+ create_dnstap(&d, "test_dnstap");
+
+ // failed unpack
+ assert(dnstap_decode_protobuf(&u, buf, 1) == 1);
+
+ // invalid dnstap.type
+ d.dnstap.type = (enum _Dnstap__Dnstap__Type)(DNSTAP_TYPE_MESSAGE + 1);
+ s = dnstap_encode_protobuf_size(&d);
+ assert(s < sizeof(buf));
+ assert(dnstap_encode_protobuf(&d, buf) == s);
+ assert(dnstap_decode_protobuf(&u, buf, s) == 0);
+ assert(u.dnstap.type == (enum _Dnstap__Dnstap__Type)DNSTAP_TYPE_UNKNOWN);
+ dnstap_cleanup(&u);
+ d.dnstap.type = (enum _Dnstap__Dnstap__Type)DNSTAP_TYPE_MESSAGE;
+
+ // invalid message.type
+ d.message.type = (enum _Dnstap__Message__Type)(DNSTAP_MESSAGE_TYPE_TOOL_RESPONSE + 1);
+ s = dnstap_encode_protobuf_size(&d);
+ assert(s < sizeof(buf));
+ assert(dnstap_encode_protobuf(&d, buf) == s);
+ assert(dnstap_decode_protobuf(&u, buf, s) == 0);
+ assert(u.message.type == (enum _Dnstap__Message__Type)DNSTAP_MESSAGE_TYPE_UNKNOWN);
+ dnstap_cleanup(&u);
+ d.message.type = (enum _Dnstap__Message__Type)DNSTAP_MESSAGE_TYPE_TOOL_QUERY;
+
+ // invalid message.socket_family
+ d.message.socket_family = (enum _Dnstap__SocketFamily)(DNSTAP_SOCKET_FAMILY_INET6 + 1);
+ s = dnstap_encode_protobuf_size(&d);
+ assert(s < sizeof(buf));
+ assert(dnstap_encode_protobuf(&d, buf) == s);
+ assert(dnstap_decode_protobuf(&u, buf, s) == 0);
+ assert(u.message.socket_family == (enum _Dnstap__SocketFamily)DNSTAP_SOCKET_FAMILY_UNKNOWN);
+ dnstap_cleanup(&u);
+ d.message.socket_family = (enum _Dnstap__SocketFamily)DNSTAP_SOCKET_FAMILY_INET;
+
+ // invalid message.socket_protocol
+ d.message.socket_protocol = (enum _Dnstap__SocketProtocol)(DNSTAP_SOCKET_PROTOCOL_TCP + 1);
+ s = dnstap_encode_protobuf_size(&d);
+ assert(s < sizeof(buf));
+ assert(dnstap_encode_protobuf(&d, buf) == s);
+ assert(dnstap_decode_protobuf(&u, buf, s) == 0);
+ assert(u.message.socket_protocol == (enum _Dnstap__SocketProtocol)DNSTAP_SOCKET_PROTOCOL_UNKNOWN);
+ dnstap_cleanup(&u);
+ d.message.socket_protocol = (enum _Dnstap__SocketProtocol)DNSTAP_SOCKET_PROTOCOL_UDP;
+
+ return 0;
+}