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 GmpModifyPolicySetScannerPreferenceTestCase: |
25
|
|
|
def test_modify_config_set_scanner_pref(self): |
26
|
|
|
self.gmp.modify_policy_set_scanner_preference( |
27
|
|
|
policy_id='c1', name='foo' |
28
|
|
|
) |
29
|
|
|
|
30
|
|
|
self.connection.send.has_been_called_with( |
31
|
|
|
'<modify_config config_id="c1">' |
32
|
|
|
'<preference>' |
33
|
|
|
'<name>foo</name>' |
34
|
|
|
'</preference>' |
35
|
|
|
'</modify_config>' |
36
|
|
|
) |
37
|
|
|
|
38
|
|
|
self.gmp.modify_policy_set_scanner_preference('c1', 'foo') |
39
|
|
|
|
40
|
|
|
self.connection.send.has_been_called_with( |
41
|
|
|
'<modify_config config_id="c1">' |
42
|
|
|
'<preference>' |
43
|
|
|
'<name>foo</name>' |
44
|
|
|
'</preference>' |
45
|
|
|
'</modify_config>' |
46
|
|
|
) |
47
|
|
|
|
48
|
|
|
def test_modify_config_set_scanner_pref_with_value(self): |
49
|
|
|
self.gmp.modify_policy_set_scanner_preference('c1', 'foo', value='bar') |
50
|
|
|
|
51
|
|
|
self.connection.send.has_been_called_with( |
52
|
|
|
'<modify_config config_id="c1">' |
53
|
|
|
'<preference>' |
54
|
|
|
'<name>foo</name>' |
55
|
|
|
'<value>YmFy</value>' |
56
|
|
|
'</preference>' |
57
|
|
|
'</modify_config>' |
58
|
|
|
) |
59
|
|
|
|
60
|
|
|
def test_modify_config_scanner_pref_missing_name(self): |
61
|
|
|
with self.assertRaises(RequiredArgument): |
62
|
|
|
self.gmp.modify_policy_set_scanner_preference( |
63
|
|
|
'c1', name=None, value='bar' |
64
|
|
|
) |
65
|
|
|
|
66
|
|
|
with self.assertRaises(RequiredArgument): |
67
|
|
|
self.gmp.modify_policy_set_scanner_preference( |
68
|
|
|
'c1', name='', value='bar' |
69
|
|
|
) |
70
|
|
|
|
71
|
|
|
with self.assertRaises(RequiredArgument): |
72
|
|
|
self.gmp.modify_policy_set_scanner_preference('c1', '', value='bar') |
73
|
|
|
|
74
|
|
|
def test_modify_config_set_comment_missing_config_id(self): |
75
|
|
|
with self.assertRaises(RequiredArgument): |
76
|
|
|
self.gmp.modify_policy_set_scanner_preference( |
77
|
|
|
policy_id=None, name='foo' |
78
|
|
|
) |
79
|
|
|
|
80
|
|
|
with self.assertRaises(RequiredArgument): |
81
|
|
|
self.gmp.modify_policy_set_scanner_preference('', 'foo') |
82
|
|
|
|
83
|
|
|
with self.assertRaises(RequiredArgument): |
84
|
|
|
self.gmp.modify_policy_set_scanner_preference( |
85
|
|
|
policy_id='', name='foo' |
86
|
|
|
) |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
if __name__ == '__main__': |
90
|
|
|
unittest.main() |
91
|
|
|
|