From: James Coglan Date: Wed, 12 Jun 2024 09:50:05 +0000 (+0100) Subject: resolved: tests for dns_resource_record_to_wire_format() X-Git-Tag: v257-rc1~843^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77018b2f47c79caeebbd1ef95db9e46c1b780f67;p=thirdparty%2Fsystemd.git resolved: tests for dns_resource_record_to_wire_format() Note this function does not produce compressed domain names in the RDATA when serializing the RR. --- diff --git a/src/resolve/test-dns-rr.c b/src/resolve/test-dns-rr.c index e77297ceaba..b7bf58af32e 100644 --- a/src/resolve/test-dns-rr.c +++ b/src/resolve/test-dns-rr.c @@ -2307,6 +2307,43 @@ TEST(dns_resource_record_to_string_svcb) { ASSERT_STREQ(str, "_443._wss.example.com IN SVCB 9 sock.example.com mandatory=\"\\000\\001\\000\\003\" alpn=\"websocket\" no-default-alpn port=443 ipv4hint=114.132.253.58,72.188.199.192 ipv6hint=f234:322e:b825:3835:2fd7:db7b:287e:60bb key99"); } +/* ================================================================ + * dns_resource_record_to_wire_format() + * ================================================================ */ + +TEST(dns_resource_record_to_wire_format) { + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; + int r; + + rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_CNAME, "www.example.com"); + ASSERT_NOT_NULL(rr); + rr->ttl = 3600; + rr->cname.name = strdup("example.com"); + + ASSERT_OK(dns_resource_record_to_wire_format(rr, true)); + + const uint8_t data[] = { + /* name */ 0x03, 'w', 'w', 'w', + 0x07, 'e', 'x', 'a', 'm', 'p', 'l', 'e', + 0x03, 'c', 'o', 'm', + 0x00, + /* CNAME */ 0x00, 0x05, + /* IN */ 0x00, 0x01, + /* ttl */ 0x00, 0x00, 0x0e, 0x10, + /* rdata */ 0x00, 0x0d, + /* name */ 0x07, 'e', 'x', 'a', 'm', 'p', 'l', 'e', + 0x03, 'c', 'o', 'm', + 0x00 + }; + + ASSERT_EQ(rr->wire_format_size, sizeof(data)); + ASSERT_EQ(rr->wire_format_rdata_offset, 27u); + ASSERT_EQ(rr->wire_format_canonical, true); + + r = memcmp(rr->wire_format, data, sizeof(data)); + ASSERT_EQ(r, 0); +} + /* ================================================================ * dns_resource_record_clamp_ttl() * ================================================================ */