summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/resolve/test-dns-cache.c51
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();