From 4a6ab0c4e1a0f5c8131c8fa6507b0574e56571ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 29 Jun 2021 02:01:07 +0200 Subject: [PATCH] Test to verify SSL and compression on Admin --- test/tap/tests/test_ssl_connect-t.cpp | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/tap/tests/test_ssl_connect-t.cpp diff --git a/test/tap/tests/test_ssl_connect-t.cpp b/test/tap/tests/test_ssl_connect-t.cpp new file mode 100644 index 000000000..8e8713825 --- /dev/null +++ b/test/tap/tests/test_ssl_connect-t.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "tap.h" +#include "command_line.h" +#include "utils.h" + +using std::string; + +/* this test: + * enables mysql-have_ssl + * retrieves all tables in the most important schemas + * for each table, it connects with SSL *and* compression, then retrieves all rows +*/ + +int main() { + CommandLine cl; + + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } + + + MYSQL* proxysql_admin = mysql_init(NULL); + // Initialize connections + if (!proxysql_admin) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return -1; + } + + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return -1; + } + + MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); + MYSQL_QUERY(proxysql_admin, "SET mysql-have_compress='true'"); + MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); + + std::vector tables; + std::vector schemas = { "main", "stats", "disk", "monitor" }; + for (std::vector::iterator s = schemas.begin(); s != schemas.end(); s++) { + std::string q = "SHOW TABLES FROM " + *s; + MYSQL_QUERY(proxysql_admin, q.c_str()); + + MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin); + MYSQL_ROW row; + while ((row = mysql_fetch_row(proxy_res))) { + std::string table(row[0]); + table = *s + "." + table; + tables.push_back(table); + } + mysql_free_result(proxy_res); + } + mysql_close(proxysql_admin); + plan(tables.size()); + + + for (std::vector::iterator it = tables.begin(); it != tables.end(); it++) { + MYSQL* proxysql_admin = mysql_init(NULL); // redefined locally + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return -1; + } + const char * c = mysql_get_ssl_cipher(proxysql_admin); + std::string q = "SELECT * FROM " + *it; + MYSQL_QUERY(proxysql_admin, q.c_str()); + MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin); + unsigned long rows = proxy_res->row_count; + mysql_free_result(proxy_res); + ok(c != NULL && proxysql_admin->net.compress == 1, "cipher %s and compression (%d) used while reading %lu from table %s", c, proxysql_admin->net.compress, rows, it->c_str()); + mysql_close(proxysql_admin); + } + + return exit_status(); +}