From: James Coglan Date: Thu, 23 May 2024 14:57:05 +0000 (+0100) Subject: resolved: check that adding an expired response removes cache entry X-Git-Tag: v257-rc1~832^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bec28864af50d3d9f0f8b888040384bfa00e9f9;p=thirdparty%2Fsystemd.git resolved: check that adding an expired response removes cache entry --- diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c index f8d88403ac2..11dea7002f4 100644 --- a/src/resolve/test-dns-cache.c +++ b/src/resolve/test-dns-cache.c @@ -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();