From 65975a38e254b3f7c74ccd9997e472bb94f56ab9 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Thu, 21 Mar 2019 15:46:09 +0200 Subject: [PATCH] Add test for MXS-2355 The test attempts to log in using mysql_clear_password. --- maxscale-system-test/CMakeLists.txt | 3 + maxscale-system-test/mxs2355_wrong_auth.cpp | 61 +++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 maxscale-system-test/mxs2355_wrong_auth.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 52f7512f0..52b5acfc5 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -210,6 +210,9 @@ add_test_executable(kill_query.cpp kill_query replication LABELS REPL_BACKEND) # MXS-2250: DESCRIBE on temporary table should work. add_test_executable(mxs2250_describe_temp_table.cpp mxs2250_describe_temp_table mxs2250_describe_temp_table LABELS REPL_BACKEND) +# MXS-2355: Try to log in using a different authentication plugin +add_test_executable(mxs2355_wrong_auth.cpp mxs2355_wrong_auth maxctrl LABELS REPL_BACKEND) + ############################################ # BEGIN: Tests that require GTID # ############################################ diff --git a/maxscale-system-test/mxs2355_wrong_auth.cpp b/maxscale-system-test/mxs2355_wrong_auth.cpp new file mode 100644 index 000000000..0011e0a80 --- /dev/null +++ b/maxscale-system-test/mxs2355_wrong_auth.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2019 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl11. + * + * Change Date: 2020-01-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#include "testconnections.h" + +// Try to connect with mysql client using the plugin "mysql_clear_password". MaxScale should switch back +// to "mysql_native_password". + +int main(int argc, char** argv) +{ + TestConnections test(argc, argv); + const char* host = test.maxscales->IP[0]; + int port = test.maxscales->ports[0][0]; + const char* user = test.maxscales->user_name; + const char* pass = test.maxscales->password; + const char plugin[] = "mysql_clear_password"; + + test.tprintf("Trying to log in to [%s]:%i as %s with plugin '%s'.\n", host, port, user, plugin); + MYSQL* maxconn = mysql_init(NULL); + test.expect(maxconn, "mysql_init failed"); + if (maxconn) + { + // Need to set plugin directory so that mysql_clear_password is found. + const char plugin_path[] = "../connector-c/install/lib/mariadb/plugin"; + mysql_optionsv(maxconn, MYSQL_PLUGIN_DIR, plugin_path); + mysql_optionsv(maxconn, MYSQL_DEFAULT_AUTH, plugin); + mysql_real_connect(maxconn, host, user, pass, NULL, port, NULL, 0); + auto err = mysql_error(maxconn); + if (*err) + { + test.expect(false, "Could not log in: '%s'", err); + } + else + { + test.try_query(maxconn, "SELECT rand();"); + if (test.ok()) + { + test.tprintf("Logged in and queried successfully.\n"); + test.log_includes(0, "is using an unsupported authenticator plugin 'mysql_clear_password'."); + } + else + { + test.tprintf("Query rejected: '%s'\n", mysql_error(maxconn)); + } + } + mysql_close(maxconn); + } + + + return test.global_result; +}