mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Refactoring on the transformation classes
This commit is contained in:
@@ -14,15 +14,55 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
|
||||
#include "modsecurity/modsecurity.h"
|
||||
#include "modsecurity/rules.h"
|
||||
#include "src/operators/operator.h"
|
||||
#include "src/actions/transformations/transformation.h"
|
||||
#include "modsecurity/transaction.h"
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/actions/transformations/base64_decode_ext.h"
|
||||
#include "src/actions/transformations/base64_decode.h"
|
||||
#include "src/actions/transformations/base64_encode.h"
|
||||
#include "src/actions/transformations/cmd_line.h"
|
||||
#include "src/actions/transformations/compress_whitespace.h"
|
||||
#include "src/actions/transformations/css_decode.h"
|
||||
#include "src/actions/transformations/escape_seq_decode.h"
|
||||
#include "src/actions/transformations/hex_decode.h"
|
||||
#include "src/actions/transformations/hex_encode.h"
|
||||
#include "src/actions/transformations/html_entity_decode.h"
|
||||
#include "src/actions/transformations/js_decode.h"
|
||||
#include "src/actions/transformations/length.h"
|
||||
#include "src/actions/transformations/lower_case.h"
|
||||
#include "src/actions/transformations/md5.h"
|
||||
#include "src/actions/transformations/none.h"
|
||||
#include "src/actions/transformations/normalise_path.h"
|
||||
#include "src/actions/transformations/normalise_path_win.h"
|
||||
#include "src/actions/transformations/parity_even_7bit.h"
|
||||
#include "src/actions/transformations/parity_odd_7bit.h"
|
||||
#include "src/actions/transformations/parity_zero_7bit.h"
|
||||
#include "src/actions/transformations/remove_comments_char.h"
|
||||
#include "src/actions/transformations/remove_comments.h"
|
||||
#include "src/actions/transformations/remove_nulls.h"
|
||||
#include "src/actions/transformations/remove_whitespace.h"
|
||||
#include "src/actions/transformations/replace_comments.h"
|
||||
#include "src/actions/transformations/replace_nulls.h"
|
||||
#include "src/actions/transformations/sha1.h"
|
||||
#include "src/actions/transformations/sql_hex_decode.h"
|
||||
#include "src/actions/transformations/trim.h"
|
||||
#include "src/actions/transformations/trim_left.h"
|
||||
#include "src/actions/transformations/trim_right.h"
|
||||
#include "src/actions/transformations/url_decode.h"
|
||||
#include "src/actions/transformations/url_decode_uni.h"
|
||||
#include "src/actions/transformations/url_encode.h"
|
||||
#include "src/actions/transformations/utf8_to_unicode.h"
|
||||
|
||||
|
||||
#include "test/common/modsecurity_test.h"
|
||||
#include "test/common/modsecurity_test_results.h"
|
||||
@@ -30,12 +70,16 @@
|
||||
#include "test/unit/unit_test.h"
|
||||
#include "src/utils/string.h"
|
||||
|
||||
#define IF_MATCH(b) \
|
||||
if (a.compare(2, std::strlen(#b), #b) == 0)
|
||||
|
||||
|
||||
using modsecurity_test::UnitTest;
|
||||
using modsecurity_test::ModSecurityTest;
|
||||
using modsecurity_test::ModSecurityTestResults;
|
||||
using modsecurity::actions::transformations::Transformation;
|
||||
using modsecurity::operators::Operator;
|
||||
using namespace modsecurity::actions::transformations;
|
||||
|
||||
std::string default_test_path = "test-cases/secrules-language-tests/operators";
|
||||
|
||||
@@ -46,6 +90,51 @@ void print_help() {
|
||||
}
|
||||
|
||||
|
||||
Transformation* t_instantiate(std::string a) {
|
||||
IF_MATCH(base64DecodeExt) { return new Base64DecodeExt(a); }
|
||||
IF_MATCH(base64Decode) { return new Base64Decode(a); }
|
||||
IF_MATCH(base64Encode) { return new Base64Encode(a); }
|
||||
IF_MATCH(cmd_line) { return new CmdLine(a); }
|
||||
IF_MATCH(compress_whitespace) { return new CompressWhitespace(a); }
|
||||
IF_MATCH(cssDecode) { return new CssDecode(a); }
|
||||
IF_MATCH(escapeSeqDecode) { return new EscapeSeqDecode(a); }
|
||||
IF_MATCH(hexDecode) { return new HexDecode(a); }
|
||||
IF_MATCH(hexEncode) { return new HexEncode(a); }
|
||||
IF_MATCH(htmlEntityDecode) { return new HtmlEntityDecode(a); }
|
||||
IF_MATCH(jsDecode) { return new JsDecode(a); }
|
||||
IF_MATCH(length) { return new Length(a); }
|
||||
IF_MATCH(lowercase) { return new LowerCase(a); }
|
||||
IF_MATCH(md5) { return new Md5(a); }
|
||||
IF_MATCH(none) { return new None(a); }
|
||||
IF_MATCH(normalizePathWin) { return new NormalisePathWin(a); }
|
||||
IF_MATCH(normalisePathWin) { return new NormalisePathWin(a); }
|
||||
IF_MATCH(normalizePath) { return new NormalisePath(a); }
|
||||
IF_MATCH(normalisePath) { return new NormalisePath(a); }
|
||||
IF_MATCH(parityEven7bit) { return new ParityEven7bit(a); }
|
||||
IF_MATCH(parityOdd7bit) { return new ParityOdd7bit(a); }
|
||||
IF_MATCH(parityZero7bit) { return new ParityZero7bit(a); }
|
||||
IF_MATCH(removeCommentsChar) { return new RemoveCommentsChar(a); }
|
||||
IF_MATCH(removeComments) { return new RemoveComments(a); }
|
||||
IF_MATCH(removeNulls) { return new RemoveNulls(a); }
|
||||
IF_MATCH(removeWhitespace) { return new RemoveWhitespace(a); }
|
||||
IF_MATCH(compressWhitespace) { return new CompressWhitespace(a); }
|
||||
IF_MATCH(replaceComments) { return new ReplaceComments(a); }
|
||||
IF_MATCH(replaceNulls) { return new ReplaceNulls(a); }
|
||||
IF_MATCH(sha1) { return new Sha1(a); }
|
||||
IF_MATCH(sqlHexDecode) { return new SqlHexDecode(a); }
|
||||
IF_MATCH(transformation) { return new Transformation(a); }
|
||||
IF_MATCH(trimLeft) { return new TrimLeft(a); }
|
||||
IF_MATCH(trimRight) { return new TrimRight(a); }
|
||||
IF_MATCH(trim) { return new Trim(a); }
|
||||
IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); }
|
||||
IF_MATCH(urlDecode) { return new UrlDecode(a); }
|
||||
IF_MATCH(urlEncode) { return new UrlEncode(a); }
|
||||
IF_MATCH(utf8ToUnicode) { return new Utf8ToUnicode(a); }
|
||||
|
||||
return new Transformation(a);
|
||||
}
|
||||
|
||||
|
||||
void perform_unit_test(ModSecurityTest<UnitTest> *test, UnitTest *t,
|
||||
ModSecurityTestResults<UnitTest>* res) {
|
||||
std::string error;
|
||||
@@ -70,7 +159,7 @@ void perform_unit_test(ModSecurityTest<UnitTest> *test, UnitTest *t,
|
||||
}
|
||||
delete op;
|
||||
} else if (t->type == "tfn") {
|
||||
Transformation *tfn = Transformation::instantiate("t:" + t->name);
|
||||
Transformation *tfn = t_instantiate("t:" + t->name);
|
||||
std::string ret = tfn->evaluate(t->input, NULL);
|
||||
t->obtained = 1;
|
||||
t->obtainedOutput = ret;
|
||||
|
Reference in New Issue
Block a user