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
|
|
|
from gvm.errors import RequiredArgument, InvalidArgumentType |
20
|
|
|
|
21
|
|
|
from gvm.protocols.gmpv208 import InfoType |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
class GmpGetInfoListTestMixin: |
25
|
|
|
def test_get_info_list(self): |
26
|
|
|
self.gmp.get_info_list(InfoType.CERT_BUND_ADV) |
27
|
|
|
|
28
|
|
|
self.connection.send.has_been_called_with( |
29
|
|
|
'<get_info type="CERT_BUND_ADV"/>' |
30
|
|
|
) |
31
|
|
|
|
32
|
|
|
self.gmp.get_info_list(InfoType.CPE) |
33
|
|
|
|
34
|
|
|
self.connection.send.has_been_called_with('<get_info type="CPE"/>') |
35
|
|
|
|
36
|
|
|
self.gmp.get_info_list(info_type=InfoType.CPE) |
37
|
|
|
|
38
|
|
|
self.connection.send.has_been_called_with('<get_info type="CPE"/>') |
39
|
|
|
|
40
|
|
|
self.gmp.get_info_list(InfoType.CVE) |
41
|
|
|
|
42
|
|
|
self.connection.send.has_been_called_with('<get_info type="CVE"/>') |
43
|
|
|
|
44
|
|
|
self.gmp.get_info_list(InfoType.DFN_CERT_ADV) |
45
|
|
|
|
46
|
|
|
self.connection.send.has_been_called_with( |
47
|
|
|
'<get_info type="DFN_CERT_ADV"/>' |
48
|
|
|
) |
49
|
|
|
|
50
|
|
|
self.gmp.get_info_list(InfoType.OVALDEF) |
51
|
|
|
|
52
|
|
|
self.connection.send.has_been_called_with('<get_info type="OVALDEF"/>') |
53
|
|
|
|
54
|
|
|
self.gmp.get_info_list(InfoType.NVT) |
55
|
|
|
|
56
|
|
|
self.connection.send.has_been_called_with('<get_info type="NVT"/>') |
57
|
|
|
|
58
|
|
|
with self.assertRaises(AttributeError): |
59
|
|
|
self.gmp.get_info_list( |
60
|
|
|
InfoType.ALLINFO # pylint: disable=no-member |
61
|
|
|
) |
62
|
|
|
|
63
|
|
|
def test_get_info_list_missing_info_type(self): |
64
|
|
|
with self.assertRaises(RequiredArgument): |
65
|
|
|
self.gmp.get_info_list(info_type=None) |
66
|
|
|
|
67
|
|
|
with self.assertRaises(RequiredArgument): |
68
|
|
|
self.gmp.get_info_list(info_type='') |
69
|
|
|
|
70
|
|
|
with self.assertRaises(RequiredArgument): |
71
|
|
|
self.gmp.get_info_list('') |
72
|
|
|
|
73
|
|
|
def test_get_info_list_invalid_info_type(self): |
74
|
|
|
with self.assertRaises(InvalidArgumentType): |
75
|
|
|
self.gmp.get_info_list(info_type='foo') |
76
|
|
|
|
77
|
|
|
def test_get_info_list_with_filter(self): |
78
|
|
|
self.gmp.get_info_list(InfoType.CPE, filter='foo=bar') |
79
|
|
|
|
80
|
|
|
self.connection.send.has_been_called_with( |
81
|
|
|
'<get_info type="CPE" filter="foo=bar"/>' |
82
|
|
|
) |
83
|
|
|
|
84
|
|
|
def test_get_info_list_with_filter_id(self): |
85
|
|
|
self.gmp.get_info_list(info_type=InfoType.CPE, filter_id='f1') |
86
|
|
|
|
87
|
|
|
self.connection.send.has_been_called_with( |
88
|
|
|
'<get_info type="CPE" filt_id="f1"/>' |
89
|
|
|
) |
90
|
|
|
|
91
|
|
|
def test_get_info_list_with_name(self): |
92
|
|
|
self.gmp.get_info_list(info_type=InfoType.CPE, name='foo') |
93
|
|
|
|
94
|
|
|
self.connection.send.has_been_called_with( |
95
|
|
|
'<get_info type="CPE" name="foo"/>' |
96
|
|
|
) |
97
|
|
|
|
98
|
|
|
def test_get_info_list_with_details(self): |
99
|
|
|
self.gmp.get_info_list(info_type=InfoType.CPE, details=True) |
100
|
|
|
|
101
|
|
|
self.connection.send.has_been_called_with( |
102
|
|
|
'<get_info type="CPE" details="1"/>' |
103
|
|
|
) |
104
|
|
|
|
105
|
|
|
self.gmp.get_info_list(info_type=InfoType.CPE, details=False) |
106
|
|
|
|
107
|
|
|
self.connection.send.has_been_called_with( |
108
|
|
|
'<get_info type="CPE" details="0"/>' |
109
|
|
|
) |
110
|
|
|
|