more filters
parent
2680405c89
commit
298a4c3a11
|
@ -0,0 +1,13 @@
|
||||||
|
# pyruse is intended as a replacement to both fail2ban and epylog
|
||||||
|
# Copyright © 2017–2018 Y. Gablin
|
||||||
|
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
|
||||||
|
from pyruse import base
|
||||||
|
|
||||||
|
class Filter(base.Filter):
|
||||||
|
def __init__(self, args):
|
||||||
|
super().__init__()
|
||||||
|
self.field = args["field"]
|
||||||
|
self.values = args["values"]
|
||||||
|
|
||||||
|
def filter(self, entry):
|
||||||
|
return entry.get(self.field, None) in self.values
|
|
@ -0,0 +1,13 @@
|
||||||
|
# pyruse is intended as a replacement to both fail2ban and epylog
|
||||||
|
# Copyright © 2017–2018 Y. Gablin
|
||||||
|
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
|
||||||
|
from pyruse import base
|
||||||
|
|
||||||
|
class Filter(base.Filter):
|
||||||
|
def __init__(self, args):
|
||||||
|
super().__init__()
|
||||||
|
self.field = args["field"]
|
||||||
|
self.value = args["value"]
|
||||||
|
|
||||||
|
def filter(self, entry):
|
||||||
|
return entry[self.field] <= self.value if self.field in entry else False
|
|
@ -0,0 +1,22 @@
|
||||||
|
# pyruse is intended as a replacement to both fail2ban and epylog
|
||||||
|
# Copyright © 2017–2018 Y. Gablin
|
||||||
|
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
|
||||||
|
from pyruse.filters.filter_in import Filter
|
||||||
|
|
||||||
|
def whenNotInListThenFalse():
|
||||||
|
assert not Filter({"field": "v", "values": [0, "test"]}).filter({"v": 3})
|
||||||
|
|
||||||
|
def whenInListSameTypeThenTrue():
|
||||||
|
assert Filter({"field": "v", "values": [2]}).filter({"v": 2})
|
||||||
|
|
||||||
|
def whenInListDiffTypeThenTrue():
|
||||||
|
assert Filter({"field": "v", "values": [2.0]}).filter({"v": 2})
|
||||||
|
|
||||||
|
def whenNoFieldThenFalse():
|
||||||
|
assert not Filter({"field": "v", "values": [0]}).filter({"other": 0})
|
||||||
|
|
||||||
|
def unitTests():
|
||||||
|
whenNotInListThenFalse()
|
||||||
|
whenInListSameTypeThenTrue()
|
||||||
|
whenInListDiffTypeThenTrue()
|
||||||
|
whenNoFieldThenFalse()
|
|
@ -0,0 +1,26 @@
|
||||||
|
# pyruse is intended as a replacement to both fail2ban and epylog
|
||||||
|
# Copyright © 2017–2018 Y. Gablin
|
||||||
|
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
|
||||||
|
from pyruse.filters.filter_lowerOrEquals import Filter
|
||||||
|
|
||||||
|
def whenLowerNegIntThenTrue():
|
||||||
|
assert Filter({"field": "v", "value": -2}).filter({"v": -3})
|
||||||
|
|
||||||
|
def whenLowerPosFloatThenTrue():
|
||||||
|
assert Filter({"field": "v", "value": 2.1}).filter({"v": 1.9})
|
||||||
|
|
||||||
|
def whenEqualSameTypeThenTrue():
|
||||||
|
assert Filter({"field": "v", "value": 2}).filter({"v": 2})
|
||||||
|
|
||||||
|
def whenEqualDiffTypeThenTrue():
|
||||||
|
assert Filter({"field": "v", "value": 2.0}).filter({"v": 2})
|
||||||
|
|
||||||
|
def whenGreaterThenFalse():
|
||||||
|
assert not Filter({"field": "v", "value": 0}).filter({"v": 2})
|
||||||
|
|
||||||
|
def unitTests():
|
||||||
|
whenLowerNegIntThenTrue()
|
||||||
|
whenLowerPosFloatThenTrue()
|
||||||
|
whenEqualSameTypeThenTrue()
|
||||||
|
whenEqualDiffTypeThenTrue()
|
||||||
|
whenGreaterThenFalse()
|
|
@ -28,11 +28,13 @@ def main():
|
||||||
base.actionFallback = None
|
base.actionFallback = None
|
||||||
|
|
||||||
# Unit tests
|
# Unit tests
|
||||||
import filter_equals, filter_greaterOrEquals, filter_pcre, filter_pcreAny, filter_userExists
|
import filter_equals, filter_greaterOrEquals, filter_in, filter_lowerOrEquals, filter_pcre, filter_pcreAny, filter_userExists
|
||||||
import action_counterRaise, action_counterReset, action_dailyReport, action_email, action_nftBan
|
import action_counterRaise, action_counterReset, action_dailyReport, action_email, action_nftBan
|
||||||
|
|
||||||
filter_equals.unitTests()
|
filter_equals.unitTests()
|
||||||
filter_greaterOrEquals.unitTests()
|
filter_greaterOrEquals.unitTests()
|
||||||
|
filter_in.unitTests()
|
||||||
|
filter_lowerOrEquals.unitTests()
|
||||||
filter_pcre.unitTests()
|
filter_pcre.unitTests()
|
||||||
filter_pcreAny.unitTests()
|
filter_pcreAny.unitTests()
|
||||||
filter_userExists.unitTests()
|
filter_userExists.unitTests()
|
||||||
|
|
Loading…
Reference in New Issue