From: James Coglan Date: Fri, 31 May 2024 15:35:36 +0000 (+0100) Subject: resolved: tests for dns_zone_remove_rr() X-Git-Tag: v257-rc1~838^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=41c3cd70ae2c8714081ec013d99116596a9bd546;p=thirdparty%2Fsystemd.git resolved: tests for dns_zone_remove_rr() --- diff --git a/src/resolve/test-dns-zone.c b/src/resolve/test-dns-zone.c index c3cea1ac778..d7990a7d39d 100644 --- a/src/resolve/test-dns-zone.c +++ b/src/resolve/test-dns-zone.c @@ -80,4 +80,91 @@ TEST(dns_zone_put_any_type_is_invalid) { ASSERT_TRUE(dns_zone_is_empty(zone)); } +/* ================================================================ + * dns_zone_remove_rr() + * ================================================================ */ + +TEST(dns_zone_remove_rr_match) { + Manager manager = {}; + _cleanup_(dns_scope_freep) DnsScope *scope = NULL; + DnsZone *zone = NULL; + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr_in = NULL, *rr_out = NULL; + + dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET); + ASSERT_NOT_NULL(scope); + zone = &scope->zone; + + rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(rr_in); + rr_in->a.in_addr.s_addr = htobe32(0xc0a8017f); + + ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0)); + + rr_out = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(rr_out); + rr_out->a.in_addr.s_addr = htobe32(0xc0a8017f); + + ASSERT_NOT_NULL(dns_zone_get(zone, rr_in)); + dns_zone_remove_rr(zone, rr_out); + ASSERT_NULL(dns_zone_get(zone, rr_in)); +} + +TEST(dns_zone_remove_rr_match_one) { + Manager manager = {}; + _cleanup_(dns_scope_freep) DnsScope *scope = NULL; + DnsZone *zone = NULL; + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr_in = NULL, *rr_out = NULL; + + dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET); + ASSERT_NOT_NULL(scope); + zone = &scope->zone; + + rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(rr_in); + rr_in->a.in_addr.s_addr = htobe32(0xc0a8017f); + + ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0)); + dns_resource_record_unref(rr_in); + + rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_CNAME, "example.com"); + ASSERT_NOT_NULL(rr_in); + rr_in->cname.name = strdup("www.example.com"); + + ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0)); + + rr_out = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(rr_out); + rr_out->a.in_addr.s_addr = htobe32(0xc0a8017f); + + ASSERT_NOT_NULL(dns_zone_get(zone, rr_out)); + dns_zone_remove_rr(zone, rr_out); + ASSERT_NULL(dns_zone_get(zone, rr_out)); + ASSERT_NOT_NULL(dns_zone_get(zone, rr_in)); +} + +TEST(dns_zone_remove_rr_different_payload) { + Manager manager = {}; + _cleanup_(dns_scope_freep) DnsScope *scope = NULL; + DnsZone *zone = NULL; + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr_in = NULL, *rr_out = NULL; + + dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET); + ASSERT_NOT_NULL(scope); + zone = &scope->zone; + + rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(rr_in); + rr_in->a.in_addr.s_addr = htobe32(0xc0a8017f); + + ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0)); + + rr_out = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(rr_out); + rr_out->a.in_addr.s_addr = htobe32(0xc0a80180); + + ASSERT_NOT_NULL(dns_zone_get(zone, rr_in)); + dns_zone_remove_rr(zone, rr_out); + ASSERT_NOT_NULL(dns_zone_get(zone, rr_in)); +} + DEFINE_TEST_MAIN(LOG_DEBUG);