]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: check that adding an expired response removes cache entry
authorJames Coglan <james@neighbourhood.ie>
Thu, 23 May 2024 14:57:05 +0000 (15:57 +0100)
committerJames Coglan <james@neighbourhood.ie>
Tue, 23 Jul 2024 13:08:31 +0000 (14:08 +0100)
src/resolve/test-dns-cache.c

index f8d88403ac271e20f35d84551d5543d16aa5646c..11dea7002f4938b9dedcbab15a21f18897165606 100644 (file)
@@ -230,6 +230,27 @@ TEST(dns_a_success_zero_ttl_is_not_cached) {
         ASSERT_TRUE(dns_cache_is_empty(&cache));
 }
 
+TEST(dns_a_success_zero_ttl_removes_existing_entry) {
+        _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_SUCCESS;
+        answer_add_a(&put_args, put_args.key, 0xc0a8017f, 3600, DNS_ANSWER_CACHEABLE);
+
+        ASSERT_OK(cache_put(&cache, &put_args));
+        ASSERT_FALSE(dns_cache_is_empty(&cache));
+
+        dns_answer_unref(put_args.answer);
+        put_args.answer = dns_answer_new(1);
+        ASSERT_NOT_NULL(put_args.answer);
+        answer_add_a(&put_args, put_args.key, 0xc0a8017f, 0, DNS_ANSWER_CACHEABLE);
+
+        ASSERT_OK(cache_put(&cache, &put_args));
+        ASSERT_TRUE(dns_cache_is_empty(&cache));
+}
+
 TEST(dns_a_success_not_cacheable_is_not_cached) {
         _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache();
         _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args();