
commit 48a0b902b67da46f1eed4afa687bdcb56b59d02f Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Mon Dec 16 15:35:07 2019 +0200 Increase timouts in the mxs173_trottle_filter test commit 81d8083a89421a8004b8024d480ae0f35d715b86 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Mon Dec 16 14:19:39 2019 +0200 Increase timeouts in max1071_maxrow test commit e1039c6132f0e9274b8801165f3f905ede7c9421 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Mon Dec 16 00:06:53 2019 +0200 Remove hardcoded 'home/vagrant/' from all maxscale.cnf in system tests commit 28c8029e060afdcf5159bf802b13dcd5e484d9f1 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sun Dec 15 21:31:34 2019 +0200 Use private IP for Galera congiguration in maxscale-system-tests commit 66dc36cbf43a5fb92465df31e1295e82865be1fc Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sun Dec 15 09:06:28 2019 +0200 Fix typos in fwf_*.cpp commit 44c7a4384ddf39596c0254c955aeb6c008a00a35 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sun Dec 15 09:05:26 2019 +0200 Fix typos in fwf_*.cpp commit 2649017611908a8b0d27090f49722947ac31c4f4 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sun Dec 15 09:03:41 2019 +0200 Fix typos in fwf_*.cpp commit 5cc87658523e8496eaab17700be8a821af5b0cde Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sat Dec 14 23:54:53 2019 +0200 Fix typo in fwf_copy_rules.cpp commit fb1accc36cb9d79691469f63cb4535f3bc38dedd Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sat Dec 14 23:52:51 2019 +0200 More hardcoded 'vagrant' removals commit 77e49d474b4abe767629ff87b01f08137773d761 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sat Dec 14 23:35:09 2019 +0200 Fix hardcoded 'vagrant' user in fwf* tests Several firewall filter tests has hardcoded 'vagrant' as a user name for access user on the VM. Changed to node->access_user. commit ed5ab1487f37822db6a7478f76c0f3652776c389 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sat Dec 14 22:50:35 2019 +0200 Fix IP vs IP_private Many tests use IP instead of IP_private which makes them failed in the AWS or GCloud environment. The same applies to get_conn_num() etc functions. commit 0558aac23d303a675dc12d05b1766e698753b444 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Thu Aug 15 12:02:01 2019 +0300 fix IP -> IP_private for some mysqlmon* testst commit 5d9c70970d970eb995c8774d0088bd1c54ab76fe Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Sat Dec 14 20:20:51 2019 +0200 Replace IP to IP_private in the maxscale-system-tests commit b06cf3329af59ff100748691991213fe639f29e6 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Tue Nov 19 11:52:33 2019 +0200 Remove spaces from value which were read from *_network_config MDBCI can put spaces around values in the *_network_config file which can cause ssh connection failures in the tests. To fix it removing all spaces from all values which were read from *_network_config commit b3904f019847ef1db9d4ec9714ad9ef869fa0b01 Author: Timofey Turenko <timofey.turenko@mariadb.com> Date: Thu Dec 12 23:36:31 2019 +0200 Increate default timeout for all system tests
237 lines
7.6 KiB
C++
237 lines
7.6 KiB
C++
/**
|
|
* @file fwf - Firewall filter test (also regression test for MXS-683 "qc_mysqlembedded reports as-name
|
|
* instead of original-name")
|
|
* - setup Firewall filter to use rules from rule file fw/ruleXX, where XX - number of sub-test
|
|
* - execute queries for fw/passXX file, expect OK
|
|
* - execute queries from fw/denyXX, expect Access Denied error (mysql_error 1141)
|
|
* - repeat for all XX
|
|
* - setup Firewall filter to block queries next 2 minutes using 'at_time' statement (see template
|
|
* fw/rules_at_time)
|
|
* - start sending queries, expect Access Denied now and OK after two mintes
|
|
* - setup Firewall filter to limit a number of queries during certain time
|
|
* - start sending queries as fast as possible, expect OK for N first quries and Access Denied for next
|
|
* queries
|
|
* - wait, start sending queries again, but only one query per second, expect OK
|
|
* - try to load rules with syntax error, expect failure for all sessions and queries
|
|
*/
|
|
|
|
|
|
#include <iostream>
|
|
#include <ctime>
|
|
#include "testconnections.h"
|
|
#include "maxadmin_operations.h"
|
|
#include "sql_t1.h"
|
|
#include "fw_copy_rules.h"
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
TestConnections::skip_maxscale_start(true);
|
|
TestConnections* Test = new TestConnections(argc, argv);
|
|
int local_result;
|
|
char str[4096];
|
|
char sql[4096];
|
|
char pass_file[4096];
|
|
char deny_file[4096];
|
|
char rules_dir[4096];
|
|
FILE* file;
|
|
|
|
sprintf(rules_dir, "%s/fw/", test_dir);
|
|
int N = 19;
|
|
int i;
|
|
|
|
for (i = 1; i < N + 1; i++)
|
|
{
|
|
Test->set_timeout(180);
|
|
local_result = 0;
|
|
|
|
sprintf(str, "rules%d", i);
|
|
copy_rules(Test, str, rules_dir);
|
|
|
|
Test->maxscales->restart_maxscale(0);
|
|
Test->maxscales->connect_rwsplit(0);
|
|
|
|
sprintf(pass_file, "%s/fw/pass%d", test_dir, i);
|
|
sprintf(deny_file, "%s/fw/deny%d", test_dir, i);
|
|
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("Pass file: %s", pass_file);
|
|
Test->tprintf("Deny file: %s", deny_file);
|
|
}
|
|
|
|
file = fopen(pass_file, "r");
|
|
if (file != NULL)
|
|
{
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("********** Trying queries that should be OK ********** ");
|
|
}
|
|
while (fgets(sql, sizeof(sql), file))
|
|
{
|
|
if (strlen(sql) > 1)
|
|
{
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("%s", sql);
|
|
}
|
|
int rv = execute_query(Test->maxscales->conn_rwsplit[0], "%s", sql);
|
|
Test->add_result(rv, "Query should succeed: %s", sql);
|
|
local_result += rv;
|
|
}
|
|
}
|
|
fclose(file);
|
|
}
|
|
else
|
|
{
|
|
Test->add_result(1, "Error opening query file");
|
|
}
|
|
|
|
file = fopen(deny_file, "r");
|
|
if (file != NULL)
|
|
{
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("********** Trying queries that should FAIL ********** ");
|
|
}
|
|
while (fgets(sql, sizeof(sql), file))
|
|
{
|
|
Test->set_timeout(180);
|
|
if (strlen(sql) > 1)
|
|
{
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("%s", sql);
|
|
}
|
|
execute_query_silent(Test->maxscales->conn_rwsplit[0], sql);
|
|
if (mysql_errno(Test->maxscales->conn_rwsplit[0]) != 1141)
|
|
{
|
|
Test->tprintf("Expected 1141, Access Denied but got %d, %s instead: %s",
|
|
mysql_errno(Test->maxscales->conn_rwsplit[0]),
|
|
mysql_error(Test->maxscales->conn_rwsplit[0]),
|
|
sql);
|
|
local_result++;
|
|
}
|
|
}
|
|
}
|
|
fclose(file);
|
|
}
|
|
else
|
|
{
|
|
Test->add_result(1, "Error opening query file");
|
|
}
|
|
|
|
if (local_result)
|
|
{
|
|
Test->add_result(1, "********** rules%d test FAILED", i);
|
|
}
|
|
else
|
|
{
|
|
Test->tprintf("********** rules%d test PASSED", i);
|
|
}
|
|
|
|
mysql_close(Test->maxscales->conn_rwsplit[0]);
|
|
}
|
|
|
|
Test->set_timeout(180);
|
|
|
|
// Test for at_times clause
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("Trying at_times clause");
|
|
}
|
|
copy_rules(Test, (char*) "rules_at_time", rules_dir);
|
|
|
|
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("DELETE quries without WHERE clause will be blocked during the 15 seconds");
|
|
Test->tprintf("Put time to rules.txt: %s", str);
|
|
}
|
|
Test->maxscales->ssh_node_f(0,
|
|
false,
|
|
"start_time=`date +%%T`;"
|
|
"stop_time=` date --date \"now +15 secs\" +%%T`;"
|
|
"%s sed -i \"s/###time###/$start_time-$stop_time/\" %s/rules/rules.txt",
|
|
Test->maxscales->access_sudo[0],
|
|
Test->maxscales->access_homedir[0]);
|
|
|
|
Test->maxscales->restart_maxscale(0);
|
|
Test->maxscales->connect_rwsplit(0);
|
|
|
|
Test->tprintf("Trying 'DELETE FROM t1' and expecting FAILURE");
|
|
execute_query_silent(Test->maxscales->conn_rwsplit[0], "DELETE FROM t1");
|
|
|
|
if (mysql_errno(Test->maxscales->conn_rwsplit[0]) != 1141)
|
|
{
|
|
Test->add_result(1,
|
|
"Query succeded, but fail expected, errono is %d",
|
|
mysql_errno(Test->maxscales->conn_rwsplit[0]));
|
|
}
|
|
|
|
Test->tprintf("Waiting 16 seconds and trying 'DELETE FROM t1', expecting OK");
|
|
|
|
Test->stop_timeout();
|
|
sleep(16);
|
|
Test->set_timeout(180);
|
|
Test->try_query(Test->maxscales->conn_rwsplit[0], "DELETE FROM t1");
|
|
|
|
mysql_close(Test->maxscales->conn_rwsplit[0]);
|
|
Test->maxscales->stop_maxscale(0);
|
|
|
|
Test->tprintf("Trying limit_queries clause");
|
|
Test->tprintf("Copying rules to Maxscale machine: %s", str);
|
|
copy_rules(Test, (char*) "rules_limit_queries", rules_dir);
|
|
|
|
Test->maxscales->start_maxscale(0);
|
|
Test->maxscales->connect_rwsplit(0);
|
|
|
|
Test->tprintf("Trying 10 quries as fast as possible");
|
|
for (i = 0; i < 10; i++)
|
|
{
|
|
Test->add_result(execute_query_silent(Test->maxscales->conn_rwsplit[0], "SELECT * FROM t1"),
|
|
"%d -query failed",
|
|
i);
|
|
}
|
|
|
|
Test->tprintf("Expecting failures during next 5 seconds");
|
|
|
|
time_t start_time_clock = time(NULL);
|
|
timeval t1, t2;
|
|
double elapsedTime;
|
|
gettimeofday(&t1, NULL);
|
|
|
|
do
|
|
{
|
|
gettimeofday(&t2, NULL);
|
|
elapsedTime = (t2.tv_sec - t1.tv_sec);
|
|
elapsedTime += (double) (t2.tv_usec - t1.tv_usec) / 1000000.0;
|
|
}
|
|
while ((execute_query_silent(Test->maxscales->conn_rwsplit[0], "SELECT * FROM t1") != 0)
|
|
&& (elapsedTime < 10));
|
|
|
|
Test->tprintf("Quries were blocked during %f (using clock_gettime())", elapsedTime);
|
|
Test->tprintf("Quries were blocked during %lu (using time())", time(NULL) - start_time_clock);
|
|
|
|
if ((elapsedTime > 6) or (elapsedTime < 4))
|
|
{
|
|
Test->add_result(1, "Queries were blocked during wrong time");
|
|
}
|
|
|
|
Test->set_timeout(180);
|
|
Test->tprintf("Trying 12 quries, 1 query / second");
|
|
for (i = 0; i < 12; i++)
|
|
{
|
|
sleep(1);
|
|
Test->add_result(execute_query_silent(Test->maxscales->conn_rwsplit[0], "SELECT * FROM t1"),
|
|
"query failed");
|
|
if (Test->verbose)
|
|
{
|
|
Test->tprintf("%d ", i);
|
|
}
|
|
}
|
|
|
|
int rval = Test->global_result;
|
|
delete Test;
|
|
return rval;
|
|
}
|