Completed
Push — master ( 52721c...da306e )
by Jaspar
18s queued 14s
created

GmpModifyNoteTestMixin.test_modify_note_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 GmpModifyNoteTestMixin:
27
    def test_modify_note(self):
28
        self.gmp.modify_note(note_id='n1', text='foo')
29
30
        self.connection.send.has_been_called_with(
31
            '<modify_note note_id="n1">' '<text>foo</text>' '</modify_note>'
32
        )
33
34
    def test_modify_note_missing_note_id(self):
35
        with self.assertRaises(RequiredArgument):
36
            self.gmp.modify_note(note_id=None, text='foo')
37
38
        with self.assertRaises(RequiredArgument):
39
            self.gmp.modify_note(note_id='', text='foo')
40
41
        with self.assertRaises(RequiredArgument):
42
            self.gmp.modify_note('', text='foo')
43
44
    def test_modify_note_missing_text(self):
45
        with self.assertRaises(RequiredArgument):
46
            self.gmp.modify_note(note_id='n1', text='')
47
48
        with self.assertRaises(RequiredArgument):
49
            self.gmp.modify_note(note_id='n1', text=None)
50
51
        with self.assertRaises(RequiredArgument):
52
            self.gmp.modify_note('n1', '')
53
54
    def test_modify_note_with_days_active(self):
55
        self.gmp.modify_note(note_id='n1', text='foo', days_active=0)
56
57
        self.connection.send.has_been_called_with(
58
            '<modify_note note_id="n1">'
59
            '<text>foo</text>'
60
            '<active>0</active>'
61
            '</modify_note>'
62
        )
63
64
        self.gmp.modify_note(note_id='n1', text='foo', days_active=-1)
65
66
        self.connection.send.has_been_called_with(
67
            '<modify_note note_id="n1">'
68
            '<text>foo</text>'
69
            '<active>-1</active>'
70
            '</modify_note>'
71
        )
72
73
        self.gmp.modify_note(note_id='n1', text='foo', days_active=600)
74
75
        self.connection.send.has_been_called_with(
76
            '<modify_note note_id="n1">'
77
            '<text>foo</text>'
78
            '<active>600</active>'
79
            '</modify_note>'
80
        )
81
82
    def test_modify_note_with_port(self):
83
        self.gmp.modify_note(note_id='n1', text='foo', port='123')
84
85
        self.connection.send.has_been_called_with(
86
            '<modify_note note_id="n1">'
87
            '<text>foo</text>'
88
            '<port>123</port>'
89
            '</modify_note>'
90
        )
91
92
        self.gmp.modify_note(note_id='n1', text='foo', port=123)
93
94
        self.connection.send.has_been_called_with(
95
            '<modify_note note_id="n1">'
96
            '<text>foo</text>'
97
            '<port>123</port>'
98
            '</modify_note>'
99
        )
100
101
    def test_modify_note_with_hosts(self):
102
        self.gmp.modify_note(note_id='n1', text='foo', hosts=['foo'])
103
104
        self.connection.send.has_been_called_with(
105
            '<modify_note note_id="n1">'
106
            '<text>foo</text>'
107
            '<hosts>foo</hosts>'
108
            '</modify_note>'
109
        )
110
111
        self.gmp.modify_note(note_id='n1', text='foo', hosts=['foo', 'bar'])
112
113
        self.connection.send.has_been_called_with(
114
            '<modify_note note_id="n1">'
115
            '<text>foo</text>'
116
            '<hosts>foo,bar</hosts>'
117
            '</modify_note>'
118
        )
119
120
    def test_modify_note_with_result_id(self):
121
        self.gmp.modify_note(note_id='n1', text='foo', result_id='r1')
122
123
        self.connection.send.has_been_called_with(
124
            '<modify_note note_id="n1">'
125
            '<text>foo</text>'
126
            '<result id="r1"/>'
127
            '</modify_note>'
128
        )
129
130
    def test_modify_note_with_task_id(self):
131
        self.gmp.modify_note(note_id='n1', text='foo', task_id='r1')
132
133
        self.connection.send.has_been_called_with(
134
            '<modify_note note_id="n1">'
135
            '<text>foo</text>'
136
            '<task id="r1"/>'
137
            '</modify_note>'
138
        )
139
140
    def test_modify_note_with_severity(self):
141
        self.gmp.modify_note(note_id='n1', text='foo', severity='5.5')
142
143
        self.connection.send.has_been_called_with(
144
            '<modify_note note_id="n1">'
145
            '<text>foo</text>'
146
            '<severity>5.5</severity>'
147
            '</modify_note>'
148
        )
149
150
        self.gmp.modify_note(note_id='n1', text='foo', severity=5.5)
151
152
        self.connection.send.has_been_called_with(
153
            '<modify_note note_id="n1">'
154
            '<text>foo</text>'
155
            '<severity>5.5</severity>'
156
            '</modify_note>'
157
        )
158
159
        self.gmp.modify_note(note_id='n1', text='foo', severity=Decimal(5.5))
160
161
        self.connection.send.has_been_called_with(
162
            '<modify_note note_id="n1">'
163
            '<text>foo</text>'
164
            '<severity>5.5</severity>'
165
            '</modify_note>'
166
        )
167
168
    def test_modify_note_with_threat(self):
169
        self.gmp.modify_note(
170
            note_id='n1', text='foo', threat=SeverityLevel.HIGH
171
        )
172
173
        self.connection.send.has_been_called_with(
174
            '<modify_note note_id="n1">'
175
            '<text>foo</text>'
176
            '<threat>High</threat>'
177
            '</modify_note>'
178
        )
179
180
    def test_modify_note_invalid_threat(self):
181
        with self.assertRaises(InvalidArgumentType):
182
            self.gmp.modify_note(note_id='n1', text='foo', threat='')
183
184
        with self.assertRaises(InvalidArgumentType):
185
            self.gmp.modify_note(note_id='n1', text='foo', threat='foo')
186