From: James Coglan Date: Tue, 21 May 2024 14:37:56 +0000 (+0100) Subject: resolved: tests for dns_cache_put() with non-matching class, type, name X-Git-Tag: v257-rc1~832^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f44ed739f1f1dc2a1f265140af60d80cb36f4a4d;p=thirdparty%2Fsystemd.git resolved: tests for dns_cache_put() with non-matching class, type, name --- diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c index 51559ffa330..9ec5abd0d30 100644 --- a/src/resolve/test-dns-cache.c +++ b/src/resolve/test-dns-cache.c @@ -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();