Adds support to error_log in the regression tests

This commit is contained in:
Felipe Zimmerle 2017-02-07 15:49:04 -03:00 committed by Felipe Zimmerle
parent ae8c2a4865
commit 795994bb0e
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
2 changed files with 24 additions and 2 deletions

View File

@ -50,6 +50,13 @@ void print_help() {
std::cout << std::endl; std::cout << std::endl;
} }
bool contains(const std::string &s, const std::string &pattern) {
bool ret;
modsecurity::Utils::Regex re(pattern);
ret = modsecurity::Utils::regex_search(s, re);
return ret;
}
void actions(ModSecurityTestResults<RegressionTest> *r, void actions(ModSecurityTestResults<RegressionTest> *r,
modsecurity::Transaction *a) { modsecurity::Transaction *a) {
@ -336,7 +343,7 @@ end:
testRes->reason << "Debug log was not matching the " \ testRes->reason << "Debug log was not matching the " \
<< "expected results." << std::endl; << "expected results." << std::endl;
testRes->reason << KWHT << "Expecting: " << RESET \ testRes->reason << KWHT << "Expecting: " << RESET \
<< t->debug_log + "."; << t->debug_log + "";
testRes->passed = false; testRes->passed = false;
} else if (r.status != t->http_code) { } else if (r.status != t->http_code) {
if (test->m_automake_output) { if (test->m_automake_output) {
@ -349,6 +356,18 @@ end:
std::to_string(t->http_code) + \ std::to_string(t->http_code) + \
" got: " + std::to_string(r.status) + "\n"; " got: " + std::to_string(r.status) + "\n";
testRes->passed = false; testRes->passed = false;
} else if (!contains(serverLog.str(), t->error_log)) {
if (test->m_automake_output) {
std::cout << ":test-result: FAIL " << filename \
<< ":" << t->name << std::endl;
} else {
std::cout << KRED << "failed!" << RESET << std::endl;
}
testRes->reason << "Error log was not matching the " \
<< "expected results." << std::endl;
testRes->reason << KWHT << "Expecting: " << RESET \
<< t->error_log + "";
testRes->passed = false;
} else { } else {
if (test->m_automake_output) { if (test->m_automake_output) {
std::cout << ":test-result: PASS " << filename \ std::cout << ":test-result: PASS " << filename \
@ -364,9 +383,12 @@ end:
testRes->reason << std::endl; testRes->reason << std::endl;
testRes->reason << KWHT << "Debug log:" << RESET << std::endl; testRes->reason << KWHT << "Debug log:" << RESET << std::endl;
testRes->reason << d->log_messages() << std::endl; testRes->reason << d->log_messages() << std::endl;
testRes->reason << KWHT << "Error log:" << RESET << std::endl;
testRes->reason << serverLog.str() << std::endl;
} }
} }
after_debug_log: after_debug_log:
if (d != NULL) { if (d != NULL) {
r.log_raw_debug_log = d->log_messages(); r.log_raw_debug_log = d->log_messages();

View File

@ -186,7 +186,7 @@ RegressionTest *RegressionTest::from_yajl_node(const yajl_val &node) {
u->debug_log = YAJL_GET_STRING(val2); u->debug_log = YAJL_GET_STRING(val2);
} }
if (strcmp(key2, "error_log") == 0) { if (strcmp(key2, "error_log") == 0) {
u->error_log = yajl_array_to_str(val2); u->error_log = YAJL_GET_STRING(val2);
} }
if (strcmp(key2, "http_code") == 0) { if (strcmp(key2, "http_code") == 0) {
u->http_code = YAJL_GET_INTEGER(val2); u->http_code = YAJL_GET_INTEGER(val2);