From 049eb682542e56b1ffc805815f4fe8fbaccb401d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 19 Sep 2017 14:10:19 +0300 Subject: [PATCH] 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. --- maxscale-system-test/CMakeLists.txt | 1 - maxscale-system-test/{fw2/deny1 => fw/deny14} | 0 maxscale-system-test/{fw2/deny2 => fw/deny15} | 0 maxscale-system-test/{fw2/deny3 => fw/deny16} | 0 maxscale-system-test/{fw2/deny4 => fw/deny17} | 0 maxscale-system-test/{fw2/deny5 => fw/deny18} | 0 maxscale-system-test/{fw2/pass1 => fw/pass14} | 0 maxscale-system-test/{fw2/pass2 => fw/pass15} | 0 maxscale-system-test/{fw2/pass3 => fw/pass16} | 0 maxscale-system-test/{fw2/pass4 => fw/pass17} | 0 maxscale-system-test/{fw2/pass5 => fw/pass18} | 0 .../{fw2/rules1 => fw/rules14} | 0 .../{fw2/rules2 => fw/rules15} | 0 .../{fw2/rules3 => fw/rules16} | 0 .../{fw2/rules4 => fw/rules17} | 0 .../{fw2/rules5 => fw/rules18} | 0 maxscale-system-test/fw_copy_rules.cpp | 29 ++--- maxscale-system-test/fwf.cpp | 51 +++------ maxscale-system-test/fwf2.cpp | 104 ------------------ 19 files changed, 24 insertions(+), 161 deletions(-) rename maxscale-system-test/{fw2/deny1 => fw/deny14} (100%) rename maxscale-system-test/{fw2/deny2 => fw/deny15} (100%) rename maxscale-system-test/{fw2/deny3 => fw/deny16} (100%) rename maxscale-system-test/{fw2/deny4 => fw/deny17} (100%) rename maxscale-system-test/{fw2/deny5 => fw/deny18} (100%) rename maxscale-system-test/{fw2/pass1 => fw/pass14} (100%) rename maxscale-system-test/{fw2/pass2 => fw/pass15} (100%) rename maxscale-system-test/{fw2/pass3 => fw/pass16} (100%) rename maxscale-system-test/{fw2/pass4 => fw/pass17} (100%) rename maxscale-system-test/{fw2/pass5 => fw/pass18} (100%) rename maxscale-system-test/{fw2/rules1 => fw/rules14} (100%) rename maxscale-system-test/{fw2/rules2 => fw/rules15} (100%) rename maxscale-system-test/{fw2/rules3 => fw/rules16} (100%) rename maxscale-system-test/{fw2/rules4 => fw/rules17} (100%) rename maxscale-system-test/{fw2/rules5 => fw/rules18} (100%) delete mode 100644 maxscale-system-test/fwf2.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index d6ba322a3..d2affad7c 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -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) diff --git a/maxscale-system-test/fw2/deny1 b/maxscale-system-test/fw/deny14 similarity index 100% rename from maxscale-system-test/fw2/deny1 rename to maxscale-system-test/fw/deny14 diff --git a/maxscale-system-test/fw2/deny2 b/maxscale-system-test/fw/deny15 similarity index 100% rename from maxscale-system-test/fw2/deny2 rename to maxscale-system-test/fw/deny15 diff --git a/maxscale-system-test/fw2/deny3 b/maxscale-system-test/fw/deny16 similarity index 100% rename from maxscale-system-test/fw2/deny3 rename to maxscale-system-test/fw/deny16 diff --git a/maxscale-system-test/fw2/deny4 b/maxscale-system-test/fw/deny17 similarity index 100% rename from maxscale-system-test/fw2/deny4 rename to maxscale-system-test/fw/deny17 diff --git a/maxscale-system-test/fw2/deny5 b/maxscale-system-test/fw/deny18 similarity index 100% rename from maxscale-system-test/fw2/deny5 rename to maxscale-system-test/fw/deny18 diff --git a/maxscale-system-test/fw2/pass1 b/maxscale-system-test/fw/pass14 similarity index 100% rename from maxscale-system-test/fw2/pass1 rename to maxscale-system-test/fw/pass14 diff --git a/maxscale-system-test/fw2/pass2 b/maxscale-system-test/fw/pass15 similarity index 100% rename from maxscale-system-test/fw2/pass2 rename to maxscale-system-test/fw/pass15 diff --git a/maxscale-system-test/fw2/pass3 b/maxscale-system-test/fw/pass16 similarity index 100% rename from maxscale-system-test/fw2/pass3 rename to maxscale-system-test/fw/pass16 diff --git a/maxscale-system-test/fw2/pass4 b/maxscale-system-test/fw/pass17 similarity index 100% rename from maxscale-system-test/fw2/pass4 rename to maxscale-system-test/fw/pass17 diff --git a/maxscale-system-test/fw2/pass5 b/maxscale-system-test/fw/pass18 similarity index 100% rename from maxscale-system-test/fw2/pass5 rename to maxscale-system-test/fw/pass18 diff --git a/maxscale-system-test/fw2/rules1 b/maxscale-system-test/fw/rules14 similarity index 100% rename from maxscale-system-test/fw2/rules1 rename to maxscale-system-test/fw/rules14 diff --git a/maxscale-system-test/fw2/rules2 b/maxscale-system-test/fw/rules15 similarity index 100% rename from maxscale-system-test/fw2/rules2 rename to maxscale-system-test/fw/rules15 diff --git a/maxscale-system-test/fw2/rules3 b/maxscale-system-test/fw/rules16 similarity index 100% rename from maxscale-system-test/fw2/rules3 rename to maxscale-system-test/fw/rules16 diff --git a/maxscale-system-test/fw2/rules4 b/maxscale-system-test/fw/rules17 similarity index 100% rename from maxscale-system-test/fw2/rules4 rename to maxscale-system-test/fw/rules17 diff --git a/maxscale-system-test/fw2/rules5 b/maxscale-system-test/fw/rules18 similarity index 100% rename from maxscale-system-test/fw2/rules5 rename to maxscale-system-test/fw/rules18 diff --git a/maxscale-system-test/fw_copy_rules.cpp b/maxscale-system-test/fw_copy_rules.cpp index df5ba3141..10f0a4685 100644 --- a/maxscale-system-test/fw_copy_rules.cpp +++ b/maxscale-system-test/fw_copy_rules.cpp @@ -1,30 +1,15 @@ #include "fw_copy_rules.h" -#include +#include 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(); } diff --git a/maxscale-system-test/fwf.cpp b/maxscale-system-test/fwf.cpp index f518dc4bf..f0841bede 100644 --- a/maxscale-system-test/fwf.cpp +++ b/maxscale-system-test/fwf.cpp @@ -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; diff --git a/maxscale-system-test/fwf2.cpp b/maxscale-system-test/fwf2.cpp deleted file mode 100644 index bd282d4a9..000000000 --- a/maxscale-system-test/fwf2.cpp +++ /dev/null @@ -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 -#include -#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; -} - -