From: Fabiano Rosas <[email protected]> Make sure the TLS options handling is working correctly with a NULL parameter. This is relevant due to the usage of StrOrNull for the tls-creds, tls-authz and tls-hostname options.
With this, all manners of passing TLS options are somehow covered by the tests, we should not need to do manual testing when touching TLS options code. Signed-off-by: Fabiano Rosas <[email protected]> Reviewed-by: Peter Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]> --- tests/qtest/migration/migration-qmp.h | 1 + tests/qtest/migration/migration-qmp.c | 9 +++++ tests/qtest/migration/tls-tests.c | 56 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/tests/qtest/migration/migration-qmp.h b/tests/qtest/migration/migration-qmp.h index 44482d250f..940ffd5950 100644 --- a/tests/qtest/migration/migration-qmp.h +++ b/tests/qtest/migration/migration-qmp.h @@ -36,6 +36,7 @@ void migrate_set_parameter_str(QTestState *who, const char *parameter, const char *value); void migrate_set_parameter_strv(QTestState *who, const char *parameter, char **strv); +void migrate_set_parameter_null(QTestState *who, const char *parameter); void migrate_set_parameter_bool(QTestState *who, const char *parameter, int value); void migrate_ensure_non_converge(QTestState *who); diff --git a/tests/qtest/migration/migration-qmp.c b/tests/qtest/migration/migration-qmp.c index c803fcee9d..5c46ceb3e6 100644 --- a/tests/qtest/migration/migration-qmp.c +++ b/tests/qtest/migration/migration-qmp.c @@ -458,6 +458,15 @@ void migrate_set_parameter_strv(QTestState *who, const char *parameter, qtest_qmp_assert_success(who, command, parameter); } +void migrate_set_parameter_null(QTestState *who, const char *parameter) +{ + qtest_qmp_assert_success(who, + "{ 'execute': 'migrate-set-parameters'," + "'arguments': { %s: null } }", + parameter); + migrate_check_parameter_str(who, parameter, ""); +} + static long long migrate_get_parameter_bool(QTestState *who, const char *parameter) { diff --git a/tests/qtest/migration/tls-tests.c b/tests/qtest/migration/tls-tests.c index 21e9fec87d..e0e8a7335c 100644 --- a/tests/qtest/migration/tls-tests.c +++ b/tests/qtest/migration/tls-tests.c @@ -507,6 +507,57 @@ static void test_precopy_tcp_tls_psk_mismatch(void) test_precopy_common(&args); } +static void *migrate_hook_start_no_tls(QTestState *from, QTestState *to) +{ + struct TestMigrateTLSPSKData *data = + g_new0(struct TestMigrateTLSPSKData, 1); + + migrate_set_parameter_null(from, "tls-creds"); + migrate_set_parameter_null(to, "tls-creds"); + + return data; +} + +static void test_precopy_tcp_no_tls(void) +{ + MigrateCommon args = { + .listen_uri = "tcp:127.0.0.1:0", + .start_hook = migrate_hook_start_no_tls, + .end_hook = migrate_hook_end_tls_psk, + }; + + test_precopy_common(&args); +} + +static void * +migrate_hook_start_tls_x509_no_host(QTestState *from, QTestState *to) +{ + TestMigrateTLSX509 args = { + .verifyclient = true, + .clientcert = true, + .authzclient = true, + }; + TestMigrateTLSX509Data *data = migrate_hook_start_tls_x509_common(from, to, + &args); + migrate_set_parameter_null(from, "tls-hostname"); + migrate_set_parameter_null(to, "tls-hostname"); + + return data; +} + +static void test_precopy_tcp_tls_no_hostname(void) +{ + MigrateCommon args = { + .listen_uri = "tcp:127.0.0.1:0", + .start_hook = migrate_hook_start_tls_x509_no_host, + .end_hook = migrate_hook_end_tls_x509, + .result = MIG_TEST_FAIL_DEST_QUIT_ERR, + .start.hide_stderr = true, + }; + + test_precopy_common(&args); +} + #ifdef CONFIG_TASN1 static void test_precopy_tcp_tls_x509_default_host(void) { @@ -799,6 +850,11 @@ void migration_test_add_tls(MigrationTestEnv *env) return; } + migration_test_add("/migration/precopy/tcp/no-tls", + test_precopy_tcp_no_tls); + migration_test_add("/migration/precopy/tcp/tls/no-hostname", + test_precopy_tcp_tls_no_hostname); + migration_test_add("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); -- 2.50.1
