Completed
Push — master ( f3cde9...b114e7 )
by
unknown
13s queued 11s
created

GmpCreateOverrideTestCase.test_create_override_with_comment()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2018 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, InvalidArgument
24
from gvm.protocols.gmpv7 import Gmp
25
26
from .. import MockConnection
27
28
29
class GmpCreateOverrideTestCase(unittest.TestCase):
30
31
    def setUp(self):
32
        self.connection = MockConnection()
33
        self.gmp = Gmp(self.connection)
34
35
    def test_create_override(self):
36
        self.gmp.create_override('foo', nvt_oid='oid1')
37
38
        self.connection.send.has_been_called_with(
39
            '<create_override>'
40
            '<text>foo</text>'
41
            '<nvt oid="oid1"/>'
42
            '</create_override>'
43
        )
44
45
    def test_create_override_missing_text(self):
46
        with self.assertRaises(RequiredArgument):
47
            self.gmp.create_override(None, 'od1')
48
49
        with self.assertRaises(RequiredArgument):
50
            self.gmp.create_override('', 'oid1')
51
52
    def test_create_override_missing_nvt_iod(self):
53
        with self.assertRaises(RequiredArgument):
54
            self.gmp.create_override('foo', None)
55
56
        with self.assertRaises(RequiredArgument):
57
            self.gmp.create_override('foo', '')
58
59
    def test_create_override_with_hosts(self):
60
        self.gmp.create_override('foo', nvt_oid='oid1', hosts=[])
61
62
        self.connection.send.has_been_called_with(
63
            '<create_override>'
64
            '<text>foo</text>'
65
            '<nvt oid="oid1"/>'
66
            '</create_override>'
67
        )
68
69
        self.gmp.create_override('foo', nvt_oid='oid1', hosts=['h1', 'h2'])
70
71
        self.connection.send.has_been_called_with(
72
            '<create_override>'
73
            '<text>foo</text>'
74
            '<nvt oid="oid1"/>'
75
            '<hosts>h1,h2</hosts>'
76
            '</create_override>'
77
        )
78
79
    def test_create_override_with_port(self):
80
        self.gmp.create_override('foo', nvt_oid='oid1', port='666')
81
82
        self.connection.send.has_been_called_with(
83
            '<create_override>'
84
            '<text>foo</text>'
85
            '<nvt oid="oid1"/>'
86
            '<port>666</port>'
87
            '</create_override>'
88
        )
89
90
        self.gmp.create_override('foo', nvt_oid='oid1', port=666)
91
92
        self.connection.send.has_been_called_with(
93
            '<create_override>'
94
            '<text>foo</text>'
95
            '<nvt oid="oid1"/>'
96
            '<port>666</port>'
97
            '</create_override>'
98
        )
99
100
    def test_create_override_with_result_id(self):
101
        self.gmp.create_override('foo', nvt_oid='oid1', result_id='r1')
102
103
        self.connection.send.has_been_called_with(
104
            '<create_override>'
105
            '<text>foo</text>'
106
            '<nvt oid="oid1"/>'
107
            '<result id="r1"/>'
108
            '</create_override>'
109
        )
110
111
    def test_create_override_with_task_id(self):
112
        self.gmp.create_override('foo', nvt_oid='oid1', task_id='t1')
113
114
        self.connection.send.has_been_called_with(
115
            '<create_override>'
116
            '<text>foo</text>'
117
            '<nvt oid="oid1"/>'
118
            '<task id="t1"/>'
119
            '</create_override>'
120
        )
121
122
    def test_create_override_with_severity(self):
123
        self.gmp.create_override('foo', nvt_oid='oid1', severity='5.5')
124
125
        self.connection.send.has_been_called_with(
126
            '<create_override>'
127
            '<text>foo</text>'
128
            '<nvt oid="oid1"/>'
129
            '<severity>5.5</severity>'
130
            '</create_override>'
131
        )
132
133
        self.gmp.create_override('foo', nvt_oid='oid1', severity=5.5)
134
135
        self.connection.send.has_been_called_with(
136
            '<create_override>'
137
            '<text>foo</text>'
138
            '<nvt oid="oid1"/>'
139
            '<severity>5.5</severity>'
140
            '</create_override>'
141
        )
142
143
        self.gmp.create_override('foo', nvt_oid='oid1', severity=Decimal(5.5))
144
145
        self.connection.send.has_been_called_with(
146
            '<create_override>'
147
            '<text>foo</text>'
148
            '<nvt oid="oid1"/>'
149
            '<severity>5.5</severity>'
150
            '</create_override>'
151
        )
152
153
    def test_create_override_with_new_severity(self):
154
        self.gmp.create_override('foo', nvt_oid='oid1', new_severity='5.5')
155
156
        self.connection.send.has_been_called_with(
157
            '<create_override>'
158
            '<text>foo</text>'
159
            '<nvt oid="oid1"/>'
160
            '<new_severity>5.5</new_severity>'
161
            '</create_override>'
162
        )
163
164
        self.gmp.create_override('foo', nvt_oid='oid1', new_severity=5.5)
165
166
        self.connection.send.has_been_called_with(
167
            '<create_override>'
168
            '<text>foo</text>'
169
            '<nvt oid="oid1"/>'
170
            '<new_severity>5.5</new_severity>'
171
            '</create_override>'
172
        )
173
174
        self.gmp.create_override(
175
            'foo',
176
            nvt_oid='oid1',
177
            new_severity=Decimal(5.5),
178
        )
179
180
        self.connection.send.has_been_called_with(
181
            '<create_override>'
182
            '<text>foo</text>'
183
            '<nvt oid="oid1"/>'
184
            '<new_severity>5.5</new_severity>'
185
            '</create_override>'
186
        )
187
188
    def test_create_override_with_threat(self):
189
        self.gmp.create_override('foo', nvt_oid='oid1', threat='High')
190
191
        self.connection.send.has_been_called_with(
192
            '<create_override>'
193
            '<text>foo</text>'
194
            '<nvt oid="oid1"/>'
195
            '<threat>High</threat>'
196
            '</create_override>'
197
        )
198
199
    def test_create_override_invalid_threat(self):
200
        with self.assertRaises(InvalidArgument):
201
            self.gmp.create_override(
202
                'foo',
203
                nvt_oid='oid1',
204
                threat='',
205
            )
206
207
        with self.assertRaises(InvalidArgument):
208
            self.gmp.create_override(
209
                'foo',
210
                nvt_oid='oid1',
211
                threat='foo',
212
            )
213
214
    def test_create_override_with_new_threat(self):
215
        self.gmp.create_override(
216
            'foo',
217
            nvt_oid='oid1',
218
            new_threat='High',
219
        )
220
221
        self.connection.send.has_been_called_with(
222
            '<create_override>'
223
            '<text>foo</text>'
224
            '<nvt oid="oid1"/>'
225
            '<new_threat>High</new_threat>'
226
            '</create_override>'
227
        )
228
229
    def test_create_override_invalid_new_threat(self):
230
        with self.assertRaises(InvalidArgument):
231
            self.gmp.create_override(
232
                'foo',
233
                nvt_oid='oid1',
234
                new_threat='',
235
            )
236
237
        with self.assertRaises(InvalidArgument):
238
            self.gmp.create_override(
239
                'foo',
240
                nvt_oid='oid1',
241
                new_threat='foo',
242
            )
243
244
    def test_create_override_with_seconds_active(self):
245
        self.gmp.create_override('foo', nvt_oid='oid1', seconds_active=0)
246
247
        self.connection.send.has_been_called_with(
248
            '<create_override>'
249
            '<text>foo</text>'
250
            '<nvt oid="oid1"/>'
251
            '<active>0</active>'
252
            '</create_override>'
253
        )
254
255
        self.gmp.create_override('foo', nvt_oid='oid1', seconds_active=-1)
256
257
        self.connection.send.has_been_called_with(
258
            '<create_override>'
259
            '<text>foo</text>'
260
            '<nvt oid="oid1"/>'
261
            '<active>-1</active>'
262
            '</create_override>'
263
        )
264
265
        self.gmp.create_override('foo', nvt_oid='oid1', seconds_active=3600)
266
267
        self.connection.send.has_been_called_with(
268
            '<create_override>'
269
            '<text>foo</text>'
270
            '<nvt oid="oid1"/>'
271
            '<active>3600</active>'
272
            '</create_override>'
273
        )
274
275
276
if __name__ == '__main__':
277
    unittest.main()
278