Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
941e483
Update test/test-cases/regression/fn-setHostname.json
hnakamur Feb 7, 2026
c795b09
Set uri and method in regression/secruleengine.json
hnakamur Feb 7, 2026
f72106d
Make test clearer in regression/request-body-parser-multipart-crlf.json
hnakamur Feb 7, 2026
b8d37a0
Change superclass of ModSecurityTest to map for consistent order of o…
hnakamur Feb 7, 2026
edbd4b8
Change type of RegressionTests::tests to use unique_ptr
hnakamur Feb 7, 2026
af09a15
Add const for loop variable in regression_test.cc
hnakamur Feb 7, 2026
af3c0d0
Revert "Add const for loop variable in regression_test.cc"
hnakamur Feb 7, 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
24 changes: 11 additions & 13 deletions test/common/modsecurity_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <utility>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>

#ifndef TEST_COMMON_MODSECURITY_TEST_H_
#define TEST_COMMON_MODSECURITY_TEST_H_
Expand All @@ -29,13 +29,9 @@ extern std::string default_test_path;
namespace modsecurity_test {

template <class T> class ModSecurityTest :
public std::unordered_map<std::string, std::vector<std::unique_ptr<T>>> {
public std::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
1 change: 0 additions & 1 deletion test/common/modsecurity_test_results.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>

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};
Comment on lines +447 to +448
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the unordered_map key (name) as the output path makes formatting behavior depend on how keys are constructed in load_test_json. Since you already set u->filename = file during load, it would be more robust to open tests[0]->filename (or the original file value) for writing, rather than relying on the map key.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to use std::map instead of std::unordered_map for consistent order of output at b8d37a0

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