Passed
Pull Request — master (#300)
by Juan José
01:27
created

GmpCreateScannerTestCase.test_create_scanner_missing_host()   A

Complexity

Conditions 3

Size

Total Lines 17
Code Lines 15

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nop 1
dl 17
loc 17
rs 9.65
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, InvalidArgumentType
22
23
from gvm.protocols.gmpv9 import ScannerType
24
25
26 View Code Duplication
class GmpCreateScannerTestCase:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
27
    def test_create_scanner(self):
28
        self.gmp.create_scanner(
29
            name='foo',
30
            host='localhost',
31
            port=1234,
32
            scanner_type=ScannerType.OSP_SCANNER_TYPE,
33
            credential_id='c1',
34
        )
35
36
        self.connection.send.has_been_called_with(
37
            '<create_scanner>'
38
            '<name>foo</name>'
39
            '<host>localhost</host>'
40
            '<port>1234</port>'
41
            '<type>1</type>'
42
            '<credential id="c1"/>'
43
            '</create_scanner>'
44
        )
45
46
    def test_create_scanner_missing_name(self):
47
        with self.assertRaises(RequiredArgument):
48
            self.gmp.create_scanner(
49
                name=None,
50
                host='localhost',
51
                port=1234,
52
                scanner_type=ScannerType.OSP_SCANNER_TYPE,
53
                credential_id='c1',
54
            )
55
56
        with self.assertRaises(RequiredArgument):
57
            self.gmp.create_scanner(
58
                name='',
59
                host='localhost',
60
                port=1234,
61
                scanner_type='1',
62
                credential_id='c1',
63
            )
64
65
    def test_create_scanner_missing_host(self):
66
        with self.assertRaises(RequiredArgument):
67
            self.gmp.create_scanner(
68
                name='foo',
69
                host=None,
70
                port=1234,
71
                scanner_type=ScannerType.OSP_SCANNER_TYPE,
72
                credential_id='c1',
73
            )
74
75
        with self.assertRaises(RequiredArgument):
76
            self.gmp.create_scanner(
77
                name='foo',
78
                host='',
79
                port=1234,
80
                scanner_type=ScannerType.OSP_SCANNER_TYPE,
81
                credential_id='c1',
82
            )
83
84
    def test_create_scanner_missing_port(self):
85
        with self.assertRaises(RequiredArgument):
86
            self.gmp.create_scanner(
87
                name='foo',
88
                host='localhost',
89
                port=None,
90
                scanner_type=ScannerType.OSP_SCANNER_TYPE,
91
                credential_id='c1',
92
            )
93
94
        with self.assertRaises(RequiredArgument):
95
            self.gmp.create_scanner(
96
                name='foo',
97
                host='localhost',
98
                port='',
99
                scanner_type=ScannerType.OSP_SCANNER_TYPE,
100
                credential_id='c1',
101
            )
102
103
    def test_create_scanner_missing_scanner_type(self):
104
        with self.assertRaises(RequiredArgument):
105
            self.gmp.create_scanner(
106
                name='foo',
107
                host='localhost',
108
                port=1234,
109
                scanner_type=None,
110
                credential_id='c1',
111
            )
112
113
        with self.assertRaises(RequiredArgument):
114
            self.gmp.create_scanner(
115
                name='foo',
116
                host='localhost',
117
                port=1234,
118
                scanner_type='',
119
                credential_id='c1',
120
            )
121
122
    def test_create_scanner_missing_credential_id(self):
123
        with self.assertRaises(RequiredArgument):
124
            self.gmp.create_scanner(
125
                name='foo',
126
                host='localhost',
127
                port=1234,
128
                scanner_type=ScannerType.OSP_SCANNER_TYPE,
129
                credential_id=None,
130
            )
131
132
        with self.assertRaises(RequiredArgument):
133
            self.gmp.create_scanner(
134
                name='foo',
135
                host='localhost',
136
                port=1234,
137
                scanner_type=ScannerType.OSP_SCANNER_TYPE,
138
                credential_id='',
139
            )
140
141
    def test_create_scanner_invalid_scanner_type(self):
142
        with self.assertRaises(InvalidArgumentType):
143
            self.gmp.create_scanner(
144
                name='foo',
145
                host='localhost',
146
                port=1234,
147
                scanner_type='bar',
148
                credential_id='c1',
149
            )
150
151
        with self.assertRaises(InvalidArgumentType):
152
            self.gmp.create_scanner(
153
                name='foo',
154
                host='localhost',
155
                port=1234,
156
                scanner_type='55',
157
                credential_id='c1',
158
            )
159
160
    def test_create_scanner_with_ca_pub(self):
161
        self.gmp.create_scanner(
162
            name='foo',
163
            host='localhost',
164
            port=1234,
165
            ca_pub='foo',
166
            scanner_type=ScannerType.OSP_SCANNER_TYPE,
167
            credential_id='c1',
168
        )
169
170
        self.connection.send.has_been_called_with(
171
            '<create_scanner>'
172
            '<name>foo</name>'
173
            '<host>localhost</host>'
174
            '<port>1234</port>'
175
            '<type>1</type>'
176
            '<ca_pub>foo</ca_pub>'
177
            '<credential id="c1"/>'
178
            '</create_scanner>'
179
        )
180
181
    def test_create_scanner_with_comment(self):
182
        self.gmp.create_scanner(
183
            name='foo',
184
            host='localhost',
185
            port=1234,
186
            scanner_type=ScannerType.OSP_SCANNER_TYPE,
187
            credential_id='c1',
188
            comment='bar',
189
        )
190
191
        self.connection.send.has_been_called_with(
192
            '<create_scanner>'
193
            '<name>foo</name>'
194
            '<host>localhost</host>'
195
            '<port>1234</port>'
196
            '<type>1</type>'
197
            '<credential id="c1"/>'
198
            '<comment>bar</comment>'
199
            '</create_scanner>'
200
        )
201
202
203
if __name__ == '__main__':
204
    unittest.main()
205