mirror of
https://github.com/tnodir/fort
synced 2024-11-14 21:55:37 +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" });
|
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();
|
const QChar *value = parsedCharPtr();
|
||||||
|
|
||||||
const char *extraChars = expectValueEnd ? extraValueEndChars : extraValueChars;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
const char *extraChars = expectValueEnd ? extraValueEndChars : extraValueChars;
|
||||||
|
|
||||||
if (!parseChars(CharLetter | CharValue, extraChars))
|
if (!parseChars(CharLetter | CharValue, extraChars))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (expectValueEnd) {
|
if (!checkValueEnd(expectValueEnd)) {
|
||||||
if (m_charType != CharValueEnd) {
|
if (hasError())
|
||||||
setError(ErrorUnexpectedEndOfValue, tr("Unexpected end of value"));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
advanceCharPtr();
|
|
||||||
|
|
||||||
expectValueEnd = false;
|
|
||||||
extraChars = extraValueChars;
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,6 +345,25 @@ bool RuleTextParser::parseValue(bool expectValueEnd)
|
|||||||
return true;
|
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()
|
bool RuleTextParser::checkAddFilter()
|
||||||
{
|
{
|
||||||
if (!m_ruleFilter.hasValues())
|
if (!m_ruleFilter.hasValues())
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
ErrorCode errorCode() const { return m_errorCode; }
|
ErrorCode errorCode() const { return m_errorCode; }
|
||||||
const QString &errorMessage() const { return m_errorMessage; }
|
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; }
|
const QVector<RuleFilter> &ruleFilters() const { return m_ruleFilters; }
|
||||||
|
|
||||||
@ -107,6 +107,7 @@ private:
|
|||||||
void parseBracketValues();
|
void parseBracketValues();
|
||||||
bool parseBracketValue(RuleCharTypes expectedSeparator);
|
bool parseBracketValue(RuleCharTypes expectedSeparator);
|
||||||
bool parseValue(bool expectValueEnd);
|
bool parseValue(bool expectValueEnd);
|
||||||
|
bool checkValueEnd(bool &expectValueEnd);
|
||||||
|
|
||||||
bool checkAddFilter();
|
bool checkAddFilter();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user