summaryrefslogtreecommitdiffstats
path: root/src/resolve
diff options
context:
space:
mode:
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/test-dns-cache.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c
index d6568a9a5c..c9f084d3de 100644
--- a/src/resolve/test-dns-cache.c
+++ b/src/resolve/test-dns-cache.c
@@ -104,6 +104,50 @@ TEST(dns_a_success_is_cached) {
ASSERT_FALSE(dns_cache_is_empty(&cache));
}
+TEST(dns_a_nxdomain_is_cached) {
+ _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+ _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+
+ 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_NXDOMAIN;
+
+ put_args.answer = dns_answer_new(1);
+ ASSERT_NOT_NULL(put_args.answer);
+ dns_answer_add_soa(put_args.answer, "example.com", 3600, 0);
+
+ ASSERT_OK(cache_put(&cache, &put_args));
+ ASSERT_FALSE(dns_cache_is_empty(&cache));
+}
+
+TEST(dns_a_servfail_is_cached) {
+ _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+ _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+
+ 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_SERVFAIL;
+ put_args.answer = dns_answer_new(0);
+ ASSERT_NOT_NULL(put_args.answer);
+
+ ASSERT_OK(cache_put(&cache, &put_args));
+ ASSERT_FALSE(dns_cache_is_empty(&cache));
+}
+
+TEST(dns_a_refused_is_not_cached) {
+ _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
+ _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();
+
+ 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_REFUSED;
+ put_args.answer = dns_answer_new(0);
+ ASSERT_NOT_NULL(put_args.answer);
+
+ ASSERT_OK(cache_put(&cache, &put_args));
+ ASSERT_TRUE(dns_cache_is_empty(&cache));
+}
+
TEST(dns_a_success_zero_ttl_is_not_cached) {
_cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
_cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();