From: James Coglan Date: Mon, 24 Jun 2024 09:16:02 +0000 (+0100) Subject: resolved: tests for dns_query_string() X-Git-Tag: v257-rc1~833^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F33534%2Fhead;p=thirdparty%2Fsystemd.git resolved: tests for dns_query_string() --- diff --git a/src/resolve/test-dns-query.c b/src/resolve/test-dns-query.c index db69dedb948..53c45884744 100644 --- a/src/resolve/test-dns-query.c +++ b/src/resolve/test-dns-query.c @@ -617,6 +617,77 @@ TEST(dns_query_process_cname_many_success_match_multiple_cname) { dns_resource_key_unref(key); } +/* ================================================================ + * dns_query_string() + * ================================================================ */ + +TEST(dns_query_string_question_utf8) { + Manager manager = {}; + _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL; + _cleanup_(dns_query_freep) DnsQuery *query = NULL; + + ASSERT_OK(dns_question_new_address(&question, AF_INET, "utf8.example.com", false)); + ASSERT_NOT_NULL(question); + + ASSERT_OK(dns_query_new(&manager, &query, question, NULL, NULL, 1, 0)); + ASSERT_NOT_NULL(query); + + const char *str = dns_query_string(query); + ASSERT_STREQ(str, "utf8.example.com"); +} + +TEST(dns_query_string_question_idna) { + Manager manager = {}; + _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL; + _cleanup_(dns_query_freep) DnsQuery *query = NULL; + + ASSERT_OK(dns_question_new_address(&question, AF_INET, "idna.example.com", false)); + ASSERT_NOT_NULL(question); + + ASSERT_OK(dns_query_new(&manager, &query, NULL, question, NULL, 1, 0)); + ASSERT_NOT_NULL(query); + + const char *str = dns_query_string(query); + ASSERT_STREQ(str, "idna.example.com"); +} + +TEST(dns_query_string_question_bypass) { + Manager manager = {}; + _cleanup_(dns_query_freep) DnsQuery *query = NULL; + _cleanup_(dns_packet_unrefp) DnsPacket * packet = NULL; + + ASSERT_OK(dns_packet_new_query(&packet, DNS_PROTOCOL_DNS, 0, false)); + ASSERT_NOT_NULL(packet); + + ASSERT_OK(dns_question_new_address(&packet->question, AF_INET, "bypass.example.com", false)); + ASSERT_NOT_NULL(packet->question); + + ASSERT_OK(dns_query_new(&manager, &query, NULL, NULL, packet, 1, 0)); + ASSERT_NOT_NULL(query); + + const char *str = dns_query_string(query); + ASSERT_STREQ(str, "bypass.example.com"); +} + +TEST(dns_query_string_request_address) { + Manager manager = {}; + _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL; + _cleanup_(dns_query_freep) DnsQuery *query = NULL; + + ASSERT_OK(dns_question_new_address(&question, AF_INET, "www.example.com", false)); + ASSERT_NOT_NULL(question); + + ASSERT_OK(dns_query_new(&manager, &query, question, NULL, NULL, 1, 0)); + ASSERT_NOT_NULL(query); + + query->request_family = AF_INET; + query->request_address.in.s_addr = htobe32(0x7f000001); + query->request_address_valid = true; + + const char *str = dns_query_string(query); + ASSERT_STREQ(str, "127.0.0.1"); +} + /* ================================================================ * dns_query_go() * ================================================================ */