|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright (C) 2018-2021 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
|
|
|
from gvm.protocols.gmpv208 import PortRangeType |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
View Code Duplication |
class GmpCreatePortRangeTestCase: |
|
|
|
|
|
|
27
|
|
|
def test_create_port_range_missing_port_list_id(self): |
|
28
|
|
|
with self.assertRaises(RequiredArgument): |
|
29
|
|
|
self.gmp.create_port_range( |
|
30
|
|
|
port_list_id=None, |
|
31
|
|
|
start=1, |
|
32
|
|
|
end=1234, |
|
33
|
|
|
port_range_type=PortRangeType.TCP, |
|
34
|
|
|
) |
|
35
|
|
|
|
|
36
|
|
|
with self.assertRaises(RequiredArgument): |
|
37
|
|
|
self.gmp.create_port_range( |
|
38
|
|
|
port_list_id='', |
|
39
|
|
|
start=1, |
|
40
|
|
|
end=1234, |
|
41
|
|
|
port_range_type=PortRangeType.TCP, |
|
42
|
|
|
) |
|
43
|
|
|
|
|
44
|
|
|
def test_create_port_range_missing_start(self): |
|
45
|
|
|
with self.assertRaises(RequiredArgument): |
|
46
|
|
|
self.gmp.create_port_range( |
|
47
|
|
|
port_list_id='pl1', |
|
48
|
|
|
start=None, |
|
49
|
|
|
end=1234, |
|
50
|
|
|
port_range_type=PortRangeType.TCP, |
|
51
|
|
|
) |
|
52
|
|
|
|
|
53
|
|
|
with self.assertRaises(RequiredArgument): |
|
54
|
|
|
self.gmp.create_port_range( |
|
55
|
|
|
port_list_id='pl1', |
|
56
|
|
|
start='', |
|
57
|
|
|
end=1234, |
|
58
|
|
|
port_range_type=PortRangeType.TCP, |
|
59
|
|
|
) |
|
60
|
|
|
|
|
61
|
|
|
def test_create_port_range_missing_end(self): |
|
62
|
|
|
with self.assertRaises(RequiredArgument): |
|
63
|
|
|
self.gmp.create_port_range( |
|
64
|
|
|
port_list_id='pl1', |
|
65
|
|
|
start=1, |
|
66
|
|
|
end=None, |
|
67
|
|
|
port_range_type=PortRangeType.TCP, |
|
68
|
|
|
) |
|
69
|
|
|
|
|
70
|
|
|
with self.assertRaises(RequiredArgument): |
|
71
|
|
|
self.gmp.create_port_range( |
|
72
|
|
|
port_list_id='pl1', |
|
73
|
|
|
start=1, |
|
74
|
|
|
end='', |
|
75
|
|
|
port_range_type=PortRangeType.TCP, |
|
76
|
|
|
) |
|
77
|
|
|
|
|
78
|
|
|
def test_create_port_range_missing_port_range_type(self): |
|
79
|
|
|
with self.assertRaises(RequiredArgument): |
|
80
|
|
|
self.gmp.create_port_range( |
|
81
|
|
|
port_list_id='pl1', start=1, end=1234, port_range_type=None |
|
82
|
|
|
) |
|
83
|
|
|
|
|
84
|
|
|
with self.assertRaises(RequiredArgument): |
|
85
|
|
|
self.gmp.create_port_range( |
|
86
|
|
|
port_list_id='pl1', start=1, end=1234, port_range_type='' |
|
87
|
|
|
) |
|
88
|
|
|
|
|
89
|
|
|
def test_create_port_range(self): |
|
90
|
|
|
self.gmp.create_port_range( |
|
91
|
|
|
port_list_id='pl1', |
|
92
|
|
|
start=1, |
|
93
|
|
|
end=1234, |
|
94
|
|
|
port_range_type=PortRangeType.TCP, |
|
95
|
|
|
) |
|
96
|
|
|
|
|
97
|
|
|
self.connection.send.has_been_called_with( |
|
98
|
|
|
'<create_port_range>' |
|
99
|
|
|
'<port_list id="pl1"/>' |
|
100
|
|
|
'<start>1</start>' |
|
101
|
|
|
'<end>1234</end>' |
|
102
|
|
|
'<type>TCP</type>' |
|
103
|
|
|
'</create_port_range>' |
|
104
|
|
|
) |
|
105
|
|
|
|
|
106
|
|
|
self.gmp.create_port_range( |
|
107
|
|
|
port_list_id='pl1', |
|
108
|
|
|
start=1, |
|
109
|
|
|
end=1234, |
|
110
|
|
|
port_range_type=PortRangeType.UDP, |
|
111
|
|
|
) |
|
112
|
|
|
|
|
113
|
|
|
self.connection.send.has_been_called_with( |
|
114
|
|
|
'<create_port_range>' |
|
115
|
|
|
'<port_list id="pl1"/>' |
|
116
|
|
|
'<start>1</start>' |
|
117
|
|
|
'<end>1234</end>' |
|
118
|
|
|
'<type>UDP</type>' |
|
119
|
|
|
'</create_port_range>' |
|
120
|
|
|
) |
|
121
|
|
|
|
|
122
|
|
|
self.gmp.create_port_range( |
|
123
|
|
|
port_list_id='pl1', |
|
124
|
|
|
start='1', |
|
125
|
|
|
end='1234', |
|
126
|
|
|
port_range_type=PortRangeType.TCP, |
|
127
|
|
|
) |
|
128
|
|
|
|
|
129
|
|
|
self.connection.send.has_been_called_with( |
|
130
|
|
|
'<create_port_range>' |
|
131
|
|
|
'<port_list id="pl1"/>' |
|
132
|
|
|
'<start>1</start>' |
|
133
|
|
|
'<end>1234</end>' |
|
134
|
|
|
'<type>TCP</type>' |
|
135
|
|
|
'</create_port_range>' |
|
136
|
|
|
) |
|
137
|
|
|
|
|
138
|
|
|
def test_create_port_range_with_comment(self): |
|
139
|
|
|
self.gmp.create_port_range( |
|
140
|
|
|
port_list_id='pl1', |
|
141
|
|
|
start=1, |
|
142
|
|
|
end=1234, |
|
143
|
|
|
port_range_type=PortRangeType.TCP, |
|
144
|
|
|
comment='lorem', |
|
145
|
|
|
) |
|
146
|
|
|
|
|
147
|
|
|
self.connection.send.has_been_called_with( |
|
148
|
|
|
'<create_port_range>' |
|
149
|
|
|
'<port_list id="pl1"/>' |
|
150
|
|
|
'<start>1</start>' |
|
151
|
|
|
'<end>1234</end>' |
|
152
|
|
|
'<type>TCP</type>' |
|
153
|
|
|
'<comment>lorem</comment>' |
|
154
|
|
|
'</create_port_range>' |
|
155
|
|
|
) |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
if __name__ == '__main__': |
|
159
|
|
|
unittest.main() |
|
160
|
|
|
|