summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Coglan <james@neighbourhood.ie>2024-06-24 11:16:02 +0200
committerJames Coglan <james@neighbourhood.ie>2024-07-23 15:17:23 +0200
commit538a3dc298c28ac27563ab54db93b4e91ae320af (patch)
tree4e5095dfa3e66e47d5250a3502dd88314fc52b2a
parentresolved: tests for dns_query_go(); multiple search domains for dns_query_can... (diff)
downloadsystemd-538a3dc298c28ac27563ab54db93b4e91ae320af.tar.xz
systemd-538a3dc298c28ac27563ab54db93b4e91ae320af.zip
resolved: tests for dns_query_string()
-rw-r--r--src/resolve/test-dns-query.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/resolve/test-dns-query.c b/src/resolve/test-dns-query.c
index db69dedb94..53c4588474 100644
--- a/src/resolve/test-dns-query.c
+++ b/src/resolve/test-dns-query.c
@@ -618,6 +618,77 @@ TEST(dns_query_process_cname_many_success_match_multiple_cname) {
}
/* ================================================================
+ * 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()
* ================================================================ */