Combine redundant dbfwfilter tests

The fwf test now only tests the functionality of the rules themselves, not
the parsing. The fwf_syntax test handles the testing of the parser. The
fwf2 test was removed as it was almost identical with the original fwf
test.
This commit is contained in:
Markus Mäkelä 2017-09-19 14:10:19 +03:00
parent 773bae1615
commit 049eb68254
19 changed files with 24 additions and 161 deletions

View File

@ -257,7 +257,6 @@ add_test_executable(false_monitor_state_change.cpp false_monitor_state_change re
# A set of tests for Firewall filter
add_test_executable(fwf.cpp fwf fwf LABELS dbfwfilter REPL_BACKEND)
add_test_executable(fwf2.cpp fwf2 fwf LABELS dbfwfilter REPL_BACKEND)
add_test_executable(fwf_duplicate_rules.cpp fwf_duplicate_rules fwf LABELS dbfwfilter REPL_BACKEND)
add_test_executable(fwf_prepared_stmt.cpp fwf_prepared_stmt fwf LABELS dbfwfilter REPL_BACKEND)
add_test_executable(fwf_actions.cpp fwf_actions fwf_action LABELS dbfwfilter REPL_BACKEND)

View File

@ -1,30 +1,15 @@
#include "fw_copy_rules.h"
#include <string>
#include <sstream>
void copy_rules(TestConnections* Test, const char* rules_name, const char* rules_dir)
{
Test->set_timeout(30);
Test->ssh_maxscale(true, "cd %s;"
"rm -rf rules;"
"mkdir rules;"
"chown vagrant:vagrant rules -R",
Test->maxscale_access_homedir);
std::stringstream src;
std::stringstream dest;
src << rules_dir << "/" << rules_name;
dest << Test->maxscale_access_homedir << "/rules/rules.txt";
Test->set_timeout(30);
std::string src;
std::string dest;
src += rules_dir;
src += "/";
src += rules_name;
dest += Test->maxscale_access_homedir;
dest += "/rules/rules.txt";
Test->copy_to_maxscale(src.c_str(), dest.c_str());
Test->set_timeout(30);
Test->ssh_maxscale(true, "chown maxscale:maxscale %s/rules -R", Test->maxscale_access_homedir);
Test->copy_to_maxscale(src.str().c_str(), dest.str().c_str());
Test->stop_timeout();
}

View File

@ -32,8 +32,14 @@ int main(int argc, char *argv[])
char rules_dir[4096];
FILE* file;
Test->ssh_maxscale(true, "cd %s;"
"rm -rf rules;"
"mkdir rules;"
"chown vagrant:vagrant rules",
Test->maxscale_access_homedir);
sprintf(rules_dir, "%s/fw/", test_dir);
int N = 13;
int N = 18;
int i;
for (i = 1; i < N + 1; i++)
@ -41,12 +47,10 @@ int main(int argc, char *argv[])
Test->set_timeout(180);
local_result = 0;
Test->stop_maxscale();
sprintf(str, "rules%d", i);
copy_rules(Test, str, rules_dir);
Test->start_maxscale();
Test->restart_maxscale();
Test->connect_rwsplit();
sprintf(pass_file, "%s/fw/pass%d", test_dir, i);
@ -130,7 +134,6 @@ int main(int argc, char *argv[])
}
Test->set_timeout(180);
Test->stop_maxscale();
// Test for at_times clause
if (Test->verbose)
@ -142,14 +145,15 @@ int main(int argc, char *argv[])
if (Test->verbose)
{
Test->tprintf("DELETE quries without WHERE clause will be blocked during next 2 minutes");
Test->tprintf("DELETE quries without WHERE clause will be blocked during the 15 seconds");
Test->tprintf("Put time to rules.txt: %s", str);
}
Test->ssh_maxscale(false, "start_time=`date +%%T`; stop_time=` date --date "
"\"now +2 mins\" +%%T`; %s sed -i \"s/###time###/$start_time-$stop_time/\" %s/rules/rules.txt",
Test->ssh_maxscale(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->maxscale_access_sudo, Test->maxscale_access_homedir);
Test->start_maxscale();
Test->restart_maxscale();
Test->connect_rwsplit();
Test->tprintf("Trying 'DELETE FROM t1' and expecting FAILURE");
@ -160,10 +164,10 @@ int main(int argc, char *argv[])
Test->add_result(1, "Query succeded, but fail expected, errono is %d", mysql_errno(Test->conn_rwsplit));
}
Test->tprintf("Waiting 3 minutes and trying 'DELETE FROM t1', expecting OK");
Test->tprintf("Waiting 16 seconds and trying 'DELETE FROM t1', expecting OK");
Test->stop_timeout();
sleep(180);
sleep(16);
Test->set_timeout(180);
Test->try_query(Test->conn_rwsplit, "DELETE FROM t1");
@ -190,7 +194,6 @@ int main(int argc, char *argv[])
double elapsedTime;
gettimeofday(&t1, NULL);
do
{
gettimeofday(&t2, NULL);
@ -208,8 +211,8 @@ int main(int argc, char *argv[])
}
Test->set_timeout(180);
printf("Trying 20 quries, 1 query / second");
for (i = 0; i < 20; i++)
Test->tprintf("Trying 12 quries, 1 query / second");
for (i = 0; i < 12; i++)
{
sleep(1);
Test->add_result(execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1"), "query failed");
@ -219,26 +222,6 @@ int main(int argc, char *argv[])
}
}
Test->set_timeout(180);
Test->tprintf("Stopping Maxscale");
Test->stop_maxscale();
Test->tprintf("Trying rules with syntax error");
Test->tprintf("Copying rules to Maxscale machine: %s", str);
copy_rules(Test, (char *) "rules_syntax_error", rules_dir);
Test->tprintf("Starting Maxscale");
Test->start_maxscale();
Test->connect_rwsplit();
Test->tprintf("Trying to connect to Maxscale when 'rules' has syntax error, expecting failures");
if (execute_query(Test->conn_rwsplit, "SELECT * FROM t1") == 0)
{
Test->add_result(1, "Rule has syntax error, but query OK");
}
Test->check_maxscale_processes(0);
int rval = Test->global_result;
delete Test;
return rval;

View File

@ -1,104 +0,0 @@
/**
* @file fwf - Firewall filtyer test
* - 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 read_and_execute_queries(TestConnections *Test, const char* filename, int expected)
{
FILE *file = fopen(filename, "r");
int local_result = 0;
if (file != NULL)
{
char sql[4096];
while (fgets(sql, sizeof(sql), file))
{
Test->set_timeout(60);
if (strlen(sql) > 1)
{
Test->tprintf("%s", sql);
if (execute_query(Test->conn_rwsplit, sql) != expected &&
(expected == 1 || mysql_errno(Test->conn_rwsplit) == 1141))
{
Test->tprintf("Query %s, but %s expected, MySQL error: %d, %s\n",
expected ? "succeeded" : "failed",
expected ? "failure" : "success",
mysql_errno(Test->conn_rwsplit), mysql_error(Test->conn_rwsplit));
local_result++;
}
}
}
fclose(file);
}
else
{
Test->add_result(1, "Error opening file '%s'\n", filename);
}
return local_result;
}
int main(int argc, char *argv[])
{
TestConnections::skip_maxscale_start(true);
TestConnections * Test = new TestConnections(argc, argv);
int local_result;
char str[4096];
char pass_file[4096];
char deny_file[4096];
char rules_dir[4096];
FILE* file;
sprintf(rules_dir, "%s/fw2/", test_dir);
int N = 5;
int i;
for (i = 1; i < N + 1; i++)
{
Test->set_timeout(60);
local_result = 0;
Test->stop_maxscale();
sprintf(str, "rules%d", i);
copy_rules(Test, str, rules_dir);
Test->start_maxscale();
Test->connect_rwsplit();
sprintf(pass_file, "%s/fw2/pass%d", test_dir, i);
sprintf(deny_file, "%s/fw2/deny%d", test_dir, i);
Test->tprintf("********** Trying queries that should be OK ********** \n");
local_result += read_and_execute_queries(Test, pass_file, 0);
Test->tprintf("********** Trying queries that should FAIL ********** \n");
local_result += read_and_execute_queries(Test, deny_file, 1);
Test->add_result(local_result, "********** rules%d test FAILED\n", i);
mysql_close(Test->conn_rwsplit);
}
Test->check_maxscale_processes(1);
int rval = Test->global_result;
delete Test;
return rval;
}