summaryrefslogtreecommitdiffstats
path: root/src/resolve
diff options
context:
space:
mode:
authorJames Coglan <james@neighbourhood.ie>2024-05-21 15:30:30 +0200
committerJames Coglan <james@neighbourhood.ie>2024-07-23 15:08:31 +0200
commitc5df8d53a915a2fc91960198549cb049a0de07cc (patch)
tree49a89127d265e8878d6d5b1d908b78991578b7b0 /src/resolve
parentresolved: tests for dns_cache_put(); successful A query (diff)
downloadsystemd-c5df8d53a915a2fc91960198549cb049a0de07cc.tar.xz
systemd-c5df8d53a915a2fc91960198549cb049a0de07cc.zip
resolved: tests for dns_cache_put() with different RCODEs
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();