Skip to content

Commit

Permalink
Unit Test to validate from field in toml file (elastic#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank-elastic authored Jul 10, 2024
1 parent 7041166 commit 59a10be
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_all_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ def test_max_signals_note(self):
f'Expected: {max_signal_standard_setup}\n\n'
f'Actual: {rule.contents.data.setup}')

def test_from_filed_value(self):
""" Add "from" Field Validation for All Rules"""
failures = []
valid_format = re.compile(r'^now-\d+[yMwdhHms]$')
for rule in self.all_rules:
from_field = rule.contents.data.get('from_')
if from_field is not None:
if not valid_format.match(from_field):
err_msg = f'{self.rule_str(rule)} has invalid value {from_field}'
failures.append(err_msg)
if failures:
fail_msg = """
The following rules have invalid 'from' filed value \n
"""
self.fail(fail_msg + '\n'.join(failures))


class TestThreatMappings(BaseRuleTest):
"""Test threat mapping data for rules."""
Expand Down

0 comments on commit 59a10be

Please sign in to comment.