|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright (C) 2018 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 gvm.errors import RequiredArgument |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class GmpModifyPolicySetNvtPreferenceTestCase: |
|
25
|
|
|
def test_modify_config_set_nvt_pref(self): |
|
26
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
27
|
|
|
policy_id='c1', nvt_oid='o1', name='foo' |
|
28
|
|
|
) |
|
29
|
|
|
|
|
30
|
|
|
self.connection.send.has_been_called_with( |
|
31
|
|
|
'<modify_config config_id="c1">' |
|
32
|
|
|
'<preference>' |
|
33
|
|
|
'<nvt oid="o1"/>' |
|
34
|
|
|
'<name>foo</name>' |
|
35
|
|
|
'</preference>' |
|
36
|
|
|
'</modify_config>' |
|
37
|
|
|
) |
|
38
|
|
|
|
|
39
|
|
|
self.gmp.modify_policy_set_nvt_preference('c1', 'foo', 'o1') |
|
40
|
|
|
|
|
41
|
|
|
self.connection.send.has_been_called_with( |
|
42
|
|
|
'<modify_config config_id="c1">' |
|
43
|
|
|
'<preference>' |
|
44
|
|
|
'<nvt oid="o1"/>' |
|
45
|
|
|
'<name>foo</name>' |
|
46
|
|
|
'</preference>' |
|
47
|
|
|
'</modify_config>' |
|
48
|
|
|
) |
|
49
|
|
|
|
|
50
|
|
|
def test_modify_config_set_nvt_pref_with_value(self): |
|
51
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
52
|
|
|
'c1', 'foo', nvt_oid='o1', value='bar' |
|
53
|
|
|
) |
|
54
|
|
|
|
|
55
|
|
|
self.connection.send.has_been_called_with( |
|
56
|
|
|
'<modify_config config_id="c1">' |
|
57
|
|
|
'<preference>' |
|
58
|
|
|
'<nvt oid="o1"/>' |
|
59
|
|
|
'<name>foo</name>' |
|
60
|
|
|
'<value>YmFy</value>' |
|
61
|
|
|
'</preference>' |
|
62
|
|
|
'</modify_config>' |
|
63
|
|
|
) |
|
64
|
|
|
|
|
65
|
|
|
def test_modify_config_set_nvt_pref_missing_nvt_oid(self): |
|
66
|
|
|
with self.assertRaises(RequiredArgument): |
|
67
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
68
|
|
|
'c1', 'foo', nvt_oid=None, value='bar' |
|
69
|
|
|
) |
|
70
|
|
|
|
|
71
|
|
|
with self.assertRaises(RequiredArgument): |
|
72
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
73
|
|
|
'c1', 'foo', nvt_oid='', value='bar' |
|
74
|
|
|
) |
|
75
|
|
|
|
|
76
|
|
|
with self.assertRaises(RequiredArgument): |
|
77
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
78
|
|
|
'c1', 'foo', '', value='bar' |
|
79
|
|
|
) |
|
80
|
|
|
|
|
81
|
|
|
def test_modify_config_nvt_pref_missing_name(self): |
|
82
|
|
|
with self.assertRaises(RequiredArgument): |
|
83
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
84
|
|
|
'c1', name=None, nvt_oid='o1', value='bar' |
|
85
|
|
|
) |
|
86
|
|
|
|
|
87
|
|
|
with self.assertRaises(RequiredArgument): |
|
88
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
89
|
|
|
'c1', name='', nvt_oid='o1', value='bar' |
|
90
|
|
|
) |
|
91
|
|
|
|
|
92
|
|
|
with self.assertRaises(RequiredArgument): |
|
93
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
94
|
|
|
'c1', '', nvt_oid='o1', value='bar' |
|
95
|
|
|
) |
|
96
|
|
|
|
|
97
|
|
|
def test_modify_config_set_comment_missing_config_id(self): |
|
98
|
|
|
with self.assertRaises(RequiredArgument): |
|
99
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
100
|
|
|
policy_id=None, name='foo', nvt_oid='o1' |
|
101
|
|
|
) |
|
102
|
|
|
|
|
103
|
|
|
with self.assertRaises(RequiredArgument): |
|
104
|
|
|
self.gmp.modify_policy_set_nvt_preference('', 'foo', 'o1') |
|
105
|
|
|
|
|
106
|
|
|
with self.assertRaises(RequiredArgument): |
|
107
|
|
|
self.gmp.modify_policy_set_nvt_preference( |
|
108
|
|
|
policy_id='', name='foo', nvt_oid='o1' |
|
109
|
|
|
) |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
if __name__ == '__main__': |
|
113
|
|
|
unittest.main() |
|
114
|
|
|
|