11
11
import intelmq .lib .test as test
12
12
from intelmq .bots .outputs .misp .output_feed import MISPFeedOutputBot
13
13
14
- EXAMPLE_EVENT = {"classification.type" : "infected-system" ,
15
- "destination.port" : 9796 ,
16
- "feed.accuracy" : 100.0 ,
17
- "destination.ip" : "52.18.196.169" ,
18
- "malware.name" : "salityp2p" ,
19
- "event_description.text" : "Sinkhole attempted connection" ,
20
- "time.source" : "2016-04-19T23:16:08+00:00" ,
21
- "source.ip" : "152.166.119.2" ,
22
- "feed.url" : "http://alerts.bitsighttech.com:8080/stream?" ,
23
- "source.geolocation.country" : "Dominican Republic" ,
24
- "time.observation" : "2016-04-19T23:16:08+00:00" ,
25
- "source.port" : 65118 ,
26
- "__type" : "Event" ,
27
- "feed.name" : "BitSight" ,
28
- "extra.non_ascii" : "ççãããã\x80 \ua000 \164 \x80 \x80 abcd \165 \166 " ,
29
- "raw" : "eyJ0cm9qYW5mYW1pbHkiOiJTYWxpdHlwMnAiLCJlbnYiOnsic"
30
- "mVtb3RlX2FkZHIiOiIxNTIuMTY2LjExOS4yIiwicmVtb3RlX3"
31
- "BvcnQiOiI2NTExOCIsInNlcnZlcl9hZGRyIjoiNTIuMTguMTk"
32
- "2LjE2OSIsInNlcnZlcl9wb3J0IjoiOTc5NiJ9LCJfdHMiOjE0"
33
- "NjExMDc3NjgsIl9nZW9fZW52X3JlbW90ZV9hZGRyIjp7ImNvd"
34
- "W50cnlfbmFtZSI6IkRvbWluaWNhbiBSZXB1YmxpYyJ9fQ==" ,
35
- "__type" : "Event" ,
36
- }
14
+ EXAMPLE_EVENT = {
15
+ "classification.type" : "infected-system" ,
16
+ "destination.port" : 9796 ,
17
+ "feed.accuracy" : 100.0 ,
18
+ "destination.ip" : "52.18.196.169" ,
19
+ "malware.name" : "salityp2p" ,
20
+ "event_description.text" : "Sinkhole attempted connection" ,
21
+ "time.source" : "2016-04-19T23:16:08+00:00" ,
22
+ "source.ip" : "152.166.119.2" ,
23
+ "feed.url" : "http://alerts.bitsighttech.com:8080/stream?" ,
24
+ "source.geolocation.country" : "Dominican Republic" ,
25
+ "time.observation" : "2016-04-19T23:16:08+00:00" ,
26
+ "source.port" : 65118 ,
27
+ "__type" : "Event" ,
28
+ "feed.name" : "BitSight" ,
29
+ "extra.non_ascii" : "ççãããã\x80 \ua000 \164 \x80 \x80 abcd \165 \166 " ,
30
+ "raw" : "eyJ0cm9qYW5mYW1pbHkiOiJTYWxpdHlwMnAiLCJlbnYiOnsic"
31
+ "mVtb3RlX2FkZHIiOiIxNTIuMTY2LjExOS4yIiwicmVtb3RlX3"
32
+ "BvcnQiOiI2NTExOCIsInNlcnZlcl9hZGRyIjoiNTIuMTguMTk"
33
+ "2LjE2OSIsInNlcnZlcl9wb3J0IjoiOTc5NiJ9LCJfdHMiOjE0"
34
+ "NjExMDc3NjgsIl9nZW9fZW52X3JlbW90ZV9hZGRyIjp7ImNvd"
35
+ "W50cnlfbmFtZSI6IkRvbWluaWNhbiBSZXB1YmxpYyJ9fQ==" ,
36
+ "__type" : "Event" ,
37
+ }
37
38
38
39
39
40
@test .skip_exotic ()
@@ -43,11 +44,16 @@ def set_bot(cls):
43
44
cls .use_cache = True
44
45
cls .bot_reference = MISPFeedOutputBot
45
46
cls .default_input_message = EXAMPLE_EVENT
46
- cls .directory = TemporaryDirectory ()
47
- cls .sysconfig = {"misp_org_name" : 'IntelMQTestOrg' ,
48
- "misp_org_uuid" : "b89da4c2-0f74-11ea-96a1-6fa873a0eb4d" ,
49
- "output_dir" : cls .directory .name ,
50
- "interval_event" : '1 hour' }
47
+ cls .sysconfig = {
48
+ "misp_org_name" : "IntelMQTestOrg" ,
49
+ "misp_org_uuid" : "b89da4c2-0f74-11ea-96a1-6fa873a0eb4d" ,
50
+ "interval_event" : "1 hour" ,
51
+ }
52
+
53
+ def setUp (self ) -> None :
54
+ super ().setUp ()
55
+ self .directory = TemporaryDirectory ()
56
+ self .sysconfig ["output_dir" ] = self .directory .name
51
57
52
58
def test_event (self ):
53
59
self .run_bot ()
@@ -59,7 +65,7 @@ def test_event(self):
59
65
60
66
def test_accumulating_events (self ):
61
67
self .input_message = [EXAMPLE_EVENT , EXAMPLE_EVENT ]
62
- self .run_bot (iterations = 2 , parameters = {"delay_save_event_count " : 3 })
68
+ self .run_bot (iterations = 2 , parameters = {"bulk_save_count " : 3 })
63
69
64
70
current_event = open (f"{ self .directory .name } /.current" ).read ()
65
71
@@ -69,15 +75,15 @@ def test_accumulating_events(self):
69
75
assert len (objects ) == 0
70
76
71
77
self .input_message = [EXAMPLE_EVENT ]
72
- self .run_bot (parameters = {"delay_save_event_count " : 3 })
78
+ self .run_bot (parameters = {"bulk_save_count " : 3 })
73
79
74
80
# When enough events were collected, save them
75
81
with open (current_event ) as f :
76
82
objects = json .load (f )["Event" ]["Object" ]
77
83
assert len (objects ) == 3
78
84
79
85
self .input_message = [EXAMPLE_EVENT , EXAMPLE_EVENT , EXAMPLE_EVENT ]
80
- self .run_bot (iterations = 3 , parameters = {"delay_save_event_count " : 3 })
86
+ self .run_bot (iterations = 3 , parameters = {"bulk_save_count " : 3 })
81
87
82
88
# We continue saving to the same file until interval timeout
83
89
with open (current_event ) as f :
@@ -87,22 +93,18 @@ def test_accumulating_events(self):
87
93
# Simulating leftovers in the queue when it's time to generate new event
88
94
Path (f"{ self .directory .name } /.current" ).unlink ()
89
95
self .bot .cache_put (EXAMPLE_EVENT )
90
- self .run_bot (parameters = {"delay_save_event_count " : 3 })
96
+ self .run_bot (parameters = {"bulk_save_count " : 3 })
91
97
92
98
new_event = open (f"{ self .directory .name } /.current" ).read ()
93
99
with open (new_event ) as f :
94
100
objects = json .load (f )["Event" ]["Object" ]
95
101
assert len (objects ) == 1
96
102
97
-
98
103
def tearDown (self ):
99
104
self .cache .delete (self .bot_id )
105
+ self .directory .cleanup ()
100
106
super ().tearDown ()
101
107
102
- @classmethod
103
- def tearDownClass (cls ):
104
- cls .directory .cleanup ()
105
-
106
108
107
109
if __name__ == "__main__" : # pragma: no cover
108
110
unittest .main ()
0 commit comments