@@ 26-201 (lines=176) @@ | ||
23 | from gvm.protocols.gmpv9 import AlertCondition, AlertEvent, AlertMethod |
|
24 | ||
25 | ||
26 | class GmpModifyAlertTestCase: |
|
27 | def test_modify_alert(self): |
|
28 | self.gmp.modify_alert(alert_id='a1') |
|
29 | ||
30 | self.connection.send.has_been_called_with( |
|
31 | '<modify_alert alert_id="a1"/>' |
|
32 | ) |
|
33 | ||
34 | def test_modify_alert_without_alert_id(self): |
|
35 | with self.assertRaises(RequiredArgument): |
|
36 | self.gmp.modify_alert(alert_id=None) |
|
37 | ||
38 | with self.assertRaises(RequiredArgument): |
|
39 | self.gmp.modify_alert(alert_id='') |
|
40 | ||
41 | with self.assertRaises(RequiredArgument): |
|
42 | self.gmp.modify_alert('') |
|
43 | ||
44 | def test_modify_alert_with_comment(self): |
|
45 | self.gmp.modify_alert(alert_id='a1', comment='lorem') |
|
46 | ||
47 | self.connection.send.has_been_called_with( |
|
48 | '<modify_alert alert_id="a1">' |
|
49 | '<comment>lorem</comment>' |
|
50 | '</modify_alert>' |
|
51 | ) |
|
52 | ||
53 | def test_modify_alert_with_name(self): |
|
54 | self.gmp.modify_alert(alert_id='a1', name='lorem') |
|
55 | ||
56 | self.connection.send.has_been_called_with( |
|
57 | '<modify_alert alert_id="a1">' |
|
58 | '<name>lorem</name>' |
|
59 | '</modify_alert>' |
|
60 | ) |
|
61 | ||
62 | def test_modify_alert_with_filter_id(self): |
|
63 | self.gmp.modify_alert(alert_id='a1', filter_id='f1') |
|
64 | ||
65 | self.connection.send.has_been_called_with( |
|
66 | '<modify_alert alert_id="a1">' '<filter id="f1"/>' '</modify_alert>' |
|
67 | ) |
|
68 | ||
69 | def test_modify_alert_invalid_condition(self): |
|
70 | with self.assertRaises(InvalidArgumentType): |
|
71 | self.gmp.modify_alert( |
|
72 | alert_id='a1', |
|
73 | condition='bar', |
|
74 | event='Task run status changed', |
|
75 | method='Email', |
|
76 | ) |
|
77 | ||
78 | def test_modify_alert_invalid_event(self): |
|
79 | with self.assertRaises(InvalidArgumentType): |
|
80 | self.gmp.modify_alert( |
|
81 | alert_id='a1', condition='Always', event='lorem', method='Email' |
|
82 | ) |
|
83 | ||
84 | def test_modify_alert_invalid_method(self): |
|
85 | with self.assertRaises(InvalidArgumentType): |
|
86 | self.gmp.modify_alert( |
|
87 | alert_id='a1', |
|
88 | condition='Always', |
|
89 | event='Task run status changed', |
|
90 | method='ipsum', |
|
91 | ) |
|
92 | ||
93 | def test_modify_alert_with_event_missing_method(self): |
|
94 | with self.assertRaisesRegex(RequiredArgument, "method is required"): |
|
95 | self.gmp.modify_alert( |
|
96 | alert_id='a1', |
|
97 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
98 | condition=AlertCondition.ALWAYS, |
|
99 | ) |
|
100 | ||
101 | with self.assertRaisesRegex(RequiredArgument, "method is required"): |
|
102 | self.gmp.modify_alert( |
|
103 | alert_id='a1', |
|
104 | event=AlertEvent.NEW_SECINFO_ARRIVED, |
|
105 | condition=AlertCondition.ALWAYS, |
|
106 | ) |
|
107 | ||
108 | with self.assertRaisesRegex(RequiredArgument, "method is required"): |
|
109 | self.gmp.modify_alert( |
|
110 | alert_id='a1', |
|
111 | event=AlertEvent.UPDATED_SECINFO_ARRIVED, |
|
112 | condition=AlertCondition.ALWAYS, |
|
113 | ) |
|
114 | ||
115 | def test_modify_alert_with_event_missing_condition(self): |
|
116 | with self.assertRaisesRegex(RequiredArgument, "condition is required"): |
|
117 | self.gmp.modify_alert( |
|
118 | alert_id='a1', |
|
119 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
120 | method=AlertMethod.SCP, |
|
121 | ) |
|
122 | ||
123 | with self.assertRaisesRegex(RequiredArgument, "condition is required"): |
|
124 | self.gmp.modify_alert( |
|
125 | alert_id='a1', |
|
126 | event=AlertEvent.NEW_SECINFO_ARRIVED, |
|
127 | method=AlertMethod.SCP, |
|
128 | ) |
|
129 | ||
130 | with self.assertRaisesRegex(RequiredArgument, "condition is required"): |
|
131 | self.gmp.modify_alert( |
|
132 | alert_id='a1', |
|
133 | event=AlertEvent.UPDATED_SECINFO_ARRIVED, |
|
134 | method=AlertMethod.SCP, |
|
135 | ) |
|
136 | ||
137 | def test_modify_alert_invalid_condition_for_secinfo(self): |
|
138 | with self.assertRaises(InvalidArgumentType): |
|
139 | self.gmp.modify_alert( |
|
140 | alert_id='a1', |
|
141 | condition='Severity at least', |
|
142 | event='Updated SecInfo arrived', |
|
143 | method='Email', |
|
144 | ) |
|
145 | ||
146 | def test_modify_alert_invalid_method_for_secinfo(self): |
|
147 | with self.assertRaises(InvalidArgumentType): |
|
148 | self.gmp.modify_alert( |
|
149 | alert_id='a1', |
|
150 | condition='Always', |
|
151 | event='Updated SecInfo arrived', |
|
152 | method='HTTP Get', |
|
153 | ) |
|
154 | ||
155 | def test_modify_alert_with_event_data(self): |
|
156 | self.gmp.modify_alert( |
|
157 | alert_id='a1', |
|
158 | condition=AlertCondition.ALWAYS, |
|
159 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
160 | method=AlertMethod.EMAIL, |
|
161 | event_data={'foo': 'bar'}, |
|
162 | ) |
|
163 | ||
164 | self.connection.send.has_been_called_with( |
|
165 | '<modify_alert alert_id="a1">' |
|
166 | '<condition>Always</condition>' |
|
167 | '<method>Email</method>' |
|
168 | '<event>Task run status changed' |
|
169 | '<data>bar<name>foo</name></data>' |
|
170 | '</event>' |
|
171 | '</modify_alert>' |
|
172 | ) |
|
173 | ||
174 | def test_modify_alert_with_condition_data(self): |
|
175 | self.gmp.modify_alert( |
|
176 | alert_id='a1', |
|
177 | condition=AlertCondition.ALWAYS, |
|
178 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
179 | method=AlertMethod.EMAIL, |
|
180 | condition_data={'foo': 'bar'}, |
|
181 | ) |
|
182 | ||
183 | self.connection.send.has_been_called_with( |
|
184 | '<modify_alert alert_id="a1">' |
|
185 | '<condition>Always<data>bar<name>foo</name></data></condition>' |
|
186 | '<method>Email</method>' |
|
187 | '<event>Task run status changed</event>' |
|
188 | '</modify_alert>' |
|
189 | ) |
|
190 | ||
191 | def test_modify_alert_with_method_data(self): |
|
192 | self.gmp.modify_alert( |
|
193 | alert_id='a1', |
|
194 | condition=AlertCondition.ALWAYS, |
|
195 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
196 | method=AlertMethod.EMAIL, |
|
197 | method_data={'foo': 'bar'}, |
|
198 | ) |
|
199 | ||
200 | self.connection.send.has_been_called_with( |
|
201 | '<modify_alert alert_id="a1">' |
|
202 | '<condition>Always</condition>' |
|
203 | '<method>Email<data>bar<name>foo</name></data></method>' |
|
204 | '<event>Task run status changed</event>' |
@@ 26-201 (lines=176) @@ | ||
23 | from gvm.protocols.gmpv7 import AlertCondition, AlertEvent, AlertMethod |
|
24 | ||
25 | ||
26 | class GmpModifyAlertTestCase: |
|
27 | def test_modify_alert(self): |
|
28 | self.gmp.modify_alert(alert_id='a1') |
|
29 | ||
30 | self.connection.send.has_been_called_with( |
|
31 | '<modify_alert alert_id="a1"/>' |
|
32 | ) |
|
33 | ||
34 | def test_modify_alert_without_alert_id(self): |
|
35 | with self.assertRaises(RequiredArgument): |
|
36 | self.gmp.modify_alert(alert_id=None) |
|
37 | ||
38 | with self.assertRaises(RequiredArgument): |
|
39 | self.gmp.modify_alert(alert_id='') |
|
40 | ||
41 | with self.assertRaises(RequiredArgument): |
|
42 | self.gmp.modify_alert('') |
|
43 | ||
44 | def test_modify_alert_with_comment(self): |
|
45 | self.gmp.modify_alert(alert_id='a1', comment='lorem') |
|
46 | ||
47 | self.connection.send.has_been_called_with( |
|
48 | '<modify_alert alert_id="a1">' |
|
49 | '<comment>lorem</comment>' |
|
50 | '</modify_alert>' |
|
51 | ) |
|
52 | ||
53 | def test_modify_alert_with_name(self): |
|
54 | self.gmp.modify_alert(alert_id='a1', name='lorem') |
|
55 | ||
56 | self.connection.send.has_been_called_with( |
|
57 | '<modify_alert alert_id="a1">' |
|
58 | '<name>lorem</name>' |
|
59 | '</modify_alert>' |
|
60 | ) |
|
61 | ||
62 | def test_modify_alert_with_filter_id(self): |
|
63 | self.gmp.modify_alert(alert_id='a1', filter_id='f1') |
|
64 | ||
65 | self.connection.send.has_been_called_with( |
|
66 | '<modify_alert alert_id="a1">' '<filter id="f1"/>' '</modify_alert>' |
|
67 | ) |
|
68 | ||
69 | def test_modify_alert_invalid_condition(self): |
|
70 | with self.assertRaises(InvalidArgumentType): |
|
71 | self.gmp.modify_alert( |
|
72 | alert_id='a1', |
|
73 | condition='bar', |
|
74 | event='Task run status changed', |
|
75 | method='Email', |
|
76 | ) |
|
77 | ||
78 | def test_modify_alert_invalid_event(self): |
|
79 | with self.assertRaises(InvalidArgumentType): |
|
80 | self.gmp.modify_alert( |
|
81 | alert_id='a1', condition='Always', event='lorem', method='Email' |
|
82 | ) |
|
83 | ||
84 | def test_modify_alert_invalid_method(self): |
|
85 | with self.assertRaises(InvalidArgumentType): |
|
86 | self.gmp.modify_alert( |
|
87 | alert_id='a1', |
|
88 | condition='Always', |
|
89 | event='Task run status changed', |
|
90 | method='ipsum', |
|
91 | ) |
|
92 | ||
93 | def test_modify_alert_with_event_missing_method(self): |
|
94 | with self.assertRaisesRegex(RequiredArgument, "method is required"): |
|
95 | self.gmp.modify_alert( |
|
96 | alert_id='a1', |
|
97 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
98 | condition=AlertCondition.ALWAYS, |
|
99 | ) |
|
100 | ||
101 | with self.assertRaisesRegex(RequiredArgument, "method is required"): |
|
102 | self.gmp.modify_alert( |
|
103 | alert_id='a1', |
|
104 | event=AlertEvent.NEW_SECINFO_ARRIVED, |
|
105 | condition=AlertCondition.ALWAYS, |
|
106 | ) |
|
107 | ||
108 | with self.assertRaisesRegex(RequiredArgument, "method is required"): |
|
109 | self.gmp.modify_alert( |
|
110 | alert_id='a1', |
|
111 | event=AlertEvent.UPDATED_SECINFO_ARRIVED, |
|
112 | condition=AlertCondition.ALWAYS, |
|
113 | ) |
|
114 | ||
115 | def test_modify_alert_with_event_missing_condition(self): |
|
116 | with self.assertRaisesRegex(RequiredArgument, "condition is required"): |
|
117 | self.gmp.modify_alert( |
|
118 | alert_id='a1', |
|
119 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
120 | method=AlertMethod.SCP, |
|
121 | ) |
|
122 | ||
123 | with self.assertRaisesRegex(RequiredArgument, "condition is required"): |
|
124 | self.gmp.modify_alert( |
|
125 | alert_id='a1', |
|
126 | event=AlertEvent.NEW_SECINFO_ARRIVED, |
|
127 | method=AlertMethod.SCP, |
|
128 | ) |
|
129 | ||
130 | with self.assertRaisesRegex(RequiredArgument, "condition is required"): |
|
131 | self.gmp.modify_alert( |
|
132 | alert_id='a1', |
|
133 | event=AlertEvent.UPDATED_SECINFO_ARRIVED, |
|
134 | method=AlertMethod.SCP, |
|
135 | ) |
|
136 | ||
137 | def test_modify_alert_invalid_condition_for_secinfo(self): |
|
138 | with self.assertRaises(InvalidArgumentType): |
|
139 | self.gmp.modify_alert( |
|
140 | alert_id='a1', |
|
141 | condition='Severity at least', |
|
142 | event='Updated SecInfo arrived', |
|
143 | method='Email', |
|
144 | ) |
|
145 | ||
146 | def test_modify_alert_invalid_method_for_secinfo(self): |
|
147 | with self.assertRaises(InvalidArgumentType): |
|
148 | self.gmp.modify_alert( |
|
149 | alert_id='a1', |
|
150 | condition='Always', |
|
151 | event='Updated SecInfo arrived', |
|
152 | method='HTTP Get', |
|
153 | ) |
|
154 | ||
155 | def test_modify_alert_with_event_data(self): |
|
156 | self.gmp.modify_alert( |
|
157 | alert_id='a1', |
|
158 | condition=AlertCondition.ALWAYS, |
|
159 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
160 | method=AlertMethod.EMAIL, |
|
161 | event_data={'foo': 'bar'}, |
|
162 | ) |
|
163 | ||
164 | self.connection.send.has_been_called_with( |
|
165 | '<modify_alert alert_id="a1">' |
|
166 | '<condition>Always</condition>' |
|
167 | '<method>Email</method>' |
|
168 | '<event>Task run status changed' |
|
169 | '<data>bar<name>foo</name></data>' |
|
170 | '</event>' |
|
171 | '</modify_alert>' |
|
172 | ) |
|
173 | ||
174 | def test_modify_alert_with_condition_data(self): |
|
175 | self.gmp.modify_alert( |
|
176 | alert_id='a1', |
|
177 | condition=AlertCondition.ALWAYS, |
|
178 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
179 | method=AlertMethod.EMAIL, |
|
180 | condition_data={'foo': 'bar'}, |
|
181 | ) |
|
182 | ||
183 | self.connection.send.has_been_called_with( |
|
184 | '<modify_alert alert_id="a1">' |
|
185 | '<condition>Always<data>bar<name>foo</name></data></condition>' |
|
186 | '<method>Email</method>' |
|
187 | '<event>Task run status changed</event>' |
|
188 | '</modify_alert>' |
|
189 | ) |
|
190 | ||
191 | def test_modify_alert_with_method_data(self): |
|
192 | self.gmp.modify_alert( |
|
193 | alert_id='a1', |
|
194 | condition=AlertCondition.ALWAYS, |
|
195 | event=AlertEvent.TASK_RUN_STATUS_CHANGED, |
|
196 | method=AlertMethod.EMAIL, |
|
197 | method_data={'foo': 'bar'}, |
|
198 | ) |
|
199 | ||
200 | self.connection.send.has_been_called_with( |
|
201 | '<modify_alert alert_id="a1">' |
|
202 | '<condition>Always</condition>' |
|
203 | '<method>Email<data>bar<name>foo</name></data></method>' |
|
204 | '<event>Task run status changed</event>' |