From: James Coglan Date: Wed, 29 May 2024 13:20:15 +0000 (+0100) Subject: resolved: tests for dns_resource_record_new_address(), dns_resource_record_new_reverse() X-Git-Tag: v257-rc1~843^2~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43e32a20813a7e5edf0469559b75584767a6ab77;p=thirdparty%2Fsystemd.git resolved: tests for dns_resource_record_new_address(), dns_resource_record_new_reverse() --- diff --git a/src/resolve/test-dns-rr.c b/src/resolve/test-dns-rr.c index fe3bc3666a8..7f1e81b3e6e 100644 --- a/src/resolve/test-dns-rr.c +++ b/src/resolve/test-dns-rr.c @@ -765,4 +765,56 @@ TEST(dns_resource_key_reduce_refcount) { a->n_ref = 2; } +/* ================================================================ + * dns_resource_record_new_address() + * ================================================================ */ + +TEST(dns_resource_record_new_address_ipv4) { + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; + + union in_addr_union addr = { .in.s_addr = htobe32(0xc0a8017f) }; + + ASSERT_OK(dns_resource_record_new_address(&rr, AF_INET, &addr, "www.example.com")); + ASSERT_NOT_NULL(rr); + + ASSERT_EQ(rr->key->class, DNS_CLASS_IN); + ASSERT_EQ(rr->key->type, DNS_TYPE_A); + ASSERT_STREQ(dns_resource_key_name(rr->key), "www.example.com"); + ASSERT_EQ(rr->a.in_addr.s_addr, addr.in.s_addr); +} + +TEST(dns_resource_record_new_address_ipv6) { + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; + + union in_addr_union addr = { + .in6.s6_addr = { 0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03 } + }; + + ASSERT_OK(dns_resource_record_new_address(&rr, AF_INET6, &addr, "www.example.com")); + ASSERT_NOT_NULL(rr); + + ASSERT_EQ(rr->key->class, DNS_CLASS_IN); + ASSERT_EQ(rr->key->type, DNS_TYPE_AAAA); + ASSERT_STREQ(dns_resource_key_name(rr->key), "www.example.com"); + ASSERT_EQ(memcmp(&rr->aaaa.in6_addr, &addr.in6, sizeof(struct in6_addr)), 0); +} + +/* ================================================================ + * dns_resource_record_new_reverse() + * ================================================================ */ + +TEST(dns_resource_record_new_reverse) { + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; + + union in_addr_union addr = { .in.s_addr = htobe32(0xc0a8017f) }; + + ASSERT_OK(dns_resource_record_new_reverse(&rr, AF_INET, &addr, "www.example.com")); + ASSERT_NOT_NULL(rr); + + ASSERT_EQ(rr->key->class, DNS_CLASS_IN); + ASSERT_EQ(rr->key->type, DNS_TYPE_PTR); + ASSERT_STREQ(dns_resource_key_name(rr->key), "127.1.168.192.in-addr.arpa"); + ASSERT_STREQ(rr->ptr.name, "www.example.com"); +} + DEFINE_TEST_MAIN(LOG_DEBUG);