summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Coglan <james@neighbourhood.ie>2024-06-19 11:05:29 +0200
committerJames Coglan <james@neighbourhood.ie>2024-07-23 15:08:31 +0200
commit3f6ae4a06271f0a84b1e5bff0197c09281397905 (patch)
tree0e4b7091dfc5c503000a85293f1a20d5886292b1
parentresolved: tests for dns_cache_export_shared_to_packet() (diff)
downloadsystemd-3f6ae4a06271f0a84b1e5bff0197c09281397905.tar.xz
systemd-3f6ae4a06271f0a84b1e5bff0197c09281397905.zip
resolved: tests for dns_cache_check_conflicts()
-rw-r--r--src/resolve/test-dns-cache.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c
index e3dd89b9e8..0dd69a541d 100644
--- a/src/resolve/test-dns-cache.c
+++ b/src/resolve/test-dns-cache.c
@@ -753,6 +753,61 @@ TEST(dns_cache_lookup_mdns_multiple_unshared_responses_are_not_cached) {
}
/* ================================================================
+ * dns_cache_check_conflicts()
+ * ================================================================ */
+
+TEST(dns_cache_check_conflicts_same_key_and_owner) {
+ _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+ _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+ _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
+
+ put_args.key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "ns1.example.com");
+ ASSERT_NOT_NULL(put_args.key);
+ answer_add_a(&put_args, put_args.key, 0xc0a8017f, 3600, DNS_ANSWER_CACHEABLE);
+ cache_put(&cache, &put_args);
+
+ union in_addr_union owner_addr = { .in.s_addr = htobe32(0x01020304) };
+
+ rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "ns1.example.com");
+ ASSERT_NOT_NULL(rr);
+ ASSERT_FALSE(dns_cache_check_conflicts(&cache, rr, AF_INET, &owner_addr));
+}
+
+TEST(dns_cache_check_conflicts_same_key_different_owner) {
+ _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+ _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+ _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
+
+ put_args.key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "ns1.example.com");
+ ASSERT_NOT_NULL(put_args.key);
+ answer_add_a(&put_args, put_args.key, 0xc0a8017f, 3600, DNS_ANSWER_CACHEABLE);
+ cache_put(&cache, &put_args);
+
+ union in_addr_union owner_addr = { .in.s_addr = htobe32(0x01020305) };
+
+ rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "ns1.example.com");
+ ASSERT_NOT_NULL(rr);
+ ASSERT_TRUE(dns_cache_check_conflicts(&cache, rr, AF_INET, &owner_addr));
+}
+
+TEST(dns_cache_check_conflicts_different_key) {
+ _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+ _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+ _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
+
+ put_args.key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "ns2.example.com");
+ ASSERT_NOT_NULL(put_args.key);
+ answer_add_a(&put_args, put_args.key, 0xc0a8017f, 3600, DNS_ANSWER_CACHEABLE);
+ cache_put(&cache, &put_args);
+
+ union in_addr_union owner_addr = { .in.s_addr = htobe32(0x01020305) };
+
+ rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "ns1.example.com");
+ ASSERT_NOT_NULL(rr);
+ ASSERT_FALSE(dns_cache_check_conflicts(&cache, rr, AF_INET, &owner_addr));
+}
+
+/* ================================================================
* dns_cache_export_shared_to_packet()
* ================================================================ */