Completed
Push — master ( 20d591...98174d )
by Juan José
14s queued 11s
created

tests.dummydaemon.FakeDataManager.dict()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2014-2020 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: AGPL-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 Affero General Public License as
8
# published by the Free Software Foundation, either version 3 of the
9
# License, or (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 Affero General Public License for more details.
15
#
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
20
from unittest.mock import patch, MagicMock
21
22
from xml.etree import ElementTree as et
23
24
from ospd_openvas.daemon import OSPDopenvas
25
26
27
class FakeDataManager:
28
    def __init__(self):
29
        pass
30
31
    def dict(self):
32
        return dict()
33
34
35
class DummyDaemon(OSPDopenvas):
36
    VTS = {
37
        '1.3.6.1.4.1.25623.1.0.100061': {
38
            'creation_time': '1237458156',
39
            'custom': {
40
                'category': '3',
41
                'excluded_keys': 'Settings/disable_cgi_scanning',
42
                'family': 'Product detection',
43
                'filename': 'mantis_detect.nasl',
44
                'required_ports': 'Services/www, 80',
45
                'timeout': '0',
46
            },
47
            'modification_time': ('1533906565'),
48
            'name': 'Mantis Detection',
49
            'qod_type': 'remote_banner',
50
            'insight': 'some insight',
51
            'severities': {
52
                'severity_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N',
53
                'severity_type': 'cvss_base_v2',
54
            },
55
            'solution': 'some solution',
56
            'solution_type': 'WillNotFix',
57
            'solution_method': 'DebianAPTUpgrade',
58
            'impact': 'some impact',
59
            'summary': 'some summary',
60
            'affected': 'some affection',
61
            'vt_dependencies': [],
62
            'vt_params': {
63
                '1': {
64
                    'id': '1',
65
                    'default': '',
66
                    'description': 'Description',
67
                    'name': 'Data length :',
68
                    'type': 'entry',
69
                },
70
                '2': {
71
                    'id': '2',
72
                    'default': 'no',
73
                    'description': 'Description',
74
                    'name': 'Do not randomize the  order  in  which ports are scanned',  # pylint: disable=line-too-long
75
                    'type': 'checkbox',
76
                },
77
            },
78
            'vt_refs': {
79
                'bid': [''],
80
                'cve': [''],
81
                'xref': ['URL:http://www.mantisbt.org/'],
82
            },
83
        }
84
    }
85
86
    @patch('ospd_openvas.daemon.NVTICache')
87
    @patch('ospd_openvas.daemon.MainDB')
88
    def __init__(self, _MainDBClass: MagicMock, NvtiClass: MagicMock):
89
        nvti = NvtiClass.return_value
90
        oids = [['mantis_detect.nasl', '1.3.6.1.4.1.25623.1.0.100061']]
91
        nvti.get_oids.return_value = oids
92
        nvti.get_nvt_params.return_value = {
93
            '1': {
94
                'id': '1',
95
                'default': '',
96
                'description': 'Description',
97
                'name': 'Data length :',
98
                'type': 'entry',
99
            },
100
            '2': {
101
                'id': '2',
102
                'default': 'no',
103
                'description': 'Description',
104
                'name': 'Do not randomize the  order  in  which ports are scanned',  # pylint: disable=line-too-long
105
                'type': 'checkbox',
106
            },
107
        }
108
        nvti.get_nvt_refs.return_value = {
109
            'bid': [''],
110
            'cve': [''],
111
            'xref': ['URL:http://www.mantisbt.org/'],
112
        }
113
        nvti.get_nvt_metadata.return_value = {
114
            'category': '3',
115
            'creation_date': '1237458156',
116
            'cvss_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N',
117
            'excluded_keys': 'Settings/disable_cgi_scanning',
118
            'family': 'Product detection',
119
            'filename': 'mantis_detect.nasl',
120
            'last_modification': ('1533906565'),
121
            'name': 'Mantis Detection',
122
            'qod_type': 'remote_banner',
123
            'required_ports': 'Services/www, 80',
124
            'solution': 'some solution',
125
            'solution_type': 'WillNotFix',
126
            'solution_method': 'DebianAPTUpgrade',
127
            'impact': 'some impact',
128
            'insight': 'some insight',
129
            'summary': ('some summary'),
130
            'affected': 'some affection',
131
            'timeout': '0',
132
            'vt_params': {
133
                '1': {
134
                    'id': '1',
135
                    'default': '',
136
                    'description': 'Description',
137
                    'name': 'Data length :',
138
                    'type': 'entry',
139
                },
140
                '2': {
141
                    'id': '2',
142
                    'default': 'no',
143
                    'description': 'Description',
144
                    'name': 'Do not randomize the  order  in  which ports are scanned',  # pylint: disable=line-too-long
145
                    'type': 'checkbox',
146
                },
147
            },
148
            'refs': {
149
                'bid': [''],
150
                'cve': [''],
151
                'xref': ['URL:http://www.mantisbt.org/'],
152
            },
153
        }
154
        nvti.get_feed_version.return_value = '123'
155
156
        super().__init__(niceness=10, lock_file_dir='/tmp')
157
158
        self.scan_collection.data_manager = FakeDataManager()
159
160
    def create_xml_target(self) -> et.Element:
161
        target = et.fromstring(
162
            "<target>"
163
            "<hosts>192.168.0.1</hosts>"
164
            "<ports>80,443</ports>"
165
            "</target>"
166
        )
167
        return target
168