diff options
author | James Coglan <james@neighbourhood.ie> | 2024-05-21 16:37:56 +0200 |
---|---|---|
committer | James Coglan <james@neighbourhood.ie> | 2024-07-23 15:08:31 +0200 |
commit | f44ed739f1f1dc2a1f265140af60d80cb36f4a4d (patch) | |
tree | 15170be835ecb04ed4d264555aa336678100927e | |
parent | resolved: refactor DNS answer construction for cache tests (diff) | |
download | systemd-f44ed739f1f1dc2a1f265140af60d80cb36f4a4d.tar.xz systemd-f44ed739f1f1dc2a1f265140af60d80cb36f4a4d.zip |
resolved: tests for dns_cache_put() with non-matching class, type, name
-rw-r--r-- | src/resolve/test-dns-cache.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c index 51559ffa33..9ec5abd0d3 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(); |