1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Added new test for testing binding interfaces:

To run these tests a TCP/IP connection is required and
  the environment variable MYSQL_TEST_BINADDR has to be specified.
This commit is contained in:
Georg Richter
2015-11-02 18:42:00 +01:00
parent ff13c9f749
commit e85caa83ca
2 changed files with 79 additions and 5 deletions

View File

@@ -750,8 +750,8 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
{ {
PVIO_SET_ERROR(cinfo->mysql, CR_UNKNOWN_HOST, SQLSTATE_UNKNOWN, PVIO_SET_ERROR(cinfo->mysql, CR_UNKNOWN_HOST, SQLSTATE_UNKNOWN,
ER(CR_UNKNOWN_HOST), cinfo->host, gai_rc); ER(CR_UNKNOWN_HOST), cinfo->host, gai_rc);
if (bres) if (bind_res)
freeaddrinfo(bres); freeaddrinfo(bind_res);
goto error; goto error;
} }
@@ -767,9 +767,9 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
if (bind_res) if (bind_res)
{ {
for (bind_res= bres; bind_res; bind_res= bind_res->ai_next) for (bres= bind_res; bres; bres= bres->ai_next)
{ {
if (!(rc= bind(csock->socket, bind_res->ai_addr, bind_res->ai_addrlen))) if (!(rc= bind(csock->socket, bres->ai_addr, bres->ai_addrlen)))
break; break;
} }
if (rc) if (rc)
@@ -795,7 +795,8 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
} }
freeaddrinfo(res); freeaddrinfo(res);
freeaddrinfo(bres); if (bind_res)
freeaddrinfo(bind_res);
if (csock->socket == SOCKET_ERROR) if (csock->socket == SOCKET_ERROR)
{ {

View File

@@ -669,7 +669,80 @@ static int test_conc118(MYSQL *mysql)
return OK; return OK;
} }
static int test_wrong_bind_address(MYSQL *my)
{
char *bind_addr= "100.188.111.112";
MYSQL *mysql;
if (!strcmp(hostname, "localhost"))
{
diag("test doesn't work with unix sockets");
return SKIP;
}
mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_OPT_BIND, bind_addr);
if (mysql_real_connect(mysql, hostname, username,
password, schema, port, socketname, 0))
{
diag("Error expected");
mysql_close(mysql);
return FAIL;
}
diag("Error: %s", mysql_error(mysql));
mysql_close(mysql);
return OK;
}
static int test_bind_address(MYSQL *my)
{
MYSQL *mysql;
char *bind_addr= getenv("MYSQL_TEST_BINDADDR");
char query[128];
int rc;
if (!strcmp(hostname, "localhost"))
{
diag("test doesn't work with unix sockets");
return SKIP;
}
sprintf(query, "DROP USER '%s'@'%s'", username, bind_addr);
rc= mysql_query(my, query);
sprintf(query, "CREATE USER '%s'@'%s'", username, bind_addr);
rc= mysql_query(my, query);
check_mysql_rc(rc, my);
sprintf(query, "GRANT ALL ON %s.* TO '%s'@'%s'", schema, username, bind_addr);
rc= mysql_query(my, query);
check_mysql_rc(rc, my);
if (!bind_addr)
{
diag("No bind address specified");
return SKIP;
}
mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_OPT_BIND, bind_addr);
if (!mysql_real_connect(mysql, bind_addr, username,
password, schema, port, socketname, 0))
{
diag("Error: %s\n", mysql_error(mysql));
mysql_close(mysql);
return FAIL;
}
diag("%s", mysql_get_host_info(mysql));
mysql_close(mysql);
return OK;
}
struct my_tests_st my_tests[] = { struct my_tests_st my_tests[] = {
{"test_wrong_bind_address", test_wrong_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_bind_address", test_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc118", test_conc118, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc118", test_conc118, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc66", test_conc66, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc66", test_conc66, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_bug20023", test_bug20023, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_bug20023", test_bug20023, TEST_CONNECTION_NEW, 0, NULL, NULL},