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 GmpGetInfoTestMixin: |
25
|
|
|
def test_get_info(self): |
26
|
|
|
self.gmp.get_info(info_type=InfoType.CERT_BUND_ADV, info_id='i1') |
27
|
|
|
|
28
|
|
|
self.connection.send.has_been_called_with( |
29
|
|
|
'<get_info info_id="i1" type="CERT_BUND_ADV" details="1"/>' |
30
|
|
|
) |
31
|
|
|
|
32
|
|
|
self.gmp.get_info('i1', InfoType.CPE) |
33
|
|
|
|
34
|
|
|
self.connection.send.has_been_called_with( |
35
|
|
|
'<get_info info_id="i1" type="CPE" details="1"/>' |
36
|
|
|
) |
37
|
|
|
|
38
|
|
|
self.gmp.get_info('i1', InfoType.CVE) |
39
|
|
|
|
40
|
|
|
self.connection.send.has_been_called_with( |
41
|
|
|
'<get_info info_id="i1" type="CVE" details="1"/>' |
42
|
|
|
) |
43
|
|
|
|
44
|
|
|
self.gmp.get_info('i1', InfoType.DFN_CERT_ADV) |
45
|
|
|
|
46
|
|
|
self.connection.send.has_been_called_with( |
47
|
|
|
'<get_info info_id="i1" type="DFN_CERT_ADV" details="1"/>' |
48
|
|
|
) |
49
|
|
|
|
50
|
|
|
self.gmp.get_info('i1', InfoType.OVALDEF) |
51
|
|
|
|
52
|
|
|
self.connection.send.has_been_called_with( |
53
|
|
|
'<get_info info_id="i1" type="OVALDEF" details="1"/>' |
54
|
|
|
) |
55
|
|
|
|
56
|
|
|
self.gmp.get_info('i1', InfoType.NVT) |
57
|
|
|
|
58
|
|
|
self.connection.send.has_been_called_with( |
59
|
|
|
'<get_info info_id="i1" type="NVT" details="1"/>' |
60
|
|
|
) |
61
|
|
|
|
62
|
|
|
with self.assertRaises(AttributeError): |
63
|
|
|
self.gmp.get_info( |
64
|
|
|
'i1', InfoType.ALLINFO # pylint: disable=no-member |
65
|
|
|
) |
66
|
|
|
|
67
|
|
|
def test_get_info_missing_info_type(self): |
68
|
|
|
with self.assertRaises(RequiredArgument): |
69
|
|
|
self.gmp.get_info(info_id='i1', info_type=None) |
70
|
|
|
|
71
|
|
|
with self.assertRaises(RequiredArgument): |
72
|
|
|
self.gmp.get_info(info_id='i1', info_type='') |
73
|
|
|
|
74
|
|
|
with self.assertRaises(RequiredArgument): |
75
|
|
|
self.gmp.get_info('i1', '') |
76
|
|
|
|
77
|
|
|
def test_get_info_invalid_info_type(self): |
78
|
|
|
with self.assertRaises(InvalidArgumentType): |
79
|
|
|
self.gmp.get_info(info_id='i1', info_type='foo') |
80
|
|
|
|
81
|
|
|
def test_get_info_missing_info_id(self): |
82
|
|
|
with self.assertRaises(RequiredArgument): |
83
|
|
|
self.gmp.get_info(info_id='', info_type=InfoType.CPE) |
84
|
|
|
|
85
|
|
|
with self.assertRaises(RequiredArgument): |
86
|
|
|
self.gmp.get_info('', info_type=InfoType.CPE) |
87
|
|
|
|
88
|
|
|
with self.assertRaises(RequiredArgument): |
89
|
|
|
self.gmp.get_info(info_id=None, info_type=InfoType.CPE) |
90
|
|
|
|