7
7
8
8
9
9
class TestOpenBASCrowdstrike (unittest .TestCase ):
10
- @patch ("pyobas.apis.InjectExpectationTraceManager.create" )
11
10
@patch ("pyobas.apis.InjectExpectationManager.update" )
12
11
def test_when_alert_matches_update_prevention_expectation (
13
- self , mock_expectation_update , mock_traces_create
12
+ self , mock_expectation_update
14
13
):
15
14
expected_expectation_id = "expectation_id"
16
15
expectations = [
@@ -41,7 +40,7 @@ def test_when_alert_matches_update_prevention_expectation(
41
40
42
41
collector = get_default_collector (strategy )
43
42
44
- collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
43
+ traces = collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
45
44
46
45
mock_expectation_update .assert_called_once_with (
47
46
expected_expectation_id ,
@@ -52,9 +51,10 @@ def test_when_alert_matches_update_prevention_expectation(
52
51
"metadata" : {"alertId" : expected_expectation_id },
53
52
},
54
53
)
55
-
56
- mock_traces_create .assert_called_once_with (
57
- data = {
54
+ self .assertEqual (1 , len (traces ))
55
+ self .assertEqual (
56
+ traces [0 ],
57
+ {
58
58
"inject_expectation_trace_expectation" : expected_expectation_id ,
59
59
"inject_expectation_trace_source_id" : collector .config .get_conf (
60
60
"collector_id"
@@ -69,10 +69,9 @@ def test_when_alert_matches_update_prevention_expectation(
69
69
},
70
70
)
71
71
72
- @patch ("pyobas.apis.InjectExpectationTraceManager.create" )
73
72
@patch ("pyobas.apis.InjectExpectationManager.update" )
74
73
def test_when_alert_matches_but_not_prevented_update_prevention_expectation (
75
- self , mock_expectation_update , mock_traces_create
74
+ self , mock_expectation_update
76
75
):
77
76
expected_expectation_id = "expectation_id"
78
77
expectations = [
@@ -103,7 +102,7 @@ def test_when_alert_matches_but_not_prevented_update_prevention_expectation(
103
102
104
103
collector = get_default_collector (strategy )
105
104
106
- collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
105
+ traces = collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
107
106
108
107
mock_expectation_update .assert_called_once_with (
109
108
expected_expectation_id ,
@@ -115,8 +114,10 @@ def test_when_alert_matches_but_not_prevented_update_prevention_expectation(
115
114
},
116
115
)
117
116
118
- mock_traces_create .assert_called_once_with (
119
- data = {
117
+ self .assertEqual (1 , len (traces ))
118
+ self .assertEqual (
119
+ traces [0 ],
120
+ {
120
121
"inject_expectation_trace_expectation" : expected_expectation_id ,
121
122
"inject_expectation_trace_source_id" : collector .config .get_conf (
122
123
"collector_id"
@@ -131,10 +132,9 @@ def test_when_alert_matches_but_not_prevented_update_prevention_expectation(
131
132
},
132
133
)
133
134
134
- @patch ("pyobas.apis.InjectExpectationTraceManager.create" )
135
135
@patch ("pyobas.apis.InjectExpectationManager.update" )
136
136
def test_when_alert_matches_update_detection_expectation (
137
- self , mock_expectation_update , mock_traces_create
137
+ self , mock_expectation_update
138
138
):
139
139
expected_expectation_id = "expectation_id"
140
140
expectations = [
@@ -165,7 +165,7 @@ def test_when_alert_matches_update_detection_expectation(
165
165
166
166
collector = get_default_collector (strategy )
167
167
168
- collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
168
+ traces = collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
169
169
170
170
mock_expectation_update .assert_called_once_with (
171
171
expected_expectation_id ,
@@ -177,8 +177,10 @@ def test_when_alert_matches_update_detection_expectation(
177
177
},
178
178
)
179
179
180
- mock_traces_create .assert_called_once_with (
181
- data = {
180
+ self .assertEqual (1 , len (traces ))
181
+ self .assertEqual (
182
+ traces [0 ],
183
+ {
182
184
"inject_expectation_trace_expectation" : expected_expectation_id ,
183
185
"inject_expectation_trace_source_id" : collector .config .get_conf (
184
186
"collector_id"
@@ -193,10 +195,9 @@ def test_when_alert_matches_update_detection_expectation(
193
195
},
194
196
)
195
197
196
- @patch ("pyobas.apis.InjectExpectationTraceManager.create" )
197
198
@patch ("pyobas.apis.InjectExpectationManager.update" )
198
199
def test_when_expectation_has_expected_hostname_signature_ignore_it (
199
- self , mock_expectation_update , mock_traces_create
200
+ self , mock_expectation_update
200
201
):
201
202
expected_expectation_id = "expectation_id"
202
203
expectations = [
@@ -228,7 +229,7 @@ def test_when_expectation_has_expected_hostname_signature_ignore_it(
228
229
229
230
collector = get_default_collector (strategy )
230
231
231
- collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
232
+ traces = collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
232
233
233
234
mock_expectation_update .assert_called_once_with (
234
235
expected_expectation_id ,
@@ -240,8 +241,10 @@ def test_when_expectation_has_expected_hostname_signature_ignore_it(
240
241
},
241
242
)
242
243
243
- mock_traces_create .assert_called_once_with (
244
- data = {
244
+ self .assertEqual (1 , len (traces ))
245
+ self .assertEqual (
246
+ traces [0 ],
247
+ {
245
248
"inject_expectation_trace_expectation" : expected_expectation_id ,
246
249
"inject_expectation_trace_source_id" : collector .config .get_conf (
247
250
"collector_id"
@@ -289,9 +292,10 @@ def test_when_alert_fails_to_match_dont_update_prevention_expectation(
289
292
290
293
collector = get_default_collector (strategy )
291
294
292
- collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
295
+ traces = collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
293
296
294
297
mock_expectation_update .assert_not_called ()
298
+ self .assertEqual (0 , len (traces ))
295
299
296
300
@patch ("pyobas.apis.InjectExpectationManager.update" )
297
301
def test_when_signatures_match_when_unknown_expectation_type_skip_updating_expectation (
@@ -326,10 +330,12 @@ def test_when_signatures_match_when_unknown_expectation_type_skip_updating_expec
326
330
327
331
collector = get_default_collector (strategy )
328
332
329
- collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
333
+ traces = collector ._match_expectations ([Item (** MOCKED_ALERT )], expectations )
330
334
331
335
mock_expectation_update .assert_not_called ()
332
336
337
+ self .assertEqual (0 , len (traces ))
338
+
333
339
334
340
if __name__ == "__main__" :
335
341
unittest .main ()
0 commit comments