diff options
author | James Coglan <james@neighbourhood.ie> | 2024-06-19 13:22:49 +0200 |
---|---|---|
committer | James Coglan <james@neighbourhood.ie> | 2024-07-23 15:08:31 +0200 |
commit | f5dd610978daa0970c1ad4665ae90ea54b8fe075 (patch) | |
tree | 27f4800bb4eadfd69e1df43060a439897d35b359 | |
parent | resolved: tests for dns_cache_put() for NXDOMAIN with no SOA (diff) | |
download | systemd-f5dd610978daa0970c1ad4665ae90ea54b8fe075.tar.xz systemd-f5dd610978daa0970c1ad4665ae90ea54b8fe075.zip |
resolved: tests for dns_cache_lookup() clamping the TTL
-rw-r--r-- | src/resolve/test-dns-cache.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c index 3411bb55fa..dc9152e3f7 100644 --- a/src/resolve/test-dns-cache.c +++ b/src/resolve/test-dns-cache.c @@ -571,6 +571,43 @@ TEST(dns_cache_lookup_success) { ASSERT_TRUE(dns_answer_contains(ret_answer, rr)); } +TEST(dns_cache_lookup_clamp_ttl) { + _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache(); + _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args(); + _cleanup_(dns_answer_unrefp) DnsAnswer *ret_answer = NULL; + _cleanup_(dns_packet_unrefp) DnsPacket *ret_full_packet = NULL; + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; + _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL; + int query_flags, ret_rcode; + uint64_t ret_query_flags; + + 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); + cache_put(&cache, &put_args); + + ASSERT_EQ(dns_cache_size(&cache), 1u); + + key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(key); + query_flags = SD_RESOLVED_CLAMP_TTL; + ASSERT_TRUE(dns_cache_lookup(&cache, key, query_flags, &ret_rcode, &ret_answer, &ret_full_packet, &ret_query_flags, NULL)); + + ASSERT_EQ(cache.n_hit, 1u); + ASSERT_EQ(cache.n_miss, 0u); + + ASSERT_EQ(ret_rcode, DNS_RCODE_SUCCESS); + ASSERT_EQ(ret_query_flags, SD_RESOLVED_CONFIDENTIAL); + + ASSERT_EQ(dns_answer_size(ret_answer), 1u); + + rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com"); + ASSERT_NOT_NULL(rr); + rr->a.in_addr.s_addr = htobe32(0xc0a8017f); + ASSERT_TRUE(dns_answer_contains(ret_answer, rr)); +} + TEST(dns_cache_lookup_returns_most_recent_response) { _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache(); _cleanup_(put_args_unrefp) PutArgs args1 = mk_put_args(), args2 = mk_put_args(); |