]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: test-smtp-payload - Inject ssl settings into the SMTP server settings
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Tue, 12 Dec 2023 15:23:17 +0000 (16:23 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:10 +0000 (12:34 +0200)
This is necessary for the new SMTP SNI mechanism to succeed its settings
lookup.

src/lib-smtp/test-smtp-payload.c

index 2c75d75274b8c0cfe2101aa7f759f96b02187aa4..23d7d6710ce1730f649fbbed73e8b54573259d6f 100644 (file)
@@ -18,6 +18,7 @@
 #include "connection.h"
 #include "test-common.h"
 #include "test-subprocess.h"
+#include "settings.h"
 #include "smtp-server.h"
 #include "smtp-client.h"
 #include "smtp-client-connection.h"
@@ -845,6 +846,7 @@ static void test_client_deinit(void)
 
 struct test_server_data {
        const struct smtp_server_settings *server_set;
+       struct settings_simple *settings;
 };
 
 static void test_open_server_fd(void)
@@ -882,6 +884,11 @@ static int test_run_server(struct test_server_data *data)
        i_close_fd(&fd_listen);
        test_files_deinit();
        main_deinit();
+
+       /* Cleanup the test settings in the server process as well.
+          See test_run_client_server() for the appropriate cleanup call in the
+          main process. */
+       settings_simple_deinit(data->settings);
        return 0;
 }
 
@@ -924,8 +931,22 @@ test_run_client_server(
 
        failure = NULL;
 
+       /* Add SSL settings by name into the basis of the SMTP server settings.
+          Otherwise the SMTP SNI mechanism will break when looking up the
+          relevant settings. */
+       const char *const settings[] = {
+               "ssl_ca", server_set->ssl->ca,
+               "ssl_cert", server_set->ssl->cert.cert,
+               "ssl_key", server_set->ssl->cert.key,
+               NULL,
+       };
+       struct settings_simple test_set;
+       settings_simple_init(&test_set, settings);
+       server_set->event_parent = test_set.event;
+
        i_zero(&data);
        data.server_set = server_set;
+       data.settings = &test_set;
 
        test_files_init();
 
@@ -943,6 +964,13 @@ test_run_client_server(
        bind_port = 0;
        test_subprocess_kill_all(SERVER_KILL_TIMEOUT_SECS);
        test_files_deinit();
+
+       /* Cleanup the test settings in the main process.
+          Note: This needs to be called as well in the server process,
+          otherwise it will leak it's event and the looked up settings
+          struct. See test_run_server() for the appropriate cleanup call in
+          the server process. */
+       settings_simple_deinit(&test_set);
 }
 
 static void