]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_query_string() 33534/head
authorJames Coglan <james@neighbourhood.ie>
Mon, 24 Jun 2024 09:16:02 +0000 (10:16 +0100)
committerJames Coglan <james@neighbourhood.ie>
Tue, 23 Jul 2024 13:17:23 +0000 (14:17 +0100)
src/resolve/test-dns-query.c

index db69dedb94810caec3dae753691519b7e300a090..53c45884744a7c91cc32a6db20deb05f6dcc2ad4 100644 (file)
@@ -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()
  * ================================================================ */