]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_query_go() when configured with search domains
authorJames Coglan <james@neighbourhood.ie>
Fri, 21 Jun 2024 16:56:22 +0000 (17:56 +0100)
committerJames Coglan <james@neighbourhood.ie>
Tue, 23 Jul 2024 13:17:23 +0000 (14:17 +0100)
src/resolve/test-dns-query.c

index 21792b0147e9c03b043a8a4f667115d4152dd5eb..6df06745f68de69baabc7b92af4f19b19d66b42d 100644 (file)
@@ -648,13 +648,15 @@ typedef struct GoConfig {
         bool has_scope;
         bool use_link;
         bool use_bypass;
+        bool use_search_domain;
 } GoConfig;
 
 static GoConfig mk_go_config(void) {
         return (GoConfig) {
                 .has_scope = true,
                 .use_link = false,
-                .use_bypass = false
+                .use_bypass = false,
+                .use_search_domain = false
         };
 }
 
@@ -663,6 +665,7 @@ static void exercise_dns_query_go(GoConfig *cfg, void (*check_query)(DnsQuery *q
         Link *link = NULL;
         _cleanup_(dns_server_unrefp) DnsServer *server = NULL;
         _cleanup_(dns_scope_freep) DnsScope *scope = NULL;
+        _cleanup_(dns_search_domain_unrefp) DnsSearchDomain *sd = NULL;
 
         _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
         _cleanup_(dns_packet_unrefp) DnsPacket *packet = NULL;
@@ -702,7 +705,19 @@ static void exercise_dns_query_go(GoConfig *cfg, void (*check_query)(DnsQuery *q
                 ASSERT_NOT_NULL(scope);
         }
 
-        ASSERT_OK(dns_question_new_address(&question, AF_INET, "www.example.com", false));
+        if (cfg->use_search_domain) {
+                if (link == NULL)
+                        dns_search_domain_new(&manager, &sd, DNS_SEARCH_DOMAIN_SYSTEM, NULL, "local");
+                else
+                        dns_search_domain_new(&manager, &sd, DNS_SEARCH_DOMAIN_LINK, link, "local");
+
+                /* search domains trigger on single-label domains */
+                ASSERT_OK(dns_question_new_address(&question, AF_INET, "berlin", false));
+                flags &= ~SD_RESOLVED_NO_SEARCH;
+        } else {
+                ASSERT_OK(dns_question_new_address(&question, AF_INET, "www.example.com", false));
+        }
+
         ASSERT_NOT_NULL(question);
 
         if (cfg->use_bypass) {
@@ -754,6 +769,10 @@ TEST(dns_query_go) {
         cfg = mk_go_config();
         cfg.has_scope = false;
         exercise_dns_query_go(&cfg, check_query_no_servers);
+
+        cfg = mk_go_config();
+        cfg.use_search_domain = true;
+        exercise_dns_query_go(&cfg, NULL);
 }
 
 DEFINE_TEST_MAIN(LOG_DEBUG);