/** * @file test_change_user-t.cpp * @brief Test various mysql_change_user() * @details Create connections with both mysql_native_password and caching_sha2_password * and try to reset them */ #include #include #include #include #include #include "mysql.h" // copied from ma_common.h , but only the beginning struct st_mysql_options_extension { char *plugin_dir; char *default_auth; // README: the struct is more complex, but we only need default_auth }; #include "tap.h" #include "command_line.h" #include "utils.h" #include "json.hpp" using std::pair; using std::string; using namespace std; using nlohmann::json; #define NCONNS 16 int run_queries_sets(std::vector& queries, MYSQL *my, const std::string& message_prefix) { for (std::vector::iterator it = queries.begin(); it != queries.end(); it++) { std::string q = *it; diag("%s: %s", message_prefix.c_str(), q.c_str()); MYSQL_QUERY(my, q.c_str()); } return 0; } void parse_result_json_column(MYSQL_RES *result, json& j) { if(!result) return; MYSQL_ROW row; while ((row = mysql_fetch_row(result))) { j = json::parse(row[0]); } } int get_internal_session(MYSQL *my, json& j) { MYSQL_QUERY(my, "PROXYSQL INTERNAL SESSION"); MYSQL_RES* tr_res = mysql_store_result(my); parse_result_json_column(tr_res, j); mysql_free_result(tr_res); return 0; } MYSQL* proxy[NCONNS]; MYSQL* admin = NULL; bool create_connections(const CommandLine& cl, const char *plugin, bool use_ssl, bool check_plugin, bool check_ssl, bool incorrect_connect_password) { diag("Calling create_connections with plugin: %s , use_ssl: %d , check_plugin: %d , check_ssl: %d , incorrect_connect_password: %d", plugin, use_ssl, check_plugin, check_ssl, incorrect_connect_password); MYSQL * my = NULL; int rc = 0; for (int i=0; ioptions.extension->default_auth) != 0) { ok(false, "Plugin wanted: %s , used: %s", plugin, proxy[i]->options.extension->default_auth); return false; } } } else { ok(my == NULL, "Connect should fail"); } } return true; } void close_connections() { for (int i=0; i> vec = { {"mysql_native_password", false}, {"mysql_native_password", true}, {"caching_sha2_password", true} }; for (auto it = vec.begin(); it != vec.end() ; it++) { diag("%d: Starting testing plugin %s and ssl %d" , __LINE__, it->first.c_str(), it->second); diag("Setting mysql-default_authentication_plugin='%s'", plugin); vector query_set1 = {"SET mysql-default_authentication_plugin='" + string(plugin) + "'", "LOAD MYSQL VARIABLES TO RUNTIME"}; if (run_queries_sets( query_set1 , admin, "Running on Admin")) return exit_status(); const char *auth_plugin = it->first.c_str(); vector query_set2 = {string(string("SET mysql-have_ssl='") + (it->second ? "true" : "false") + "'"), "LOAD MYSQL VARIABLES TO RUNTIME"}; if (run_queries_sets( query_set2 , admin, "Running on Admin")) return exit_status(); if (create_connections(cl, auth_plugin, false, true, test_ssl, incorrect_connect_password) != true) { return exit_status(); } if (incorrect_connect_password == false) { if (test_plugin) { for (int i = 0; ifirst == "caching_sha2_password") { s = string(plugin); } ok(j["client"]["prot"]["auth_plugin"] == s, "%s: %d: Plugin wanted: %s , used: %s", plugin, __LINE__, auth_plugin, string(j["client"]["prot"]["auth_plugin"]).c_str()); } } if (change_user) { for (int i = 0; i