]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_cache_put() with non-matching class, type, name
authorJames Coglan <james@neighbourhood.ie>
Tue, 21 May 2024 14:37:56 +0000 (15:37 +0100)
committerJames Coglan <james@neighbourhood.ie>
Tue, 23 Jul 2024 13:08:31 +0000 (14:08 +0100)
src/resolve/test-dns-cache.c

index 51559ffa3302e7437edc7dc2b966c6fcc894b91c..9ec5abd0d30849ec6c7cbeab717bbc8d69624373 100644 (file)
@@ -106,6 +106,57 @@ TEST(dns_a_success_is_cached) {
         ASSERT_FALSE(dns_cache_is_empty(&cache));
 }
 
+TEST(dns_a_success_non_matching_type_is_cached) {
+        _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+        _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        put_args.key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(put_args.key);
+        put_args.rcode = DNS_RCODE_SUCCESS;
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        answer_add_a(&put_args, key, 0xc0a8017f, 3600, DNS_ANSWER_CACHEABLE);
+
+        ASSERT_OK(cache_put(&cache, &put_args));
+        ASSERT_FALSE(dns_cache_is_empty(&cache));
+}
+
+TEST(dns_a_success_non_matching_name_is_cached) {
+        _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+        _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        put_args.key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(put_args.key);
+        put_args.rcode = DNS_RCODE_SUCCESS;
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "example.com");
+        ASSERT_NOT_NULL(key);
+        answer_add_a(&put_args, key, 0xc0a8017f, 3600, DNS_ANSWER_CACHEABLE);
+
+        ASSERT_OK(cache_put(&cache, &put_args));
+        ASSERT_FALSE(dns_cache_is_empty(&cache));
+}
+
+TEST(dns_a_success_escaped_key_returns_error) {
+        _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+        _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        put_args.key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(put_args.key);
+        put_args.rcode = DNS_RCODE_SUCCESS;
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.\\example.com");
+        ASSERT_NOT_NULL(key);
+        answer_add_a(&put_args, key, 0xc0a8017f, 3600, DNS_ANSWER_CACHEABLE);
+
+        ASSERT_ERROR(cache_put(&cache, &put_args), EINVAL);
+        ASSERT_TRUE(dns_cache_is_empty(&cache));
+}
+
 TEST(dns_a_success_empty_answer_is_not_cached) {
         _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
         _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();