Add unit-tests for open port violation alert

This commit is contained in:
Jonathan Claudius 2017-01-26 16:19:57 -05:00 коммит произвёл Brandon Myers
Родитель f935917a01
Коммит c06f653cb6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 8AA79AD83045BBC7
1 изменённых файлов: 84 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,84 @@
from positive_alert_test_case import PositiveAlertTestCase
from negative_alert_test_case import NegativeAlertTestCase
from alert_test_suite import AlertTestSuite
class TestAlertOpenPortViolation(AlertTestSuite):
alert_filename = "open_port_violation"
# This event is the default positive event that will cause the
# alert to trigger
default_event = {
"_type": "event",
"_source": {
"tags": ["open_port_policy_violation"],
"details": {
"destinationipaddress": "220.231.44.213",
"destinationport": 25,
}
}
}
# This alert is the expected result from running this task
default_alert = {
"category": "open_port_policy_violation",
"tags": ['open_port_policy_violation'],
"severity": "CRITICAL",
"summary": '10 unauthorized open port(s) on 220.231.44.213 (25 25 25 25 25 )',
}
test_cases = []
default_events = list()
for num in xrange(10):
default_events.append(AlertTestSuite.copy(default_event))
test_cases.append(
PositiveAlertTestCase(
description="Positive test with default events and default alert expected",
events=default_events,
expected_alert=default_alert
)
)
custom_events = default_events
for temp_event in custom_events:
temp_event['_source']['utctimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda(date_timedelta={'minutes': 239})
test_cases.append(
PositiveAlertTestCase(
description="Positive test with events a minute earlier",
events=custom_events,
expected_alert=default_alert
)
)
custom_events = default_events
for temp_event in custom_events:
temp_event['_type'] = 'bad'
test_cases.append(
NegativeAlertTestCase(
description="Negative test case with events with incorrect _type",
events=custom_events,
)
)
custom_events = default_events
for temp_event in custom_events:
temp_event['_source']['tags'] = 'bad tag example'
test_cases.append(
NegativeAlertTestCase(
description="Negative test case with events with incorrect tags",
events=custom_events,
)
)
custom_events = default_events
for temp_event in custom_events:
temp_event['_source']['utctimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda({'minutes': 241})
test_cases.append(
NegativeAlertTestCase(
description="Negative test case with old timestamp",
events=custom_events,
)
)