mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
regression: Allows to specify a single file or directory
Tests were directory driven. Now it is possible to specify a single test case file.
This commit is contained in:
parent
a4af4f32cd
commit
3f8fa64c9a
@ -18,11 +18,13 @@
|
|||||||
#include <yajl/yajl_tree.h>
|
#include <yajl/yajl_tree.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "modsecurity/modsecurity.h"
|
#include "modsecurity/modsecurity.h"
|
||||||
|
|
||||||
@ -92,10 +94,16 @@ 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() {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
|
struct stat buffer;
|
||||||
|
|
||||||
if ((dir = opendir(this->target_folder.c_str())) == NULL) {
|
if ((dir = opendir(this->target.c_str())) == NULL) {
|
||||||
std::cout << "Problems opening directory: " << this->target_folder;
|
/* if target is a file, use it as a single test. */
|
||||||
std::cout << std::endl;
|
if (stat(this->target.c_str(), &buffer) == 0) {
|
||||||
|
if (load_test_json(this->target) == false) {
|
||||||
|
std::cout << "Problems loading from: " << this->target;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,12 +114,11 @@ std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
|
|||||||
|| !std::equal(json.rbegin(), json.rend(), filename.rbegin())) {
|
|| !std::equal(json.rbegin(), json.rend(), filename.rbegin())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (load_test_json(this->target_folder + "/" + filename) == false) {
|
if (load_test_json(this->target + "/" + filename) == false) {
|
||||||
std::cout << "Problems loading tests from: " << filename;
|
std::cout << "Problems loading tests from: " << filename;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -143,9 +150,9 @@ void ModSecurityTest<T>::cmd_options(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (argv[1]) {
|
if (argv[1]) {
|
||||||
this->target_folder = argv[1];
|
this->target = argv[1];
|
||||||
} else {
|
} else {
|
||||||
this->target_folder = default_test_path;
|
this->target = default_test_path;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ template <class T> class ModSecurityTest :
|
|||||||
std::pair<std::string, std::vector<T *>>* load_tests();
|
std::pair<std::string, std::vector<T *>>* load_tests();
|
||||||
bool load_test_json(std::string);
|
bool load_test_json(std::string);
|
||||||
|
|
||||||
std::string target_folder;
|
std::string target;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
bool color = false;
|
bool color = false;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user