mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
/**
|
|
* ModSecurity, http://www.modsecurity.org/
|
|
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
|
*
|
|
* You may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* If any of the files related to licensing are missing or if you have any
|
|
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
|
* directly using the email address security@modsecurity.org.
|
|
*
|
|
*/
|
|
|
|
#include "unit/unit_test.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include "common/colors.h"
|
|
|
|
namespace modsecurity_test {
|
|
|
|
std::string UnitTest::print() {
|
|
std::stringstream i;
|
|
|
|
i << KRED << "Test failed." << RESET;
|
|
i << " From: " << this->filename << std::endl;
|
|
i << "{" << std::endl;
|
|
i << " \"ret\": \"" << this->ret << "\"" << std::endl;
|
|
i << " \"type\": \"" << this->type << "\"" << std::endl;
|
|
i << " \"name\": \"" << this->name << "\"" << std::endl;
|
|
i << " \"input\": \"" << this->input << "\"" << std::endl;
|
|
i << " \"param\": \"" << this->param << "\"" << std::endl;
|
|
i << "}" << std::endl;
|
|
i << "Expecting: " << this->ret << " - operator returned: ";
|
|
i << this->obtained << std::endl;
|
|
|
|
return i.str();
|
|
}
|
|
|
|
|
|
UnitTest *UnitTest::from_yajl_node(yajl_val &node) {
|
|
size_t num_tests = node->u.object.len;
|
|
UnitTest *u = new UnitTest();
|
|
|
|
for (int i = 0; i < num_tests; i++) {
|
|
const char *key = node->u.object.keys[ i ];
|
|
yajl_val val = node->u.object.values[ i ];
|
|
|
|
|
|
if (strcmp(key, "param") == 0) {
|
|
u->param = YAJL_GET_STRING(val);
|
|
} else if (strcmp(key, "input") == 0) {
|
|
u->input = YAJL_GET_STRING(val);
|
|
} else if (strcmp(key, "name") == 0) {
|
|
u->name = YAJL_GET_STRING(val);
|
|
} else if (strcmp(key, "type") == 0) {
|
|
u->type = YAJL_GET_STRING(val);
|
|
} else if (strcmp(key, "ret") == 0) {
|
|
u->ret = YAJL_GET_INTEGER(val);
|
|
}
|
|
}
|
|
|
|
return u;
|
|
}
|
|
|
|
} // namespace modsecurity_test
|