Skip to content

Commit

Permalink
Refactoring: Rule class
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmerle committed Nov 28, 2016
1 parent a776cce commit 9bd37cc
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 26 deletions.
18 changes: 2 additions & 16 deletions headers/modsecurity/rule_message.h
Expand Up @@ -49,22 +49,6 @@ class RuleMessage {
m_match(std::string(""))
{ }

RuleMessage(Rule *rule, std::string message) :
m_ruleFile(rule->m_fileName),
m_ruleLine(rule->m_lineNumber),
m_ruleId(rule->rule_id),
m_rev(rule->m_rev),
m_accuracy(rule->m_accuracy),
m_message(message),
m_data(std::string("")),
m_severity(0),
m_ver(rule->m_ver),
m_maturity(rule->m_maturity),
m_rule(rule),
m_saveMessage(false),
m_match(std::string(""))
{ }

std::string errorLog(Transaction *trans);


Expand All @@ -81,6 +65,8 @@ class RuleMessage {
int m_accuracy;

std::list<std::string> m_tags;
std::vector<actions::Action *> m_tmp_actions;
std::list<std::string> m_server_logs;

Rule *m_rule;
bool m_saveMessage;
Expand Down
1 change: 1 addition & 0 deletions src/actions/log_data.cc
Expand Up @@ -32,6 +32,7 @@ namespace actions {
bool LogData::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
rm->m_data = data(transaction);

transaction->m_collections.storeOrUpdateFirst("RULE:logdata", rm->m_data);
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions src/rule.cc
Expand Up @@ -586,8 +586,9 @@ bool Rule::evaluate(Transaction *trasn) {
&containsDisruptive, &ruleMessage);
std::string msg2save = ruleMessage.errorLog(trasn);
if (ruleMessage.m_message.empty() == false) {
trasn->debug(4, "Scheduled to be saved on the server " +
"log: " + msg2save + "");
trasn->debug(4,
"Scheduled to be saved on the server log: " \
+ msg2save + "");
ruleMessage.m_server_logs.push_back(msg2save);
}
globalRet = true;
Expand Down
2 changes: 1 addition & 1 deletion test/test-cases/regression/action-disruptive.json
Expand Up @@ -5,7 +5,7 @@
"title":"Testing Disruptive actions (1/n)",
"expected":{
"debug_log": " Running action: deny",
"http_code":404
"http_code":403
},
"rules":[
"SecRuleEngine On",
Expand Down
2 changes: 1 addition & 1 deletion test/test-cases/regression/secaction.json
Expand Up @@ -49,7 +49,7 @@
},
"expected": {
"audit_log": "",
"debug_log": "Running unconditional rule.",
"debug_log": "Executing unconditional rule",
"error_log": ""
},
"rules": [
Expand Down
4 changes: 2 additions & 2 deletions test/test-cases/regression/secruleengine.json
Expand Up @@ -5,7 +5,7 @@
"title":"Testing Disruptive actions (1/n)",
"expected":{
"debug_log": " Running action: deny",
"http_code":404
"http_code":403
},
"rules":[
"SecRuleEngine On",
Expand Down Expand Up @@ -34,7 +34,7 @@
"version_min":300000,
"title":"Testing Disruptive actions (3/n)",
"expected":{
"debug_log": "Not running disruptive action: block. SecRuleEngine is not On",
"debug_log": "_Not_ running action: deny. Rule _does not_contains a disruptive action, but SecRuleEngine is not On.",
"http_code":200
},
"rules":[
Expand Down
2 changes: 1 addition & 1 deletion test/test-cases/regression/variable-FILES.json
Expand Up @@ -51,7 +51,7 @@
]
},
"expected":{
"debug_log":"T \\(1\\) t:trim: \"small_text_file"
"debug_log":"T \\(0\\) t:trim: \"small_text_file"
},
"rules":[
"SecRuleEngine On",
Expand Down
2 changes: 1 addition & 1 deletion test/test-cases/regression/variable-FILES_NAMES.json
Expand Up @@ -51,7 +51,7 @@
]
},
"expected":{
"debug_log":"T \\(1\\) t:trim: \"filedata"
"debug_log":"T \\(0\\) t:trim: \"filedata"
},
"rules":[
"SecRuleEngine On",
Expand Down
4 changes: 2 additions & 2 deletions test/test-cases/regression/variable-RULE.json
Expand Up @@ -256,7 +256,7 @@
]
},
"expected":{
"debug_log":" Target value: \"message123\" \\(Variable: RULE:msg\\)"
"debug_log":" Target value: \"message123\" \\(Variable: rule:msg\\)"
},
"rules":[
"SecRuleEngine On",
Expand Down Expand Up @@ -304,7 +304,7 @@
},
"rules":[
"SecRuleEngine On",
"SecRule rule:msg \"@contains message\" \"id:1,setvar:'ip.block_reason=%{RULE.msg}%',msg:'message123',phase:3,pass,t:trim\""
"SecRule rule:msg \"@contains message\" \"id:1,msg:'message123',setvar:'ip.block_reason=%{RULE.msg}%',phase:3,pass,t:trim\""
]
}
]
Expand Down

0 comments on commit 9bd37cc

Please sign in to comment.