1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2020-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 |
22
|
|
|
|
23
|
|
|
from gvm.protocols.gmpv214 import SeverityLevel |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class GmpCreateNoteTestMixin: |
27
|
|
|
def test_create_note(self): |
28
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1') |
29
|
|
|
|
30
|
|
|
self.connection.send.has_been_called_with( |
31
|
|
|
'<create_note>' |
32
|
|
|
'<text>foo</text>' |
33
|
|
|
'<nvt oid="oid1"/>' |
34
|
|
|
'</create_note>' |
35
|
|
|
) |
36
|
|
|
|
37
|
|
|
def test_create_note_missing_text(self): |
38
|
|
|
with self.assertRaises(RequiredArgument): |
39
|
|
|
self.gmp.create_note(None, 'od1') |
40
|
|
|
|
41
|
|
|
with self.assertRaises(RequiredArgument): |
42
|
|
|
self.gmp.create_note('', 'oid1') |
43
|
|
|
|
44
|
|
|
def test_create_note_missing_nvt_oid(self): |
45
|
|
|
with self.assertRaises(RequiredArgument): |
46
|
|
|
self.gmp.create_note('foo', None) |
47
|
|
|
|
48
|
|
|
with self.assertRaises(RequiredArgument): |
49
|
|
|
self.gmp.create_note('foo', '') |
50
|
|
|
|
51
|
|
|
def test_create_note_with_hosts(self): |
52
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', hosts=[]) |
53
|
|
|
|
54
|
|
|
self.connection.send.has_been_called_with( |
55
|
|
|
'<create_note>' |
56
|
|
|
'<text>foo</text>' |
57
|
|
|
'<nvt oid="oid1"/>' |
58
|
|
|
'</create_note>' |
59
|
|
|
) |
60
|
|
|
|
61
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', hosts=['h1', 'h2']) |
62
|
|
|
|
63
|
|
|
self.connection.send.has_been_called_with( |
64
|
|
|
'<create_note>' |
65
|
|
|
'<text>foo</text>' |
66
|
|
|
'<nvt oid="oid1"/>' |
67
|
|
|
'<hosts>h1,h2</hosts>' |
68
|
|
|
'</create_note>' |
69
|
|
|
) |
70
|
|
|
|
71
|
|
|
def test_create_note_with_port(self): |
72
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', port='666') |
73
|
|
|
|
74
|
|
|
self.connection.send.has_been_called_with( |
75
|
|
|
'<create_note>' |
76
|
|
|
'<text>foo</text>' |
77
|
|
|
'<nvt oid="oid1"/>' |
78
|
|
|
'<port>666</port>' |
79
|
|
|
'</create_note>' |
80
|
|
|
) |
81
|
|
|
|
82
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', port=666) |
83
|
|
|
|
84
|
|
|
self.connection.send.has_been_called_with( |
85
|
|
|
'<create_note>' |
86
|
|
|
'<text>foo</text>' |
87
|
|
|
'<nvt oid="oid1"/>' |
88
|
|
|
'<port>666</port>' |
89
|
|
|
'</create_note>' |
90
|
|
|
) |
91
|
|
|
|
92
|
|
|
def test_create_note_with_result_id(self): |
93
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', result_id='r1') |
94
|
|
|
|
95
|
|
|
self.connection.send.has_been_called_with( |
96
|
|
|
'<create_note>' |
97
|
|
|
'<text>foo</text>' |
98
|
|
|
'<nvt oid="oid1"/>' |
99
|
|
|
'<result id="r1"/>' |
100
|
|
|
'</create_note>' |
101
|
|
|
) |
102
|
|
|
|
103
|
|
|
def test_create_note_with_task_id(self): |
104
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', task_id='t1') |
105
|
|
|
|
106
|
|
|
self.connection.send.has_been_called_with( |
107
|
|
|
'<create_note>' |
108
|
|
|
'<text>foo</text>' |
109
|
|
|
'<nvt oid="oid1"/>' |
110
|
|
|
'<task id="t1"/>' |
111
|
|
|
'</create_note>' |
112
|
|
|
) |
113
|
|
|
|
114
|
|
|
def test_create_note_with_severity(self): |
115
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', severity='5.5') |
116
|
|
|
|
117
|
|
|
self.connection.send.has_been_called_with( |
118
|
|
|
'<create_note>' |
119
|
|
|
'<text>foo</text>' |
120
|
|
|
'<nvt oid="oid1"/>' |
121
|
|
|
'<severity>5.5</severity>' |
122
|
|
|
'</create_note>' |
123
|
|
|
) |
124
|
|
|
|
125
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', severity=5.5) |
126
|
|
|
|
127
|
|
|
self.connection.send.has_been_called_with( |
128
|
|
|
'<create_note>' |
129
|
|
|
'<text>foo</text>' |
130
|
|
|
'<nvt oid="oid1"/>' |
131
|
|
|
'<severity>5.5</severity>' |
132
|
|
|
'</create_note>' |
133
|
|
|
) |
134
|
|
|
|
135
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', severity=Decimal(5.5)) |
136
|
|
|
|
137
|
|
|
self.connection.send.has_been_called_with( |
138
|
|
|
'<create_note>' |
139
|
|
|
'<text>foo</text>' |
140
|
|
|
'<nvt oid="oid1"/>' |
141
|
|
|
'<severity>5.5</severity>' |
142
|
|
|
'</create_note>' |
143
|
|
|
) |
144
|
|
|
|
145
|
|
|
def test_create_note_with_threat(self): |
146
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', threat=SeverityLevel.HIGH) |
147
|
|
|
|
148
|
|
|
self.connection.send.has_been_called_with( |
149
|
|
|
'<create_note>' |
150
|
|
|
'<text>foo</text>' |
151
|
|
|
'<nvt oid="oid1"/>' |
152
|
|
|
'</create_note>' |
153
|
|
|
) |
154
|
|
|
|
155
|
|
|
def test_create_note_with_days_active(self): |
156
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', days_active=0) |
157
|
|
|
|
158
|
|
|
self.connection.send.has_been_called_with( |
159
|
|
|
'<create_note>' |
160
|
|
|
'<text>foo</text>' |
161
|
|
|
'<nvt oid="oid1"/>' |
162
|
|
|
'<active>0</active>' |
163
|
|
|
'</create_note>' |
164
|
|
|
) |
165
|
|
|
|
166
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', days_active=-1) |
167
|
|
|
|
168
|
|
|
self.connection.send.has_been_called_with( |
169
|
|
|
'<create_note>' |
170
|
|
|
'<text>foo</text>' |
171
|
|
|
'<nvt oid="oid1"/>' |
172
|
|
|
'<active>-1</active>' |
173
|
|
|
'</create_note>' |
174
|
|
|
) |
175
|
|
|
|
176
|
|
|
self.gmp.create_note('foo', nvt_oid='oid1', days_active=3600) |
177
|
|
|
|
178
|
|
|
self.connection.send.has_been_called_with( |
179
|
|
|
'<create_note>' |
180
|
|
|
'<text>foo</text>' |
181
|
|
|
'<nvt oid="oid1"/>' |
182
|
|
|
'<active>3600</active>' |
183
|
|
|
'</create_note>' |
184
|
|
|
) |
185
|
|
|
|