1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2020 Greenbone Networks GmbH |
3
|
|
|
# |
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
5
|
|
|
# |
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
7
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
# (at your option) any later version. |
10
|
|
|
# |
11
|
|
|
# This program is distributed in the hope that it will be useful, |
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
# GNU General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
import unittest |
20
|
|
|
|
21
|
|
|
from decimal import Decimal |
22
|
|
|
|
23
|
|
|
from gvm.errors import RequiredArgument |
24
|
|
|
|
25
|
|
|
from gvm.protocols.gmpv214 import SeverityLevel |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class GmpCreateOverrideTestCase: |
29
|
|
|
def test_create_override(self): |
30
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1') |
31
|
|
|
|
32
|
|
|
self.connection.send.has_been_called_with( |
33
|
|
|
'<create_override>' |
34
|
|
|
'<text>foo</text>' |
35
|
|
|
'<nvt oid="oid1"/>' |
36
|
|
|
'</create_override>' |
37
|
|
|
) |
38
|
|
|
|
39
|
|
|
def test_create_override_missing_text(self): |
40
|
|
|
with self.assertRaises(RequiredArgument): |
41
|
|
|
self.gmp.create_override(None, 'od1') |
42
|
|
|
|
43
|
|
|
with self.assertRaises(RequiredArgument): |
44
|
|
|
self.gmp.create_override('', 'oid1') |
45
|
|
|
|
46
|
|
|
def test_create_override_missing_nvt_oid(self): |
47
|
|
|
with self.assertRaises(RequiredArgument): |
48
|
|
|
self.gmp.create_override('foo', None) |
49
|
|
|
|
50
|
|
|
with self.assertRaises(RequiredArgument): |
51
|
|
|
self.gmp.create_override('foo', '') |
52
|
|
|
|
53
|
|
|
def test_create_override_with_hosts(self): |
54
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', hosts=[]) |
55
|
|
|
|
56
|
|
|
self.connection.send.has_been_called_with( |
57
|
|
|
'<create_override>' |
58
|
|
|
'<text>foo</text>' |
59
|
|
|
'<nvt oid="oid1"/>' |
60
|
|
|
'</create_override>' |
61
|
|
|
) |
62
|
|
|
|
63
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', hosts=['h1', 'h2']) |
64
|
|
|
|
65
|
|
|
self.connection.send.has_been_called_with( |
66
|
|
|
'<create_override>' |
67
|
|
|
'<text>foo</text>' |
68
|
|
|
'<nvt oid="oid1"/>' |
69
|
|
|
'<hosts>h1,h2</hosts>' |
70
|
|
|
'</create_override>' |
71
|
|
|
) |
72
|
|
|
|
73
|
|
|
def test_create_override_with_port(self): |
74
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', port='666') |
75
|
|
|
|
76
|
|
|
self.connection.send.has_been_called_with( |
77
|
|
|
'<create_override>' |
78
|
|
|
'<text>foo</text>' |
79
|
|
|
'<nvt oid="oid1"/>' |
80
|
|
|
'<port>666</port>' |
81
|
|
|
'</create_override>' |
82
|
|
|
) |
83
|
|
|
|
84
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', port=666) |
85
|
|
|
|
86
|
|
|
self.connection.send.has_been_called_with( |
87
|
|
|
'<create_override>' |
88
|
|
|
'<text>foo</text>' |
89
|
|
|
'<nvt oid="oid1"/>' |
90
|
|
|
'<port>666</port>' |
91
|
|
|
'</create_override>' |
92
|
|
|
) |
93
|
|
|
|
94
|
|
|
def test_create_override_with_result_id(self): |
95
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', result_id='r1') |
96
|
|
|
|
97
|
|
|
self.connection.send.has_been_called_with( |
98
|
|
|
'<create_override>' |
99
|
|
|
'<text>foo</text>' |
100
|
|
|
'<nvt oid="oid1"/>' |
101
|
|
|
'<result id="r1"/>' |
102
|
|
|
'</create_override>' |
103
|
|
|
) |
104
|
|
|
|
105
|
|
|
def test_create_override_with_task_id(self): |
106
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', task_id='t1') |
107
|
|
|
|
108
|
|
|
self.connection.send.has_been_called_with( |
109
|
|
|
'<create_override>' |
110
|
|
|
'<text>foo</text>' |
111
|
|
|
'<nvt oid="oid1"/>' |
112
|
|
|
'<task id="t1"/>' |
113
|
|
|
'</create_override>' |
114
|
|
|
) |
115
|
|
|
|
116
|
|
|
def test_create_override_with_severity(self): |
117
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', severity='5.5') |
118
|
|
|
|
119
|
|
|
self.connection.send.has_been_called_with( |
120
|
|
|
'<create_override>' |
121
|
|
|
'<text>foo</text>' |
122
|
|
|
'<nvt oid="oid1"/>' |
123
|
|
|
'<severity>5.5</severity>' |
124
|
|
|
'</create_override>' |
125
|
|
|
) |
126
|
|
|
|
127
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', severity=5.5) |
128
|
|
|
|
129
|
|
|
self.connection.send.has_been_called_with( |
130
|
|
|
'<create_override>' |
131
|
|
|
'<text>foo</text>' |
132
|
|
|
'<nvt oid="oid1"/>' |
133
|
|
|
'<severity>5.5</severity>' |
134
|
|
|
'</create_override>' |
135
|
|
|
) |
136
|
|
|
|
137
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', severity=Decimal(5.5)) |
138
|
|
|
|
139
|
|
|
self.connection.send.has_been_called_with( |
140
|
|
|
'<create_override>' |
141
|
|
|
'<text>foo</text>' |
142
|
|
|
'<nvt oid="oid1"/>' |
143
|
|
|
'<severity>5.5</severity>' |
144
|
|
|
'</create_override>' |
145
|
|
|
) |
146
|
|
|
|
147
|
|
|
def test_create_override_with_new_severity(self): |
148
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', new_severity='5.5') |
149
|
|
|
|
150
|
|
|
self.connection.send.has_been_called_with( |
151
|
|
|
'<create_override>' |
152
|
|
|
'<text>foo</text>' |
153
|
|
|
'<nvt oid="oid1"/>' |
154
|
|
|
'<new_severity>5.5</new_severity>' |
155
|
|
|
'</create_override>' |
156
|
|
|
) |
157
|
|
|
|
158
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', new_severity=5.5) |
159
|
|
|
|
160
|
|
|
self.connection.send.has_been_called_with( |
161
|
|
|
'<create_override>' |
162
|
|
|
'<text>foo</text>' |
163
|
|
|
'<nvt oid="oid1"/>' |
164
|
|
|
'<new_severity>5.5</new_severity>' |
165
|
|
|
'</create_override>' |
166
|
|
|
) |
167
|
|
|
|
168
|
|
|
self.gmp.create_override( |
169
|
|
|
'foo', nvt_oid='oid1', new_severity=Decimal(5.5) |
170
|
|
|
) |
171
|
|
|
|
172
|
|
|
self.connection.send.has_been_called_with( |
173
|
|
|
'<create_override>' |
174
|
|
|
'<text>foo</text>' |
175
|
|
|
'<nvt oid="oid1"/>' |
176
|
|
|
'<new_severity>5.5</new_severity>' |
177
|
|
|
'</create_override>' |
178
|
|
|
) |
179
|
|
|
|
180
|
|
|
def test_create_override_with_threat(self): |
181
|
|
|
self.gmp.create_override( |
182
|
|
|
'foo', nvt_oid='oid1', threat=SeverityLevel.HIGH |
183
|
|
|
) |
184
|
|
|
|
185
|
|
|
self.connection.send.has_been_called_with( |
186
|
|
|
'<create_override>' |
187
|
|
|
'<text>foo</text>' |
188
|
|
|
'<nvt oid="oid1"/>' |
189
|
|
|
'</create_override>' |
190
|
|
|
) |
191
|
|
|
|
192
|
|
|
def test_create_override_with_new_threat(self): |
193
|
|
|
self.gmp.create_override( |
194
|
|
|
'foo', nvt_oid='oid1', new_threat=SeverityLevel.HIGH |
195
|
|
|
) |
196
|
|
|
|
197
|
|
|
self.connection.send.has_been_called_with( |
198
|
|
|
'<create_override>' |
199
|
|
|
'<text>foo</text>' |
200
|
|
|
'<nvt oid="oid1"/>' |
201
|
|
|
'</create_override>' |
202
|
|
|
) |
203
|
|
|
|
204
|
|
|
def test_create_override_with_days_active(self): |
205
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', days_active=0) |
206
|
|
|
|
207
|
|
|
self.connection.send.has_been_called_with( |
208
|
|
|
'<create_override>' |
209
|
|
|
'<text>foo</text>' |
210
|
|
|
'<nvt oid="oid1"/>' |
211
|
|
|
'<active>0</active>' |
212
|
|
|
'</create_override>' |
213
|
|
|
) |
214
|
|
|
|
215
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', days_active=-1) |
216
|
|
|
|
217
|
|
|
self.connection.send.has_been_called_with( |
218
|
|
|
'<create_override>' |
219
|
|
|
'<text>foo</text>' |
220
|
|
|
'<nvt oid="oid1"/>' |
221
|
|
|
'<active>-1</active>' |
222
|
|
|
'</create_override>' |
223
|
|
|
) |
224
|
|
|
|
225
|
|
|
self.gmp.create_override('foo', nvt_oid='oid1', days_active=3600) |
226
|
|
|
|
227
|
|
|
self.connection.send.has_been_called_with( |
228
|
|
|
'<create_override>' |
229
|
|
|
'<text>foo</text>' |
230
|
|
|
'<nvt oid="oid1"/>' |
231
|
|
|
'<active>3600</active>' |
232
|
|
|
'</create_override>' |
233
|
|
|
) |
234
|
|
|
|
235
|
|
|
|
236
|
|
|
if __name__ == '__main__': |
237
|
|
|
unittest.main() |
238
|
|
|
|