mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Loads the transformations test cases during the unit test
Related to: #1156
This commit is contained in:
parent
8d49903279
commit
f35d28b8d3
@ -94,16 +94,17 @@ bool ModSecurityTest<T>::load_test_json(std::string file) {
|
||||
|
||||
|
||||
template <class T>
|
||||
std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
|
||||
std::pair<std::string, std::vector<T *>>*
|
||||
ModSecurityTest<T>::load_tests(std::string path) {
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
struct stat buffer;
|
||||
|
||||
if ((dir = opendir(this->target.c_str())) == NULL) {
|
||||
if ((dir = opendir(path.c_str())) == NULL) {
|
||||
/* if target is a file, use it as a single test. */
|
||||
if (stat(this->target.c_str(), &buffer) == 0) {
|
||||
if (load_test_json(this->target) == false) {
|
||||
std::cout << "Problems loading from: " << this->target;
|
||||
if (stat(path.c_str(), &buffer) == 0) {
|
||||
if (load_test_json(path) == false) {
|
||||
std::cout << "Problems loading from: " << path;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
@ -117,7 +118,7 @@ std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
|
||||
|| !std::equal(json.rbegin(), json.rend(), filename.rbegin())) {
|
||||
continue;
|
||||
}
|
||||
if (load_test_json(this->target + "/" + filename) == false) {
|
||||
if (load_test_json(path + "/" + filename) == false) {
|
||||
std::cout << "Problems loading tests from: " << filename;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@ -127,6 +128,12 @@ std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
|
||||
return load_tests(this->target);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ModSecurityTest<T>::cmd_options(int argc, char **argv) {
|
||||
#if HAS_GETOPT
|
||||
|
@ -34,6 +34,7 @@ template <class T> class ModSecurityTest :
|
||||
std::string header();
|
||||
void cmd_options(int, char **);
|
||||
std::pair<std::string, std::vector<T *>>* load_tests();
|
||||
std::pair<std::string, std::vector<T *>>* load_tests(std::string path);
|
||||
bool load_test_json(std::string);
|
||||
|
||||
std::string target;
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 002eb1e668b7a017eecfdfe9c5415fb9921c0be4
|
||||
Subproject commit c3e867bf45248c1f8a31ab4d9c32b9d0c7102ff2
|
@ -85,6 +85,9 @@ int main(int argc, char **argv) {
|
||||
std::cout << test.header();
|
||||
|
||||
test.load_tests();
|
||||
if (test.target == default_test_path) {
|
||||
test.load_tests("test-cases/secrules-language-tests/transformations");
|
||||
}
|
||||
|
||||
for (std::pair<std::string, std::vector<UnitTest *> *> a : test) {
|
||||
std::vector<UnitTest *> *tests = a.second;
|
||||
|
Loading…
x
Reference in New Issue
Block a user