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
|
|
|
import warnings |
19
|
|
|
|
20
|
|
|
from gvm.errors import RequiredArgument, InvalidArgument |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class GmpModifyScanConfigTestMixin: |
24
|
|
|
def test_modify_scan_config_invalid_selection(self): |
25
|
|
|
with self.assertRaises(InvalidArgument): |
26
|
|
|
self.gmp.modify_scan_config(config_id='c1', selection='foo') |
27
|
|
|
|
28
|
|
|
with self.assertRaises(InvalidArgument): |
29
|
|
|
self.gmp.modify_scan_config(config_id='c1', selection='') |
30
|
|
|
|
31
|
|
|
def test_modify_scan_config_missing_config_id(self): |
32
|
|
|
with self.assertRaises(RequiredArgument): |
33
|
|
|
self.gmp.modify_scan_config(config_id=None, selection='nvt_pref') |
34
|
|
|
|
35
|
|
|
with self.assertRaises(RequiredArgument): |
36
|
|
|
self.gmp.modify_scan_config(config_id='', selection='nvt_pref') |
37
|
|
|
|
38
|
|
|
with self.assertRaises(RequiredArgument): |
39
|
|
|
self.gmp.modify_scan_config('', selection='nvt_pref') |
40
|
|
|
|
41
|
|
|
def test_modify_scan_config_set_comment(self): |
42
|
|
|
# pylint: disable=invalid-name |
43
|
|
|
with warnings.catch_warnings(record=True) as w: |
44
|
|
|
warnings.simplefilter("always") |
45
|
|
|
|
46
|
|
|
self.gmp.modify_scan_config( |
47
|
|
|
config_id='c1', selection=None, comment='foo' |
48
|
|
|
) |
49
|
|
|
|
50
|
|
|
self.assertEqual(len(w), 1) |
51
|
|
|
self.assertTrue(issubclass(w[0].category, DeprecationWarning)) |
52
|
|
|
|
53
|
|
|
self.connection.send.has_been_called_with( |
54
|
|
|
'<modify_config config_id="c1">' |
55
|
|
|
'<comment>foo</comment>' |
56
|
|
|
'</modify_config>' |
57
|
|
|
) |
58
|
|
|
|
59
|
|
|
def test_modify_scan_config_set_nvt_pref(self): |
60
|
|
|
# pylint: disable=invalid-name |
61
|
|
|
with warnings.catch_warnings(record=True) as w: |
62
|
|
|
warnings.simplefilter("always") |
63
|
|
|
|
64
|
|
|
self.gmp.modify_scan_config( |
65
|
|
|
config_id='c1', selection='nvt_pref', nvt_oid='o1', name='foo' |
66
|
|
|
) |
67
|
|
|
|
68
|
|
|
self.assertEqual(len(w), 1) |
69
|
|
|
self.assertTrue(issubclass(w[0].category, DeprecationWarning)) |
70
|
|
|
|
71
|
|
|
self.connection.send.has_been_called_with( |
72
|
|
|
'<modify_config config_id="c1">' |
73
|
|
|
'<preference>' |
74
|
|
|
'<nvt oid="o1"/>' |
75
|
|
|
'<name>foo</name>' |
76
|
|
|
'</preference>' |
77
|
|
|
'</modify_config>' |
78
|
|
|
) |
79
|
|
|
|
80
|
|
|
def test_modify_scan_config_set_scanner_pref(self): |
81
|
|
|
# pylint: disable=invalid-name |
82
|
|
|
with warnings.catch_warnings(record=True) as w: |
83
|
|
|
warnings.simplefilter("always") |
84
|
|
|
|
85
|
|
|
self.gmp.modify_scan_config( |
86
|
|
|
config_id='c1', selection='scan_pref', name='foo', value='bar' |
87
|
|
|
) |
88
|
|
|
|
89
|
|
|
self.assertEqual(len(w), 1) |
90
|
|
|
self.assertTrue(issubclass(w[0].category, DeprecationWarning)) |
91
|
|
|
|
92
|
|
|
self.connection.send.has_been_called_with( |
93
|
|
|
'<modify_config config_id="c1">' |
94
|
|
|
'<preference>' |
95
|
|
|
'<name>foo</name>' |
96
|
|
|
'<value>YmFy</value>' |
97
|
|
|
'</preference>' |
98
|
|
|
'</modify_config>' |
99
|
|
|
) |
100
|
|
|
|
101
|
|
|
def test_modify_scan_config_set_nvt_selection(self): |
102
|
|
|
# pylint: disable=invalid-name |
103
|
|
|
with warnings.catch_warnings(record=True) as w: |
104
|
|
|
warnings.simplefilter("always") |
105
|
|
|
|
106
|
|
|
self.gmp.modify_scan_config( |
107
|
|
|
config_id='c1', |
108
|
|
|
selection='nvt_selection', |
109
|
|
|
nvt_oids=['o1'], |
110
|
|
|
family='foo', |
111
|
|
|
) |
112
|
|
|
|
113
|
|
|
self.assertEqual(len(w), 1) |
114
|
|
|
self.assertTrue(issubclass(w[0].category, DeprecationWarning)) |
115
|
|
|
|
116
|
|
|
self.connection.send.has_been_called_with( |
117
|
|
|
'<modify_config config_id="c1">' |
118
|
|
|
'<nvt_selection>' |
119
|
|
|
'<family>foo</family>' |
120
|
|
|
'<nvt oid="o1"/>' |
121
|
|
|
'</nvt_selection>' |
122
|
|
|
'</modify_config>' |
123
|
|
|
) |
124
|
|
|
|
125
|
|
|
def test_modify_scan_config_set_family_selection(self): |
126
|
|
|
# pylint: disable=invalid-name |
127
|
|
|
with warnings.catch_warnings(record=True) as w: |
128
|
|
|
warnings.simplefilter("always") |
129
|
|
|
|
130
|
|
|
self.gmp.modify_scan_config( |
131
|
|
|
config_id='c1', |
132
|
|
|
selection='family_selection', |
133
|
|
|
families=[('foo', True, True)], |
134
|
|
|
) |
135
|
|
|
|
136
|
|
|
self.assertEqual(len(w), 1) |
137
|
|
|
self.assertTrue(issubclass(w[0].category, DeprecationWarning)) |
138
|
|
|
|
139
|
|
|
self.connection.send.has_been_called_with( |
140
|
|
|
'<modify_config config_id="c1">' |
141
|
|
|
'<family_selection>' |
142
|
|
|
'<growing>1</growing>' |
143
|
|
|
'<family>' |
144
|
|
|
'<name>foo</name>' |
145
|
|
|
'<all>1</all>' |
146
|
|
|
'<growing>1</growing>' |
147
|
|
|
'</family>' |
148
|
|
|
'</family_selection>' |
149
|
|
|
'</modify_config>' |
150
|
|
|
) |
151
|
|
|
|