2021-03-05 11:16:02 -09:00
|
|
|
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
|
# or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
|
# 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
|
# 2.0.
|
|
|
|
|
|
|
|
|
|
"""Shared resources for tests."""
|
|
|
|
|
|
|
|
|
|
import unittest
|
2021-09-01 15:29:53 -08:00
|
|
|
from typing import Union
|
2021-03-05 11:16:02 -09:00
|
|
|
|
2021-03-24 10:24:32 -06:00
|
|
|
from detection_rules.rule import TOMLRule
|
2021-09-01 15:29:53 -08:00
|
|
|
from detection_rules.rule_loader import DeprecatedCollection, DeprecatedRule, RuleCollection, production_filter
|
2021-03-05 11:16:02 -09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseRuleTest(unittest.TestCase):
|
|
|
|
|
"""Base class for shared test cases which need to load rules"""
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpClass(cls):
|
2021-09-01 15:29:53 -08:00
|
|
|
rc = RuleCollection.default()
|
2022-04-01 15:27:08 -08:00
|
|
|
cls.all_rules = rc.rules
|
2021-09-01 15:29:53 -08:00
|
|
|
cls.rule_lookup = rc.id_map
|
2022-04-01 15:27:08 -08:00
|
|
|
cls.production_rules = rc.filter(production_filter)
|
2021-09-01 15:29:53 -08:00
|
|
|
cls.deprecated_rules: DeprecatedCollection = rc.deprecated
|
2021-03-05 11:16:02 -09:00
|
|
|
|
|
|
|
|
@staticmethod
|
2021-09-01 15:29:53 -08:00
|
|
|
def rule_str(rule: Union[DeprecatedRule, TOMLRule], trailer=' ->'):
|
2021-03-05 11:16:02 -09:00
|
|
|
return f'{rule.id} - {rule.name}{trailer or ""}'
|