Passed
Pull Request — master (#457)
by Jaspar
02:22
created

GmpModifyOverrideTestMixin.test_modify_override_with_threat()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2018-2021 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
from decimal import Decimal
20
21
from gvm.errors import RequiredArgument, InvalidArgumentType
22
23
from gvm.protocols.gmpv208 import SeverityLevel
24
25
26
class GmpModifyOverrideTestMixin:
27
    def test_modify_override(self):
28
        self.gmp.modify_override(override_id='o1', text='foo')
29
30
        self.connection.send.has_been_called_with(
31
            '<modify_override override_id="o1">'
32
            '<text>foo</text>'
33
            '</modify_override>'
34
        )
35
36
    def test_modify_override_missing_override_id(self):
37
        with self.assertRaises(RequiredArgument):
38
            self.gmp.modify_override(override_id=None, text='foo')
39
40
        with self.assertRaises(RequiredArgument):
41
            self.gmp.modify_override(override_id='', text='foo')
42
43
        with self.assertRaises(RequiredArgument):
44
            self.gmp.modify_override('', text='foo')
45
46
    def test_modify_override_missing_text(self):
47
        with self.assertRaises(RequiredArgument):
48
            self.gmp.modify_override(override_id='o1', text='')
49
50
        with self.assertRaises(RequiredArgument):
51
            self.gmp.modify_override(override_id='o1', text=None)
52
53
        with self.assertRaises(RequiredArgument):
54
            self.gmp.modify_override('o1', '')
55
56
    def test_modify_override_with_days_active(self):
57
        self.gmp.modify_override(override_id='o1', text='foo', days_active=0)
58
59
        self.connection.send.has_been_called_with(
60
            '<modify_override override_id="o1">'
61
            '<text>foo</text>'
62
            '<active>0</active>'
63
            '</modify_override>'
64
        )
65
66
        self.gmp.modify_override(override_id='o1', text='foo', days_active=-1)
67
68
        self.connection.send.has_been_called_with(
69
            '<modify_override override_id="o1">'
70
            '<text>foo</text>'
71
            '<active>-1</active>'
72
            '</modify_override>'
73
        )
74
75
        self.gmp.modify_override(override_id='o1', text='foo', days_active=600)
76
77
        self.connection.send.has_been_called_with(
78
            '<modify_override override_id="o1">'
79
            '<text>foo</text>'
80
            '<active>600</active>'
81
            '</modify_override>'
82
        )
83
84
    def test_modify_override_with_port(self):
85
        self.gmp.modify_override(override_id='o1', text='foo', port='123')
86
87
        self.connection.send.has_been_called_with(
88
            '<modify_override override_id="o1">'
89
            '<text>foo</text>'
90
            '<port>123</port>'
91
            '</modify_override>'
92
        )
93
94
        self.gmp.modify_override(override_id='o1', text='foo', port=123)
95
96
        self.connection.send.has_been_called_with(
97
            '<modify_override override_id="o1">'
98
            '<text>foo</text>'
99
            '<port>123</port>'
100
            '</modify_override>'
101
        )
102
103
    def test_modify_override_with_hosts(self):
104
        self.gmp.modify_override(override_id='o1', text='foo', hosts=['foo'])
105
106
        self.connection.send.has_been_called_with(
107
            '<modify_override override_id="o1">'
108
            '<text>foo</text>'
109
            '<hosts>foo</hosts>'
110
            '</modify_override>'
111
        )
112
113
        self.gmp.modify_override(
114
            override_id='o1', text='foo', hosts=['foo', 'bar']
115
        )
116
117
        self.connection.send.has_been_called_with(
118
            '<modify_override override_id="o1">'
119
            '<text>foo</text>'
120
            '<hosts>foo,bar</hosts>'
121
            '</modify_override>'
122
        )
123
124
    def test_modify_override_with_result_id(self):
125
        self.gmp.modify_override(override_id='o1', text='foo', result_id='r1')
126
127
        self.connection.send.has_been_called_with(
128
            '<modify_override override_id="o1">'
129
            '<text>foo</text>'
130
            '<result id="r1"/>'
131
            '</modify_override>'
132
        )
133
134
    def test_modify_override_with_task_id(self):
135
        self.gmp.modify_override(override_id='o1', text='foo', task_id='r1')
136
137
        self.connection.send.has_been_called_with(
138
            '<modify_override override_id="o1">'
139
            '<text>foo</text>'
140
            '<task id="r1"/>'
141
            '</modify_override>'
142
        )
143
144
    def test_modify_override_with_severity(self):
145
        self.gmp.modify_override(override_id='o1', text='foo', severity='5.5')
146
147
        self.connection.send.has_been_called_with(
148
            '<modify_override override_id="o1">'
149
            '<text>foo</text>'
150
            '<severity>5.5</severity>'
151
            '</modify_override>'
152
        )
153
154
        self.gmp.modify_override(override_id='o1', text='foo', severity=5.5)
155
156
        self.connection.send.has_been_called_with(
157
            '<modify_override override_id="o1">'
158
            '<text>foo</text>'
159
            '<severity>5.5</severity>'
160
            '</modify_override>'
161
        )
162
163
        self.gmp.modify_override(
164
            override_id='o1', text='foo', severity=Decimal(5.5)
165
        )
166
167
        self.connection.send.has_been_called_with(
168
            '<modify_override override_id="o1">'
169
            '<text>foo</text>'
170
            '<severity>5.5</severity>'
171
            '</modify_override>'
172
        )
173
174
    def test_modify_override_with_new_severity(self):
175
        self.gmp.modify_override(
176
            override_id='o1', text='foo', new_severity='5.5'
177
        )
178
179
        self.connection.send.has_been_called_with(
180
            '<modify_override override_id="o1">'
181
            '<text>foo</text>'
182
            '<new_severity>5.5</new_severity>'
183
            '</modify_override>'
184
        )
185
186
        self.gmp.modify_override(override_id='o1', text='foo', new_severity=5.5)
187
188
        self.connection.send.has_been_called_with(
189
            '<modify_override override_id="o1">'
190
            '<text>foo</text>'
191
            '<new_severity>5.5</new_severity>'
192
            '</modify_override>'
193
        )
194
195
        self.gmp.modify_override(
196
            override_id='o1', text='foo', new_severity=Decimal(5.5)
197
        )
198
199
        self.connection.send.has_been_called_with(
200
            '<modify_override override_id="o1">'
201
            '<text>foo</text>'
202
            '<new_severity>5.5</new_severity>'
203
            '</modify_override>'
204
        )
205
206
    def test_modify_override_with_threat(self):
207
        self.gmp.modify_override(
208
            override_id='o1', text='foo', threat=SeverityLevel.HIGH
209
        )
210
211
        self.connection.send.has_been_called_with(
212
            '<modify_override override_id="o1">'
213
            '<text>foo</text>'
214
            '<threat>High</threat>'
215
            '</modify_override>'
216
        )
217
218
    def test_modify_override_invalid_threat(self):
219
        with self.assertRaises(InvalidArgumentType):
220
            self.gmp.modify_override(override_id='o1', text='foo', threat='')
221
222
        with self.assertRaises(InvalidArgumentType):
223
            self.gmp.modify_override(override_id='o1', text='foo', threat='foo')
224
225
    def test_modify_override_with_new_threat(self):
226
        self.gmp.modify_override(
227
            override_id='o1', text='foo', new_threat=SeverityLevel.HIGH
228
        )
229
230
        self.connection.send.has_been_called_with(
231
            '<modify_override override_id="o1">'
232
            '<text>foo</text>'
233
            '<new_threat>High</new_threat>'
234
            '</modify_override>'
235
        )
236
237
    def test_modify_override_invalid_new_threat(self):
238
        with self.assertRaises(InvalidArgumentType):
239
            self.gmp.modify_override(
240
                override_id='o1', text='foo', new_threat=''
241
            )
242
243
        with self.assertRaises(InvalidArgumentType):
244
            self.gmp.modify_override(
245
                override_id='o1', text='foo', new_threat='foo'
246
            )
247