Passed
Pull Request — master (#326)
by Jaspar
02:08
created

GmpModifyOverrideTestCase.test_modify_override_with_hosts()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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