mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-16 09:31:53 +03:00
Improves rules dump for better testing
This commit is contained in:
@@ -46,8 +46,8 @@ class Rule {
|
||||
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
|
||||
: m_fileName(std::make_shared<std::string>(*fileName)),
|
||||
m_lineNumber(lineNumber),
|
||||
m_phase(modsecurity::Phases::RequestHeadersPhase) {
|
||||
}
|
||||
m_phase(modsecurity::Phases::RequestHeadersPhase)
|
||||
{ }
|
||||
|
||||
Rule(const Rule &other) :
|
||||
m_fileName(other.m_fileName),
|
||||
@@ -82,6 +82,18 @@ class Rule {
|
||||
return "<<no file>>:" + std::to_string(m_lineNumber);
|
||||
}
|
||||
|
||||
virtual void dump(std::stringstream &out) {
|
||||
out << getOriginInTextFormat() << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string getOriginInTextFormat() const {
|
||||
std::stringstream ss;
|
||||
ss << "# File name: " << *getFileName() << std::endl;
|
||||
ss << "# Line number: " << getLineNumber();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::string> m_fileName;
|
||||
int m_lineNumber;
|
||||
|
||||
@@ -61,7 +61,12 @@ class Rules {
|
||||
std::vector<std::shared_ptr<actions::Action> > m_defaultActions;
|
||||
std::vector<std::shared_ptr<actions::transformations::Transformation> > m_defaultTransformations;
|
||||
|
||||
void dump();
|
||||
virtual void dump() {
|
||||
std::stringstream ss;
|
||||
dump(ss);
|
||||
std::cout << ss.str();
|
||||
};
|
||||
virtual void dump(std::stringstream &out);
|
||||
|
||||
inline iterator begin() noexcept { return m_rules.begin(); }
|
||||
inline const_iterator cbegin() const noexcept { return m_rules.cbegin(); }
|
||||
|
||||
Reference in New Issue
Block a user