mirror of
https://github.com/tnodir/fort
synced 2024-11-14 22:05:12 +00:00
Tests: tst_ruletextparser: Add tests
This commit is contained in:
parent
6cd542b21f
commit
f999630485
@ -318,3 +318,44 @@ TEST_F(RuleTextParserTest, badBadSymbol)
|
||||
|
||||
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorBadSymbol);
|
||||
}
|
||||
|
||||
TEST_F(RuleTextParserTest, filterNot)
|
||||
{
|
||||
RuleTextParser p("!!!1");
|
||||
|
||||
ASSERT_TRUE(p.parse());
|
||||
|
||||
ASSERT_EQ(p.ruleFilters().size(), 3);
|
||||
|
||||
// Check IP
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[2];
|
||||
ASSERT_TRUE(rf.isNot);
|
||||
ASSERT_EQ(rf.type, FORT_RULE_FILTER_TYPE_ADDRESS);
|
||||
checkStringList(rf.values, { "1" });
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RuleTextParserTest, lineEndNot)
|
||||
{
|
||||
RuleTextParser p("1!2");
|
||||
|
||||
ASSERT_TRUE(p.parse());
|
||||
|
||||
ASSERT_EQ(p.ruleFilters().size(), 4);
|
||||
|
||||
// Check IP
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[2];
|
||||
ASSERT_EQ(rf.type, FORT_RULE_FILTER_TYPE_ADDRESS);
|
||||
checkStringList(rf.values, { "1" });
|
||||
}
|
||||
|
||||
// Check Port
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[3];
|
||||
ASSERT_TRUE(rf.isNot);
|
||||
ASSERT_EQ(rf.type, FORT_RULE_FILTER_TYPE_PORT);
|
||||
checkStringList(rf.values, { "2" });
|
||||
}
|
||||
}
|
||||
|
@ -134,9 +134,17 @@ bool RuleTextParser::parseLine()
|
||||
if (!parseLineSection(expectedSeparator))
|
||||
break;
|
||||
|
||||
const bool isSectionEnd = m_ruleFilter.isSectionEnd;
|
||||
|
||||
if (!processSectionFilter())
|
||||
break;
|
||||
|
||||
// Next default type, if applicable
|
||||
if (!isSectionEnd && !m_ruleFilter.hasFilterName) {
|
||||
m_ruleFilter.type = m_ruleFilter.isTypeAddress() ? FORT_RULE_FILTER_TYPE_PORT
|
||||
: FORT_RULE_FILTER_TYPE_INVALID;
|
||||
}
|
||||
|
||||
expectedSeparator = CharColon | CharNewLine;
|
||||
}
|
||||
|
||||
@ -153,16 +161,8 @@ bool RuleTextParser::processSectionFilter()
|
||||
if (!checkAddFilter())
|
||||
return false;
|
||||
|
||||
const bool isSectionEnd = m_ruleFilter.isSectionEnd;
|
||||
|
||||
resetFilter();
|
||||
|
||||
// Next default type, if applicable
|
||||
if (!isSectionEnd && !m_ruleFilter.hasFilterName) {
|
||||
m_ruleFilter.type = m_ruleFilter.isTypeAddress() ? FORT_RULE_FILTER_TYPE_PORT
|
||||
: FORT_RULE_FILTER_TYPE_INVALID;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user