Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions intelmq/bots/experts/sieve/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ def validate_numeric_match(num_match) -> None:
if type not in valid_types:
raise TextXSemanticError(f"Incompatible type: {type}.", **position)
except KeyError:
if any(
num_match.key.startswith(f"{key}.") and value["type"] == "JSONDict"
for key, value in SieveExpertBot._harmonization.items()
):
return
raise TextXSemanticError(f"Invalid key: {num_match.key}.", **position)

@staticmethod
Expand Down
15 changes: 15 additions & 0 deletions intelmq/tests/bots/experts/sieve/test_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,21 @@ def test_numeric_invalid_key(self):
exception = context.exception
self.assertRegex(str(exception), r".*Incompatible type: FQDN\.$")

def test_numeric_extra_jsondict_match(self):
"""Test numeric match for dynamic extra.* fields."""
self.sysconfig["file"] = os.path.join(
os.path.dirname(__file__),
"test_sieve_files/test_numeric_extra_jsondict.sieve",
)

event = EXAMPLE_INPUT.copy()
event["extra.min_amplification"] = 6
expected = event.copy()
expected["comment"] = "matched extra numeric field"
self.input_message = event
self.run_bot()
self.assertMessageEqual(0, expected)

def test_exists_match(self):
"""Test :exists match"""
self.sysconfig["file"] = os.path.join(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if extra.min_amplification > 5 {
add comment = "matched extra numeric field"
}