|
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 |
|
20
|
|
|
from gvm.protocols.gmpv208.entities.report_formats import ( |
|
21
|
|
|
ReportFormatType, |
|
22
|
|
|
get_report_format_id_from_string, |
|
23
|
|
|
) |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class GmpGetReportTestMixin: |
|
27
|
|
|
def test_get_report_without_id(self): |
|
28
|
|
|
with self.assertRaises(RequiredArgument): |
|
29
|
|
|
self.gmp.get_report(None) |
|
30
|
|
|
|
|
31
|
|
|
with self.assertRaises(RequiredArgument): |
|
32
|
|
|
self.gmp.get_report('') |
|
33
|
|
|
|
|
34
|
|
|
def test_get_report_with_filter(self): |
|
35
|
|
|
self.gmp.get_report(report_id='r1', filter='name=foo') |
|
36
|
|
|
|
|
37
|
|
|
self.connection.send.has_been_called_with( |
|
38
|
|
|
'<get_reports report_id="r1" filter="name=foo" details="1"/>' |
|
39
|
|
|
) |
|
40
|
|
|
|
|
41
|
|
|
def test_get_report_with_filter_id(self): |
|
42
|
|
|
self.gmp.get_report(report_id='r1', filter_id='f1') |
|
43
|
|
|
|
|
44
|
|
|
self.connection.send.has_been_called_with( |
|
45
|
|
|
'<get_reports report_id="r1" filt_id="f1" details="1"/>' |
|
46
|
|
|
) |
|
47
|
|
|
|
|
48
|
|
|
def test_get_report_with_report_format_id(self): |
|
49
|
|
|
self.gmp.get_report(report_id='r1', report_format_id='bar') |
|
50
|
|
|
|
|
51
|
|
|
self.connection.send.has_been_called_with( |
|
52
|
|
|
'<get_reports report_id="r1" format_id="bar" details="1"/>' |
|
53
|
|
|
) |
|
54
|
|
|
|
|
55
|
|
|
def test_get_report_with_report_format_type(self): |
|
56
|
|
|
self.gmp.get_report( |
|
57
|
|
|
report_id='r1', report_format_id=ReportFormatType.TXT |
|
58
|
|
|
) |
|
59
|
|
|
report_format_id = get_report_format_id_from_string('txt').value |
|
60
|
|
|
|
|
61
|
|
|
self.connection.send.has_been_called_with( |
|
62
|
|
|
'<get_reports report_id="r1" format_id="{}" details="1"/>'.format( |
|
63
|
|
|
report_format_id |
|
64
|
|
|
) |
|
65
|
|
|
) |
|
66
|
|
|
|
|
67
|
|
|
def test_get_report_with_delta_report_id(self): |
|
68
|
|
|
self.gmp.get_report(report_id='r1', delta_report_id='r2') |
|
69
|
|
|
|
|
70
|
|
|
self.connection.send.has_been_called_with( |
|
71
|
|
|
'<get_reports report_id="r1" delta_report_id="r2" details="1"/>' |
|
72
|
|
|
) |
|
73
|
|
|
|
|
74
|
|
|
def test_get_report_with_ignore_pagination(self): |
|
75
|
|
|
self.gmp.get_report(report_id='r1', ignore_pagination=True) |
|
76
|
|
|
|
|
77
|
|
|
self.connection.send.has_been_called_with( |
|
78
|
|
|
'<get_reports report_id="r1" ignore_pagination="1" details="1"/>' |
|
79
|
|
|
) |
|
80
|
|
|
|
|
81
|
|
|
self.gmp.get_report(report_id='r1', ignore_pagination=False) |
|
82
|
|
|
|
|
83
|
|
|
self.connection.send.has_been_called_with( |
|
84
|
|
|
'<get_reports report_id="r1" ignore_pagination="0" details="1"/>' |
|
85
|
|
|
) |
|
86
|
|
|
|
|
87
|
|
|
def test_get_report_with_details(self): |
|
88
|
|
|
self.gmp.get_report(report_id='r1', details=True) |
|
89
|
|
|
|
|
90
|
|
|
self.connection.send.has_been_called_with( |
|
91
|
|
|
'<get_reports report_id="r1" details="1"/>' |
|
92
|
|
|
) |
|
93
|
|
|
|
|
94
|
|
|
self.gmp.get_report(report_id='r1', details=False) |
|
95
|
|
|
|
|
96
|
|
|
self.connection.send.has_been_called_with( |
|
97
|
|
|
'<get_reports report_id="r1" details="0"/>' |
|
98
|
|
|
) |
|
99
|
|
|
|