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

index 6d5e3a760abfd3a380804d34c3edf31618f36f80..21792b0147e9c03b043a8a4f667115d4152dd5eb 100644 (file)
@@ -645,18 +645,20 @@ static void dns_scope_freep(DnsScope **s) {
 }
 
 typedef struct GoConfig {
+        bool has_scope;
         bool use_link;
         bool use_bypass;
 } GoConfig;
 
 static GoConfig mk_go_config(void) {
         return (GoConfig) {
+                .has_scope = true,
                 .use_link = false,
                 .use_bypass = false
         };
 }
 
-static void exercise_dns_query_go(GoConfig *cfg) {
+static void exercise_dns_query_go(GoConfig *cfg, void (*check_query)(DnsQuery *query)) {
         Manager manager = {};
         Link *link = NULL;
         _cleanup_(dns_server_unrefp) DnsServer *server = NULL;
@@ -690,13 +692,15 @@ static void exercise_dns_query_go(GoConfig *cfg) {
         ASSERT_OK(sd_event_new(&manager.event));
         ASSERT_NOT_NULL(manager.event);
 
-        ASSERT_OK(dns_server_new(&manager, &server, type, link, family, &server_addr,
-                        port, ifindex, server_name, RESOLVE_CONFIG_SOURCE_DBUS));
+        if (cfg->has_scope) {
+                ASSERT_OK(dns_server_new(&manager, &server, type, link, family, &server_addr,
+                                port, ifindex, server_name, RESOLVE_CONFIG_SOURCE_DBUS));
 
-        ASSERT_NOT_NULL(server);
+                ASSERT_NOT_NULL(server);
 
-        ASSERT_OK(dns_scope_new(&manager, &scope, link, protocol, family));
-        ASSERT_NOT_NULL(scope);
+                ASSERT_OK(dns_scope_new(&manager, &scope, link, protocol, family));
+                ASSERT_NOT_NULL(scope);
+        }
 
         ASSERT_OK(dns_question_new_address(&question, AF_INET, "www.example.com", false));
         ASSERT_NOT_NULL(question);
@@ -717,25 +721,39 @@ static void exercise_dns_query_go(GoConfig *cfg) {
         }
 
         ASSERT_NOT_NULL(query);
-        ASSERT_OK(dns_query_go(query));
+        ASSERT_TRUE(dns_query_go(query));
+
+        if (check_query != NULL)
+                check_query(query);
 
         dns_server_unref(server);
         sd_event_unref(manager.event);
 }
 
+static void check_query_no_servers(DnsQuery *query) {
+        ASSERT_NOT_NULL(query);
+
+        ASSERT_EQ(dns_answer_size(query->answer), 0u);
+        ASSERT_EQ(query->answer_rcode, DNS_RCODE_SUCCESS);
+}
+
 TEST(dns_query_go) {
         GoConfig cfg;
 
         cfg = mk_go_config();
-        exercise_dns_query_go(&cfg);
+        exercise_dns_query_go(&cfg, NULL);
 
         cfg = mk_go_config();
         cfg.use_link = true;
-        exercise_dns_query_go(&cfg);
+        exercise_dns_query_go(&cfg, NULL);
 
         cfg = mk_go_config();
         cfg.use_bypass = true;
-        exercise_dns_query_go(&cfg);
+        exercise_dns_query_go(&cfg, NULL);
+
+        cfg = mk_go_config();
+        cfg.has_scope = false;
+        exercise_dns_query_go(&cfg, check_query_no_servers);
 }
 
 DEFINE_TEST_MAIN(LOG_DEBUG);