| 1 |
#include <dnswire/dnstap.h> |
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
|
| 5 |
#include "create_dnstap.c" |
| 6 |
|
| 7 |
int main(void) |
| 8 |
{ |
| 9 |
uint8_t buf[256 * 1024]; |
| 10 |
size_t s; |
| 11 |
struct dnstap d = DNSTAP_INITIALIZER; |
| 12 |
struct dnstap u = DNSTAP_INITIALIZER; |
| 13 |
|
| 14 |
create_dnstap(&d, "test_dnstap"); |
| 15 |
|
| 16 |
// failed unpack |
| 17 |
assert(dnstap_decode_protobuf(&u, buf, 1) == 1); |
| 18 |
|
| 19 |
// invalid dnstap.type |
| 20 |
d.dnstap.type = (enum _Dnstap__Dnstap__Type)(DNSTAP_TYPE_MESSAGE + 1); |
| 21 |
s = dnstap_encode_protobuf_size(&d); |
| 22 |
assert(s < sizeof(buf)); |
| 23 |
assert(dnstap_encode_protobuf(&d, buf) == s); |
| 24 |
assert(dnstap_decode_protobuf(&u, buf, s) == 0); |
| 25 |
assert(u.dnstap.type == (enum _Dnstap__Dnstap__Type)DNSTAP_TYPE_UNKNOWN); |
| 26 |
dnstap_cleanup(&u); |
| 27 |
d.dnstap.type = (enum _Dnstap__Dnstap__Type)DNSTAP_TYPE_MESSAGE; |
| 28 |
|
| 29 |
// invalid message.type |
| 30 |
d.message.type = (enum _Dnstap__Message__Type)(DNSTAP_MESSAGE_TYPE_UPDATE_RESPONSE + 1); |
| 31 |
s = dnstap_encode_protobuf_size(&d); |
| 32 |
assert(s < sizeof(buf)); |
| 33 |
assert(dnstap_encode_protobuf(&d, buf) == s); |
| 34 |
assert(dnstap_decode_protobuf(&u, buf, s) == 0); |
| 35 |
assert(u.message.type == (enum _Dnstap__Message__Type)DNSTAP_MESSAGE_TYPE_UNKNOWN); |
| 36 |
dnstap_cleanup(&u); |
| 37 |
d.message.type = (enum _Dnstap__Message__Type)DNSTAP_MESSAGE_TYPE_TOOL_QUERY; |
| 38 |
|
| 39 |
// invalid message.socket_family |
| 40 |
d.message.socket_family = (enum _Dnstap__SocketFamily)(DNSTAP_SOCKET_FAMILY_INET6 + 1); |
| 41 |
s = dnstap_encode_protobuf_size(&d); |
| 42 |
assert(s < sizeof(buf)); |
| 43 |
assert(dnstap_encode_protobuf(&d, buf) == s); |
| 44 |
assert(dnstap_decode_protobuf(&u, buf, s) == 0); |
| 45 |
assert(u.message.socket_family == (enum _Dnstap__SocketFamily)DNSTAP_SOCKET_FAMILY_UNKNOWN); |
| 46 |
dnstap_cleanup(&u); |
| 47 |
d.message.socket_family = (enum _Dnstap__SocketFamily)DNSTAP_SOCKET_FAMILY_INET; |
| 48 |
|
| 49 |
// invalid message.socket_protocol |
| 50 |
d.message.socket_protocol = (enum _Dnstap__SocketProtocol)(DNSTAP_SOCKET_PROTOCOL_DOQ + 1); |
| 51 |
s = dnstap_encode_protobuf_size(&d); |
| 52 |
assert(s < sizeof(buf)); |
| 53 |
assert(dnstap_encode_protobuf(&d, buf) == s); |
| 54 |
assert(dnstap_decode_protobuf(&u, buf, s) == 0); |
| 55 |
assert(u.message.socket_protocol == (enum _Dnstap__SocketProtocol)DNSTAP_SOCKET_PROTOCOL_UNKNOWN); |
| 56 |
dnstap_cleanup(&u); |
| 57 |
d.message.socket_protocol = (enum _Dnstap__SocketProtocol)DNSTAP_SOCKET_PROTOCOL_UDP; |
| 58 |
|
| 59 |
// invalid message.http_protocol |
| 60 |
d.message.http_protocol = (enum _Dnstap__HttpProtocol)(DNSTAP_HTTP_PROTOCOL_HTTP3 + 1); |
| 61 |
s = dnstap_encode_protobuf_size(&d); |
| 62 |
assert(s < sizeof(buf)); |
| 63 |
assert(dnstap_encode_protobuf(&d, buf) == s); |
| 64 |
assert(dnstap_decode_protobuf(&u, buf, s) == 0); |
| 65 |
assert(u.message.http_protocol == (enum _Dnstap__HttpProtocol)DNSTAP_HTTP_PROTOCOL_UNKNOWN); |
| 66 |
dnstap_cleanup(&u); |
| 67 |
d.message.http_protocol = (enum _Dnstap__HttpProtocol)DNSTAP_HTTP_PROTOCOL_HTTP1; |
| 68 |
|
| 69 |
return 0; |
| 70 |
} |