mirror of
https://github.com/tnodir/fort
synced 2024-11-14 22:05:12 +00:00
Tests: tst_ruletextparser.h: Add "lineIp6Range" test
This commit is contained in:
parent
1646c99fe4
commit
f75ece4e61
@ -187,3 +187,26 @@ TEST_F(RuleTextParserTest, lineSectionList)
|
||||
checkStringList(rf.values, { "80" });
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RuleTextParserTest, lineIp6Range)
|
||||
{
|
||||
RuleTextParser p("[2:]/3-[4:]/5:67");
|
||||
|
||||
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, { "[2:]/3-[4:]/5" });
|
||||
}
|
||||
|
||||
// Check Port
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[3];
|
||||
ASSERT_EQ(rf.type, FORT_RULE_FILTER_TYPE_PORT);
|
||||
checkStringList(rf.values, { "67" });
|
||||
}
|
||||
}
|
||||
|
@ -324,23 +324,16 @@ bool RuleTextParser::parseValue(bool expectValueEnd)
|
||||
{
|
||||
const QChar *value = parsedCharPtr();
|
||||
|
||||
for (;;) {
|
||||
const char *extraChars = expectValueEnd ? extraValueEndChars : extraValueChars;
|
||||
|
||||
for (;;) {
|
||||
if (!parseChars(CharLetter | CharValue, extraChars))
|
||||
return false;
|
||||
|
||||
if (expectValueEnd) {
|
||||
if (m_charType != CharValueEnd) {
|
||||
setError(ErrorUnexpectedEndOfValue, tr("Unexpected end of value"));
|
||||
if (!checkValueEnd(expectValueEnd)) {
|
||||
if (hasError())
|
||||
return false;
|
||||
}
|
||||
|
||||
advanceCharPtr();
|
||||
|
||||
expectValueEnd = false;
|
||||
extraChars = extraValueChars;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -352,6 +345,25 @@ bool RuleTextParser::parseValue(bool expectValueEnd)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuleTextParser::checkValueEnd(bool &expectValueEnd)
|
||||
{
|
||||
const bool isValueBegin = (m_charType == CharValueBegin);
|
||||
|
||||
if (isValueBegin || expectValueEnd) {
|
||||
if (isValueBegin ? expectValueEnd : (m_charType != CharValueEnd)) {
|
||||
setError(ErrorUnexpectedEndOfValue, tr("Unexpected end of value"));
|
||||
return false;
|
||||
}
|
||||
|
||||
advanceCharPtr();
|
||||
|
||||
expectValueEnd = isValueBegin;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RuleTextParser::checkAddFilter()
|
||||
{
|
||||
if (!m_ruleFilter.hasValues())
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
ErrorCode errorCode() const { return m_errorCode; }
|
||||
const QString &errorMessage() const { return m_errorMessage; }
|
||||
|
||||
bool hasError() const { return !errorMessage().isEmpty(); }
|
||||
bool hasError() const { return errorCode() != ErrorNone; }
|
||||
|
||||
const QVector<RuleFilter> &ruleFilters() const { return m_ruleFilters; }
|
||||
|
||||
@ -107,6 +107,7 @@ private:
|
||||
void parseBracketValues();
|
||||
bool parseBracketValue(RuleCharTypes expectedSeparator);
|
||||
bool parseValue(bool expectValueEnd);
|
||||
bool checkValueEnd(bool &expectValueEnd);
|
||||
|
||||
bool checkAddFilter();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user