mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-15 17:12:14 +03:00
Improves rules dump for better testing
This commit is contained in:
@@ -46,15 +46,14 @@ class Rule {
|
||||
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
|
||||
: m_fileName(std::move(fileName)),
|
||||
m_lineNumber(lineNumber),
|
||||
m_phase(modsecurity::Phases::RequestHeadersPhase) {
|
||||
}
|
||||
m_phase(modsecurity::Phases::RequestHeadersPhase)
|
||||
{ }
|
||||
|
||||
Rule(const Rule &r)
|
||||
: m_fileName(r.m_fileName),
|
||||
m_lineNumber(r.m_lineNumber),
|
||||
m_phase(r.m_phase) {
|
||||
|
||||
}
|
||||
m_phase(r.m_phase)
|
||||
{ }
|
||||
|
||||
Rule &operator=(const Rule& other) {
|
||||
m_fileName = other.m_fileName;
|
||||
@@ -80,6 +79,18 @@ class Rule {
|
||||
return *m_fileName + ":" + 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