Passed
Pull Request — master (#88)
by
unknown
01:53
created

GmpModifyScannerTestCase.setUp()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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, InvalidArgument
22
from gvm.protocols.gmpv7 import (Gmp, OSP_SCANNER_TYPE, OPENVAS_SCANNER_TYPE,
23
                                 CVE_SCANNER_TYPE, GMP_SCANNER_TYPE)
24
25
from .. import MockConnection
26
27
28
class GmpModifyScannerTestCase(unittest.TestCase):
29
30
    def setUp(self):
31
        self.connection = MockConnection()
32
        self.gmp = Gmp(self.connection)
33
34
    def test_modify_scanner(self):
35
        self.gmp.modify_scanner(
36
            scanner_id='s1',
37
        )
38
39
        self.connection.send.has_been_called_with(
40
            '<modify_scanner scanner_id="s1"/>'
41
        )
42
43
    def test_modify_scanner_missing_scanner_id(self):
44
        with self.assertRaises(RequiredArgument):
45
            self.gmp.modify_scanner(
46
                scanner_id=None,
47
            )
48
49
        with self.assertRaises(RequiredArgument):
50
            self.gmp.modify_scanner(
51
                scanner_id='',
52
            )
53
54
    def test_modify_scanner_with_comment(self):
55
        self.gmp.modify_scanner(
56
            scanner_id='s1',
57
            comment='foo',
58
        )
59
60
        self.connection.send.has_been_called_with(
61
            '<modify_scanner scanner_id="s1">'
62
            '<comment>foo</comment>'
63
            '</modify_scanner>'
64
        )
65
66
    def test_modify_scanner_with_host(self):
67
        self.gmp.modify_scanner(
68
            scanner_id='s1',
69
            host='foo',
70
        )
71
72
        self.connection.send.has_been_called_with(
73
            '<modify_scanner scanner_id="s1">'
74
            '<host>foo</host>'
75
            '</modify_scanner>'
76
        )
77
78
    def test_modify_scanner_with_port(self):
79
        self.gmp.modify_scanner(
80
            scanner_id='s1',
81
            port=1234,
82
        )
83
84
        self.connection.send.has_been_called_with(
85
            '<modify_scanner scanner_id="s1">'
86
            '<port>1234</port>'
87
            '</modify_scanner>'
88
        )
89
90
        self.gmp.modify_scanner(
91
            scanner_id='s1',
92
            port='1234',
93
        )
94
95
        self.connection.send.has_been_called_with(
96
            '<modify_scanner scanner_id="s1">'
97
            '<port>1234</port>'
98
            '</modify_scanner>'
99
        )
100
101
    def test_modify_scanner_with_name(self):
102
        self.gmp.modify_scanner(
103
            scanner_id='s1',
104
            name='foo',
105
        )
106
107
        self.connection.send.has_been_called_with(
108
            '<modify_scanner scanner_id="s1">'
109
            '<name>foo</name>'
110
            '</modify_scanner>'
111
        )
112
113
    def test_modify_scanner_with_ca_pub(self):
114
        self.gmp.modify_scanner(
115
            scanner_id='s1',
116
            ca_pub='foo',
117
        )
118
119
        self.connection.send.has_been_called_with(
120
            '<modify_scanner scanner_id="s1">'
121
            '<ca_pub>foo</ca_pub>'
122
            '</modify_scanner>'
123
        )
124
125
    def test_modify_scanner_with_credential_id(self):
126
        self.gmp.modify_scanner(
127
            scanner_id='s1',
128
            credential_id='c1',
129
        )
130
131
        self.connection.send.has_been_called_with(
132
            '<modify_scanner scanner_id="s1">'
133
            '<credential id="c1"/>'
134
            '</modify_scanner>'
135
        )
136
137
    def test_modify_scanner_with_scanner_type(self):
138
        self.gmp.modify_scanner(
139
            scanner_id='s1',
140
            scanner_type=OSP_SCANNER_TYPE,
141
        )
142
143
        self.connection.send.has_been_called_with(
144
            '<modify_scanner scanner_id="s1">'
145
            '<type>1</type>'
146
            '</modify_scanner>'
147
        )
148
149
        self.gmp.modify_scanner(
150
            scanner_id='s1',
151
            scanner_type=OPENVAS_SCANNER_TYPE,
152
        )
153
154
        self.connection.send.has_been_called_with(
155
            '<modify_scanner scanner_id="s1">'
156
            '<type>2</type>'
157
            '</modify_scanner>'
158
        )
159
160
        self.gmp.modify_scanner(
161
            scanner_id='s1',
162
            scanner_type=CVE_SCANNER_TYPE,
163
        )
164
165
        self.connection.send.has_been_called_with(
166
            '<modify_scanner scanner_id="s1">'
167
            '<type>3</type>'
168
            '</modify_scanner>'
169
        )
170
171
        self.gmp.modify_scanner(
172
            scanner_id='s1',
173
            scanner_type=GMP_SCANNER_TYPE,
174
        )
175
176
        self.connection.send.has_been_called_with(
177
            '<modify_scanner scanner_id="s1">'
178
            '<type>4</type>'
179
            '</modify_scanner>'
180
        )
181
182
    def test_modify_scanner_invalid_scanner_type(self):
183
        with self.assertRaises(InvalidArgument):
184
            self.gmp.modify_scanner(
185
                scanner_id='s1',
186
                scanner_type='',
187
            )
188
189
        with self.assertRaises(InvalidArgument):
190
            self.gmp.modify_scanner(
191
                scanner_id='s1',
192
                scanner_type='-1',
193
            )
194
195
        with self.assertRaises(InvalidArgument):
196
            self.gmp.modify_scanner(
197
                scanner_id='s1',
198
                scanner_type='66',
199
            )
200
201
202
203
if __name__ == '__main__':
204
    unittest.main()
205