Skip to content

Commit

Permalink
Applications filter: ignore app name case
Browse files Browse the repository at this point in the history
This lets messages with inconsistently cased app names match the
appropriate filters.

Fixes: #854

Signed-off-by: Nils Philippsen <nils@redhat.com>
  • Loading branch information
nphilipp committed Apr 14, 2023
1 parent 4d4a6ba commit a2e9ca2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion fmn/rules/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ def matches(self, message: message.Message):
class Applications(Filter):
name = "applications"

def __init__(self, requester: Requester, params, username):
if params:
params = [app_name.lower() for app_name in params]
super().__init__(requester=requester, params=params, username=username)

def matches(self, message):
if not self.params:
return True
return message.app_name in self.params
return message.app_name.lower() in self.params


class Severities(Filter):
Expand Down
7 changes: 6 additions & 1 deletion tests/rules/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ def requester():

@pytest.mark.parametrize(
"received,filtered,expected",
[("app1", ["app1", "app2"], True), ("app3", ["app1", "app2"], False), ("app1", None, True)],
[
("app1", ["app1", "app2"], True),
("app3", ["app1", "app2"], False),
("app1", None, True),
("App1", ["aPP1"], True),
],
)
def test_applications(requester, make_mocked_message, received, filtered, expected):
msg = make_mocked_message(topic="dummy", body={"app": received})
Expand Down

0 comments on commit a2e9ca2

Please sign in to comment.