mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +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 <dirent.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "modsecurity/modsecurity.h"
|
||||
|
||||
@ -92,10 +94,16 @@ template <class T>
|
||||
std::pair<std::string, std::vector<T *>>* ModSecurityTest<T>::load_tests() {
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
struct stat buffer;
|
||||
|
||||
if ((dir = opendir(this->target_folder.c_str())) == NULL) {
|
||||
std::cout << "Problems opening directory: " << this->target_folder;
|
||||
std::cout << std::endl;
|
||||
if ((dir = opendir(this->target.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;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
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())) {
|
||||
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 << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
return NULL;
|
||||
@ -143,9 +150,9 @@ void ModSecurityTest<T>::cmd_options(int argc, char **argv) {
|
||||
}
|
||||
#else
|
||||
if (argv[1]) {
|
||||
this->target_folder = argv[1];
|
||||
this->target = argv[1];
|
||||
} else {
|
||||
this->target_folder = default_test_path;
|
||||
this->target = default_test_path;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ template <class T> class ModSecurityTest :
|
||||
std::pair<std::string, std::vector<T *>>* load_tests();
|
||||
bool load_test_json(std::string);
|
||||
|
||||
std::string target_folder;
|
||||
std::string target;
|
||||
bool verbose = false;
|
||||
bool color = false;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user