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, InvalidArgumentType |
22
|
|
|
from gvm.protocols.gmpv9 import ScannerType |
23
|
|
|
|
24
|
|
|
|
25
|
|
View Code Duplication |
class GmpModifyScannerTestCase: |
|
|
|
|
26
|
|
|
def test_modify_scanner(self): |
27
|
|
|
self.gmp.modify_scanner(scanner_id='s1') |
28
|
|
|
|
29
|
|
|
self.connection.send.has_been_called_with( |
30
|
|
|
'<modify_scanner scanner_id="s1"/>' |
31
|
|
|
) |
32
|
|
|
|
33
|
|
|
def test_modify_scanner_missing_scanner_id(self): |
34
|
|
|
with self.assertRaises(RequiredArgument): |
35
|
|
|
self.gmp.modify_scanner(scanner_id=None) |
36
|
|
|
|
37
|
|
|
with self.assertRaises(RequiredArgument): |
38
|
|
|
self.gmp.modify_scanner(scanner_id='') |
39
|
|
|
|
40
|
|
|
def test_modify_scanner_with_comment(self): |
41
|
|
|
self.gmp.modify_scanner(scanner_id='s1', comment='foo') |
42
|
|
|
|
43
|
|
|
self.connection.send.has_been_called_with( |
44
|
|
|
'<modify_scanner scanner_id="s1">' |
45
|
|
|
'<comment>foo</comment>' |
46
|
|
|
'</modify_scanner>' |
47
|
|
|
) |
48
|
|
|
|
49
|
|
|
def test_modify_scanner_with_host(self): |
50
|
|
|
self.gmp.modify_scanner(scanner_id='s1', host='foo') |
51
|
|
|
|
52
|
|
|
self.connection.send.has_been_called_with( |
53
|
|
|
'<modify_scanner scanner_id="s1">' |
54
|
|
|
'<host>foo</host>' |
55
|
|
|
'</modify_scanner>' |
56
|
|
|
) |
57
|
|
|
|
58
|
|
|
def test_modify_scanner_with_port(self): |
59
|
|
|
self.gmp.modify_scanner(scanner_id='s1', port=1234) |
60
|
|
|
|
61
|
|
|
self.connection.send.has_been_called_with( |
62
|
|
|
'<modify_scanner scanner_id="s1">' |
63
|
|
|
'<port>1234</port>' |
64
|
|
|
'</modify_scanner>' |
65
|
|
|
) |
66
|
|
|
|
67
|
|
|
self.gmp.modify_scanner(scanner_id='s1', port='1234') |
68
|
|
|
|
69
|
|
|
self.connection.send.has_been_called_with( |
70
|
|
|
'<modify_scanner scanner_id="s1">' |
71
|
|
|
'<port>1234</port>' |
72
|
|
|
'</modify_scanner>' |
73
|
|
|
) |
74
|
|
|
|
75
|
|
|
def test_modify_scanner_with_name(self): |
76
|
|
|
self.gmp.modify_scanner(scanner_id='s1', name='foo') |
77
|
|
|
|
78
|
|
|
self.connection.send.has_been_called_with( |
79
|
|
|
'<modify_scanner scanner_id="s1">' |
80
|
|
|
'<name>foo</name>' |
81
|
|
|
'</modify_scanner>' |
82
|
|
|
) |
83
|
|
|
|
84
|
|
|
def test_modify_scanner_with_ca_pub(self): |
85
|
|
|
self.gmp.modify_scanner(scanner_id='s1', ca_pub='foo') |
86
|
|
|
|
87
|
|
|
self.connection.send.has_been_called_with( |
88
|
|
|
'<modify_scanner scanner_id="s1">' |
89
|
|
|
'<ca_pub>foo</ca_pub>' |
90
|
|
|
'</modify_scanner>' |
91
|
|
|
) |
92
|
|
|
|
93
|
|
|
def test_modify_scanner_with_credential_id(self): |
94
|
|
|
self.gmp.modify_scanner(scanner_id='s1', credential_id='c1') |
95
|
|
|
|
96
|
|
|
self.connection.send.has_been_called_with( |
97
|
|
|
'<modify_scanner scanner_id="s1">' |
98
|
|
|
'<credential id="c1"/>' |
99
|
|
|
'</modify_scanner>' |
100
|
|
|
) |
101
|
|
|
|
102
|
|
|
def test_modify_scanner_with_scanner_type(self): |
103
|
|
|
self.gmp.modify_scanner( |
104
|
|
|
scanner_id='s1', scanner_type=ScannerType.OSP_SCANNER_TYPE |
105
|
|
|
) |
106
|
|
|
|
107
|
|
|
self.connection.send.has_been_called_with( |
108
|
|
|
'<modify_scanner scanner_id="s1">' |
109
|
|
|
'<type>1</type>' |
110
|
|
|
'</modify_scanner>' |
111
|
|
|
) |
112
|
|
|
|
113
|
|
|
self.gmp.modify_scanner( |
114
|
|
|
scanner_id='s1', scanner_type=ScannerType.OPENVAS_SCANNER_TYPE |
115
|
|
|
) |
116
|
|
|
|
117
|
|
|
self.connection.send.has_been_called_with( |
118
|
|
|
'<modify_scanner scanner_id="s1">' |
119
|
|
|
'<type>2</type>' |
120
|
|
|
'</modify_scanner>' |
121
|
|
|
) |
122
|
|
|
|
123
|
|
|
self.gmp.modify_scanner( |
124
|
|
|
scanner_id='s1', scanner_type=ScannerType.CVE_SCANNER_TYPE |
125
|
|
|
) |
126
|
|
|
|
127
|
|
|
self.connection.send.has_been_called_with( |
128
|
|
|
'<modify_scanner scanner_id="s1">' |
129
|
|
|
'<type>3</type>' |
130
|
|
|
'</modify_scanner>' |
131
|
|
|
) |
132
|
|
|
|
133
|
|
|
self.gmp.modify_scanner( |
134
|
|
|
scanner_id='s1', scanner_type=ScannerType.GMP_SCANNER_TYPE |
135
|
|
|
) |
136
|
|
|
|
137
|
|
|
self.connection.send.has_been_called_with( |
138
|
|
|
'<modify_scanner scanner_id="s1">' |
139
|
|
|
'<type>4</type>' |
140
|
|
|
'</modify_scanner>' |
141
|
|
|
) |
142
|
|
|
|
143
|
|
|
def test_modify_scanner_invalid_scanner_type(self): |
144
|
|
|
with self.assertRaises(InvalidArgumentType): |
145
|
|
|
self.gmp.modify_scanner(scanner_id='s1', scanner_type='') |
146
|
|
|
|
147
|
|
|
with self.assertRaises(InvalidArgumentType): |
148
|
|
|
self.gmp.modify_scanner(scanner_id='s1', scanner_type='-1') |
149
|
|
|
|
150
|
|
|
with self.assertRaises(InvalidArgumentType): |
151
|
|
|
self.gmp.modify_scanner(scanner_id='s1', scanner_type=1) |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
if __name__ == '__main__': |
155
|
|
|
unittest.main() |
156
|
|
|
|