diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 233e7cd3..85657e60 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -1323,7 +1323,9 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->net.conn_hdlr->plugin= plugin; if (plugin && plugin->connect) + { return plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); + } } return mysql->methods->db_connect(mysql, host, user, passwd, diff --git a/plugins/connection/aurora.c b/plugins/connection/aurora.c index 3697e608..2ac5de00 100644 --- a/plugins/connection/aurora.c +++ b/plugins/connection/aurora.c @@ -362,7 +362,7 @@ MYSQL *aurora_connect_instance(AURORA *aurora, AURORA_INSTANCE *instance, MYSQL aurora->database, instance->port ? instance->port : aurora->port, NULL, - aurora->client_flag)) + aurora->client_flag | CLIENT_REMEMBER_OPTIONS)) { /* connection not available */ instance->blacklisted= time(NULL); @@ -630,8 +630,13 @@ MYSQL *aurora_connect(MYSQL *mysql, const char *host, const char *user, const ch aurora->active[AURORA_PRIMARY]= 1; aurora->pvio[AURORA_PRIMARY]= aurora->mysql[AURORA_PRIMARY]->net.pvio; } + else + aurora->pvio[AURORA_PRIMARY]= NULL; } + if (!aurora->pvio[AURORA_PRIMARY] && !aurora->pvio[AURORA_REPLICA]) + goto error; + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); ENABLE_AURORA(mysql); return mysql; @@ -676,6 +681,11 @@ void aurora_close(MYSQL *mysql) MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr; AURORA *aurora= (AURORA *)hdlr->data; + if (!aurora->pvio[AURORA_PRIMARY] && !aurora->pvio[AURORA_REPLICA]) + { + return; + } + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); /* if the connection is not active yet, just return */ @@ -702,7 +712,7 @@ void aurora_close(MYSQL *mysql) mariadb_api->mysql_close(aurora->mysql[AURORA_PRIMARY]); } - /* free masrwe information */ + /* free information */ aurora_close_memory(aurora); } /* }}} */ diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index 7d1c0be4..77867cb2 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -21,9 +21,11 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) ADD_DEFINITIONS(-DLIBMARIADB) -SET(API_TESTS "t_aurora" "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" - "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol") +SET(API_TESTS "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" + "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol") +#exclude following tests from ctests, since we need to run them maually with different credentials +SET(MANUAL_TESTS "t_aurora") # Get finger print from server certificate IF(WITH_SSL) @@ -62,3 +64,8 @@ FOREACH(API_TEST ${API_TESTS}) ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST}) SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120) ENDFOREACH(API_TEST) + +FOREACH(API_TEST ${MANUAL_TESTS}) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c ${CMAKE_SOURCE_DIR}/libmariadb/getopt.c) + TARGET_LINK_LIBRARIES(${API_TEST} mytap libmariadb) +ENDFOREACH() diff --git a/unittest/libmariadb/t_aurora.c b/unittest/libmariadb/t_aurora.c index d9c89c45..4336a3c5 100644 --- a/unittest/libmariadb/t_aurora.c +++ b/unittest/libmariadb/t_aurora.c @@ -2,12 +2,13 @@ */ #include "my_test.h" +#include "ma_pvio.h" static int aurora1(MYSQL *mysql) { int rc; my_bool read_only= 1; - char *primary, *replica; + const char *primary, *schema; MYSQL_RES *res; rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); @@ -19,7 +20,7 @@ static int aurora1(MYSQL *mysql) rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1, 'foo'), (2, 'bar')"); check_mysql_rc(rc, mysql); - primary= mysql->host; + mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &primary); diag("primary: %s", primary); mysql_options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, &read_only); @@ -37,15 +38,29 @@ static int aurora1(MYSQL *mysql) diag("Num_rows: %d", mysql_num_rows(res)); mysql_free_result(res); - replica= mysql->host; - diag("replica: %s", replica); - diag("db: %s", mysql->db); + mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &schema); + diag("db: %s", schema); return OK; } +static int test_wrong_user(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + + if (mysql_real_connect(mysql, hostname, "wrong_user", NULL, NULL, 0, NULL, 0)) + { + diag("Error expected"); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + return OK; +} + struct my_tests_st my_tests[] = { {"aurora1", aurora1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_wrong_user", test_wrong_user, TEST_CONNECTION_NONE, 0, NULL, NULL}, {NULL, NULL, 0, 0, NULL, NULL} };