Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a5a3db9
Do not add newline to test body Lines
hnakamur Jan 25, 2026
d7cad95
Add needed newlines in test request body lines or adjust tests
hnakamur Jan 25, 2026
e03f8a1
Replace CRLF to LF in test case JSON files
hnakamur Jan 25, 2026
b1c59b7
Add format subcommand to regression_test
hnakamur Jan 25, 2026
488370c
Modify RegressionTest and use it for output formatted JSON
hnakamur Jan 25, 2026
37e1f13
Update content-length in regeression_tests format subcommand
hnakamur Jan 25, 2026
191dba9
Format regression test JSON files
hnakamur Jan 25, 2026
9b49187
Update Content-Length in regression test JSON files
hnakamur Jan 25, 2026
aefd4a4
Adjust tests to pass after adding Content-Length
hnakamur Jan 26, 2026
2ef033b
Make RegressionTests::toJSON method const
hnakamur Jan 28, 2026
03c3e75
Do not shadow outer variable
hnakamur Jan 28, 2026
d8fd7d6
Use in-class initializer in ModSecurityTest
hnakamur Jan 28, 2026
48fbc1b
Use a structured binding in regression_test.cc
hnakamur Jan 28, 2026
1492841
Use emplace_back in regression_test.cc
hnakamur Jan 28, 2026
8d5a80d
Use std::optional has_value to clarify the code
hnakamur Jan 28, 2026
57689a0
Use unique_ptr in from_yajl_node in test/common/
hnakamur Jan 28, 2026
2a84d52
Use default implementation for ModSecurityTest constructor
hnakamur Jan 28, 2026
c0fdf7b
Use std::any_of in has_chunked_header
hnakamur Jan 28, 2026
22c7d78
Do not shadow variable
hnakamur Jan 28, 2026
cf46967
Reduce complexity in RegressionTest::from_yajl_node
hnakamur Jan 28, 2026
550b0be
Reduce complexity more in RegressionTest::from_yajl_node
hnakamur Jan 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions test/common/modsecurity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ bool ModSecurityTest<T>::load_test_json(const std::string &file) {
return false;
}

size_t num_tests = node->u.array.len;
for ( int i = 0; i < num_tests; i++ ) {
yajl_val obj = node->u.array.values[i];

auto u = std::unique_ptr<T>(T::from_yajl_node(obj));
if (m_format) {
auto u = T::from_yajl_node(node);
u->filename = file;

const auto key = u->filename + ":" + u->name;
(*this)[key].push_back(std::move(u));
(*this)[file].push_back(std::move(u));
} else {
size_t num_tests = node->u.array.len;
for ( int i = 0; i < num_tests; i++ ) {
yajl_val obj = node->u.array.values[i];

auto u = T::from_yajl_node(obj);
u->filename = file;

const auto key = u->filename + ":" + u->name;
(*this)[key].push_back(std::move(u));
}
}

yajl_tree_free(node);
Expand Down Expand Up @@ -140,6 +147,13 @@ void ModSecurityTest<T>::cmd_options(int argc, char **argv) {
i++;
m_test_multithreaded = true;
}
if (argc > i && strcmp(argv[i], "format") == 0) {
i++;
m_format = true;
}
if (std::getenv("UPDATE_CONTENT_LENGTH")) {
m_update_content_length = true;
}
if (std::getenv("AUTOMAKE_TESTS")) {
m_automake_output = true;
}
Expand Down
20 changes: 9 additions & 11 deletions test/common/modsecurity_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ namespace modsecurity_test {
template <class T> class ModSecurityTest :
public std::unordered_map<std::string, std::vector<std::unique_ptr<T>>> {
public:
ModSecurityTest()
: m_test_number(0),
m_automake_output(false),
m_count_all(false),
m_test_multithreaded(false) { }
ModSecurityTest() = default;

std::string header();
void cmd_options(int, char **);
Expand All @@ -44,12 +40,14 @@ template <class T> class ModSecurityTest :
bool load_test_json(const std::string &file);

std::string target;
bool verbose = false;
bool color = false;
int m_test_number;
bool m_automake_output;
bool m_count_all;
bool m_test_multithreaded;
bool verbose{false};
bool color{false};
int m_test_number{0};
bool m_automake_output{false};
bool m_count_all{false};
bool m_test_multithreaded{false};
bool m_format{false};
bool m_update_content_length{false};
};

} // namespace modsecurity_test
Expand Down
30 changes: 30 additions & 0 deletions test/regression/regression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ using modsecurity_test::CustomDebugLog;
using modsecurity_test::ModSecurityTest;
using modsecurity_test::ModSecurityTestResults;
using modsecurity_test::RegressionTest;
using modsecurity_test::RegressionTests;
using modsecurity_test::RegressionTestResult;

using modsecurity::Utils::regex_search;
Expand Down Expand Up @@ -436,6 +437,35 @@ int main(int argc, char **argv)
return 0;
#else
test.cmd_options(argc, argv);

if (test.m_format) {
#ifdef WITH_YAJL
std::cout << "start formatting test case JSON files" << std::endl;
ModSecurityTest<RegressionTests> test2;
test2.cmd_options(argc, argv);
test2.load_tests();
for (const auto &[name, tests] : test2) {
std::ofstream ofs{name};
if (!ofs.is_open()) {
std::cerr << "cannot open " << name << " for writing." << std::endl;
return 1;
}
if (test2.m_update_content_length) {
tests[0]->update_content_lengths();
}
ofs << tests[0]->toJSON();
ofs.close();
std::cout << "written formatted JSON to " << name << std::endl;
}
std::cout << "finished formatting files." << std::endl;
return 0;
#else
std::cout << "Test utility cannot format test case JSON files without being built with YAJL." \
<< std::endl;
return 1;
#endif
}

if (!test.m_automake_output && !test.m_count_all) {
std::cout << test.header();
}
Expand Down
Loading
Loading