]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_resource_record_to_wire_format()
authorJames Coglan <james@neighbourhood.ie>
Wed, 12 Jun 2024 09:50:05 +0000 (10:50 +0100)
committerLuca Boccassi <bluca@debian.org>
Tue, 23 Jul 2024 11:44:35 +0000 (12:44 +0100)
Note this function does not produce compressed domain names in the RDATA
when serializing the RR.

src/resolve/test-dns-rr.c

index e77297ceaba348a36f56e657e965c31106bcfb81..b7bf58af32e612f363ff5e345fc2f709c560e614 100644 (file)
@@ -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()
  * ================================================================ */