Completed
Push — master ( e3b2dd...9ff0e2 )
by
unknown
22s
created

FullTest.testScanMultiTargetParallel100()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nop 1
dl 0
loc 13
rs 9.75
c 0
b 0
f 0
1
# Copyright (C) 2015-2018 Greenbone Networks GmbH
0 ignored issues
show
Coding Style Naming introduced by
The name testScanAndResult does not conform to the module naming conventions ((([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
2
#
3
# SPDX-License-Identifier: GPL-2.0-or-later
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
""" Test module for scan runs
20
"""
21
22
from __future__ import print_function
23
24
import time
25
import unittest
26
import xml.etree.ElementTree as ET
27
import defusedxml.lxml as secET
28
from defusedxml.common import EntitiesForbidden
29
30
from ospd.ospd import OSPDaemon, OSPDError
31
32
class Result(object):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
best-practice introduced by
Too many instance attributes (8/7)
Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
33
    def __init__(self, type_, **kwargs):
34
        self.result_type = type_
35
        self.host = ''
36
        self.name = ''
37
        self.value = ''
38
        self.port = ''
39
        self.test_id = ''
40
        self.severity = ''
41
        self.qod = ''
42
        for name, value in kwargs.items():
43
            setattr(self, name, value)
44
45
46
class DummyWrapper(OSPDaemon):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
47
    def __init__(self, results, checkresult=True):
48
        OSPDaemon.__init__(self, 'cert', 'key', 'ca')
49
        self.checkresult = checkresult
50
        self.results = results
51
52
    def check(self):
53
        return self.checkresults
0 ignored issues
show
Bug introduced by
Instance of 'DummyWrapper' has no 'checkresults' member; maybe 'checkresult'?

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
54
55
    def get_custom_vt_as_xml_str(self, custom):
56
        return '<mytest>static test</mytest>'
57
58
    def get_params_vt_as_xml_str(self, vt_param):
0 ignored issues
show
Bug introduced by
Parameters differ from overridden 'get_params_vt_as_xml_str' method
Loading history...
Unused Code introduced by
The argument vt_param seems to be unused.
Loading history...
59
        return ('<vt_param id="abc" type="string">'
60
                '<name>ABC</name><description>Test ABC</description><default>yes</default>'
61
                '</vt_param>'
62
                '<vt_param id="def" type="string">'
63
                '<name>DEF</name><description>Test DEF</description><default>no</default>'
64
                '</vt_param>')
65
66
    def get_refs_vt_as_xml_str(self, vt_refs):
67
        response = ('<ref type="cve" id="CVE-2010-4480"/>' +
68
                    '<ref type="url" id="http://example.com"/>')
69
        return response
70
71
    def exec_scan(self, scan_id, target):
72
        time.sleep(0.01)
73
        for res in self.results:
74
            if res.result_type == 'log':
75
                self.add_scan_log(scan_id, res.host or target, res.name, res.value, res.port)
76
            if res.result_type == 'error':
77
                self.add_scan_error(scan_id, res.host or target, res.name, res.value, res.port)
78
            elif res.result_type == 'host-detail':
79
                self.add_scan_host_detail(scan_id, res.host or target, res.name, res.value)
80
            elif res.result_type == 'alarm':
81
                self.add_scan_alarm(scan_id, res.host or target, res.name, res.value, res.port, res.test_id, res.severity, res.qod)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (131/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
82
            else:
83
                raise ValueError(res.result_type)
84
85
86
class FullTest(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
best-practice introduced by
Too many public methods (22/20)
Loading history...
87
    # TODO: There should be a lot more assert in there !
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
88
89
    def testGetDefaultScannerParams(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetDefaultScannerParams does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
90
        daemon = DummyWrapper([])
91
        response = secET.fromstring(daemon.handle_command('<get_scanner_details />'))
92
        # The status of the response must be success (i.e. 200)
93
        self.assertEqual(response.get('status'), '200')
94
        # The response root element must have the correct name
95
        self.assertEqual(response.tag, 'get_scanner_details_response')
96
        # The response must contain a 'scanner_params' element
97
        print(ET.tostring(response))
98
        self.assertIsNotNone(response.find('scanner_params'))
99
100
    def testGetDefaultHelp(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetDefaultHelp does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
101
        daemon = DummyWrapper([])
102
        response = secET.fromstring(daemon.handle_command('<help />'))
103
        print(ET.tostring(response))
104
        self.assertEqual(response.get('status'), '200')
105
        response = secET.fromstring(daemon.handle_command('<help format="xml" />'))
106
        print(ET.tostring(response))
107
        self.assertEqual(response.get('status'), '200')
108
        self.assertEqual(response.tag, 'help_response')
109
110
    def testGetDefaultScannerVersion(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetDefaultScannerVersion does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
111
        daemon = DummyWrapper([])
112
        response = secET.fromstring(daemon.handle_command('<get_version />'))
113
        print(ET.tostring(response))
114
        self.assertEqual(response.get('status'), '200')
115
        self.assertIsNotNone(response.find('protocol'))
116
117
    def testGetVTs_no_VT(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetVTs_no_VT does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
118
        daemon = DummyWrapper([])
119
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
120
        print(ET.tostring(response))
121
        self.assertEqual(response.get('status'), '200')
122
        self.assertIsNotNone(response.find('vts'))
123
124
    def testGetVTs_single_VT(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetVTs_single_VT does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
125
        daemon = DummyWrapper([])
126
        daemon.add_vt('1.2.3.4', 'A vulnerability test')
127
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
128
        print(ET.tostring(response))
129
        self.assertEqual(response.get('status'), '200')
130
        vts = response.find('vts')
131
        self.assertIsNotNone(vts.find('vt'))
132
        vt = vts.find('vt')
0 ignored issues
show
Coding Style Naming introduced by
The name vt does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
133
        self.assertEqual(vt.get('id'), '1.2.3.4')
134
135
    def testGetVTs_multiple_VTs(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetVTs_multiple_VTs does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
136
        daemon = DummyWrapper([])
137
        daemon.add_vt('1.2.3.4', 'A vulnerability test')
138
        daemon.add_vt('some id', 'Another vulnerability test')
139
        daemon.add_vt('123456789', 'Yet another vulnerability test')
140
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
141
        print(ET.tostring(response))
142
        self.assertEqual(response.get('status'), '200')
143
        vts = response.find('vts')
144
        self.assertIsNotNone(vts.find('vt'))
145
146
    def testGetVTs_multiple_VTs_with_custom(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetVTs_multiple_VTs_with_custom does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
147
        daemon = DummyWrapper([])
148
        daemon.add_vt('1.2.3.4', 'A vulnerability test')
149
        daemon.add_vt('some id', 'Another vulnerability test with custom info', {'depencency': '1.2.3.4'})
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
150
        daemon.add_vt('123456789', 'Yet another vulnerability test')
151
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
152
        print(ET.tostring(response))
153
154 View Code Duplication
    def testGetVTs_VTs_with_params(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name testGetVTs_VTs_with_params does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
155
        daemon = DummyWrapper([])
156
        daemon.add_vt('1.2.3.4', 'A vulnerability test', vt_params="a", custom="b")
157
        response = secET.fromstring(daemon.handle_command('<get_vts vt_id="1.2.3.4"></get_vts>'))
158
        print(ET.tostring(response))
159
        # The status of the response must be success (i.e. 200)
160
        self.assertEqual(response.get('status'), '200')
161
        # The response root element must have the correct name
162
        self.assertEqual(response.tag, 'get_vts_response')
163
        # The response must contain a 'scanner_params' element
164
        self.assertIsNotNone(response.find('vts'))
165
        vt_params = response[0][0].findall('vt_params')
166
        self.assertEqual(1, len(vt_params))
167
        custom = response[0][0].findall('custom')
168
        self.assertEqual(1, len(custom))
169
        params = response.findall('vts/vt/vt_params/vt_param')
170
        self.assertEqual(2, len(params))
171
172 View Code Duplication
    def testGetVTs_VTs_with_refs(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name testGetVTs_VTs_with_refs does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
173
        daemon = DummyWrapper([])
174
        daemon.add_vt('1.2.3.4',
175
                      'A vulnerability test',
176
                      vt_params="a",
177
                      custom="b",
178
                      vt_refs="c")
179
        response = secET.fromstring(
180
            daemon.handle_command('<get_vts vt_id="1.2.3.4"></get_vts>'))
181
        print(ET.tostring(response))
182
        # The status of the response must be success (i.e. 200)
183
        self.assertEqual(response.get('status'), '200')
184
        # The response root element must have the correct name
185
        self.assertEqual(response.tag, 'get_vts_response')
186
        # The response must contain a 'vts' element
187
        self.assertIsNotNone(response.find('vts'))
188
        vt_params = response[0][0].findall('vt_params')
189
        self.assertEqual(1, len(vt_params))
190
        custom = response[0][0].findall('custom')
191
        self.assertEqual(1, len(custom))
192
        refs = response.findall('vts/vt/vt_refs/ref')
193
        self.assertEqual(2, len(refs))
194
195
    def testiScanWithError(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testiScanWithError does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
196
        daemon = DummyWrapper([
197
            Result('error', value='something went wrong'),
198
        ])
199
200
        response = secET.fromstring(daemon.handle_command('<start_scan target="localhost" ports="80, 443"><scanner_params /></start_scan>'))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (140/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
201
        print(ET.tostring(response))
202
        scan_id = response.findtext('id')
203
        finished = False
204
        while not finished:
205
            response = secET.fromstring(daemon.handle_command('<get_scans scan_id="%s" details="0"/>' % scan_id))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
206
            print(ET.tostring(response))
207
            scans = response.findall('scan')
208
            self.assertEqual(1, len(scans))
209
            scan = scans[0]
210
            if int(scan.get('progress')) != 100:
211
                self.assertEqual('0', scan.get('end_time'))
212
                time.sleep(.010)
213
            else:
214
                finished = True
215
        response = secET.fromstring(daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
216
        print(ET.tostring(response))
217
        response = secET.fromstring(daemon.handle_command('<get_scans />'))
218
        print(ET.tostring(response))
219
        response = secET.fromstring(daemon.handle_command('<get_scans scan_id="%s" details="1"/>' % scan_id))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
220
        self.assertEqual(response.findtext('scan/results/result'), 'something went wrong')
221
        print(ET.tostring(response))
222
223
        response = secET.fromstring(daemon.handle_command('<delete_scan scan_id="%s" />' % scan_id))
224
        self.assertEqual(response.get('status'), '200')
225
        print(ET.tostring(response))
226
227
228
    def testGetScanPop(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testGetScanPop does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
229
        daemon = DummyWrapper([
230
            Result('host-detail', value='Some Host Detail'),
231
        ])
232
233
        response = secET.fromstring(daemon.handle_command('<start_scan target="localhost" ports="80, 443"><scanner_params /></start_scan>'))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (140/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
234
        print(ET.tostring(response))
235
        scan_id = response.findtext('id')
236
        time.sleep(1)
237
238
        response = secET.fromstring(
239
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
240
        self.assertEqual(response.findtext('scan/results/result'),
241
                         'Some Host Detail')
242
243
        response = secET.fromstring(
244
            daemon.handle_command(
245
                '<get_scans details="0" pop_results="1"/>'))
246
        self.assertEqual(response.findtext('scan/results/result'),
247
                         None)
248
249
        response = secET.fromstring(
250
            daemon.handle_command(
251
                '<get_scans scan_id="%s" pop_results="1"/>' % scan_id))
252
        self.assertEqual(response.findtext('scan/results/result'),
253
                         'Some Host Detail')
254
255
        response = secET.fromstring(
256
            daemon.handle_command(
257
                '<get_scans scan_id="%s" pop_results="1"/>' % scan_id))
258
        self.assertNotEqual(response.findtext('scan/results/result'),
259
                         'Some Host Detail')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 3 spaces).
Loading history...
260
        self.assertEqual(response.findtext('scan/results/result'),
261
                         None)
262
263
        while True:
264
            response = secET.fromstring(
265
                daemon.handle_command(
266
                    '<get_scans scan_id="%s" details="0"/>' % scan_id))
267
            scans = response.findall('scan')
268
            self.assertEqual(1, len(scans))
269
            scan = scans[0]
270
            if int(scan.get('progress')) == 100:
271
                break
272
273
        response = secET.fromstring(
274
            daemon.handle_command('<delete_scan scan_id="%s" />' % scan_id))
275
        self.assertEqual(response.get('status'), '200')
276
        print(ET.tostring(response))
277
278
279
    def testStopScan(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testStopScan does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
280
        daemon = DummyWrapper([])
281
        response = secET.fromstring(
282
            daemon.handle_command('<start_scan ' +
283
                                  'target="localhost" ports="80, 443">' +
284
                                  '<scanner_params /></start_scan>'))
285
        print(ET.tostring(response))
286
        scan_id = response.findtext('id')
287
288
        # Depending on the sistem this test can end with a race condition
289
        # because the scanner is already stopped when the <stop_scan> commmand
290
        # is run.
291
        time.sleep(3)
292
        cmd = secET.fromstring('<stop_scan scan_id="%s" />' % scan_id)
293
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
294
295
        cmd = secET.fromstring('<stop_scan />')
296
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
297
298
299
    def testScanWithVTs(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testScanWithVTs does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
300
        daemon = DummyWrapper([])
301
        cmd = secET.fromstring('<start_scan ' +
302
                               'target="localhost" ports="80, 443">' +
303
                               '<scanner_params /><vt_selection /></start_scan>')
304
        print(ET.tostring(cmd))
305
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
306
307
        # With one VT, without params
308
        response = secET.fromstring(
309
            daemon.handle_command('<start_scan ' +
310
                                  'target="localhost" ports="80, 443">' +
311
                                  '<scanner_params /><vt_selection><vt_single id="1.2.3.4" />' +
312
                                  '</vt_selection></start_scan>'))
313
        print(ET.tostring(response))
314
        scan_id = response.findtext('id')
315
        time.sleep(0.01)
316
        self.assertEqual(daemon.get_scan_vts(scan_id), {'1.2.3.4': {}, 'vt_groups': []})
317
        self.assertNotEqual(daemon.get_scan_vts(scan_id), {'1.2.3.6': {}})
318
319
        # With out VTS
320
        response = secET.fromstring(
321
            daemon.handle_command('<start_scan ' +
322
                                  'target="localhost" ports="80, 443">' +
323
                                  '<scanner_params /></start_scan>'))
324
        print(ET.tostring(response))
325
        scan_id = response.findtext('id')
326
        time.sleep(0.01)
327
        self.assertEqual(daemon.get_scan_vts(scan_id), {})
328
329
    def testScanWithVTs_and_param(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testScanWithVTs_and_param does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
330
        daemon = DummyWrapper([])
331
332
        # Raise because no vt_param id attribute
333
        cmd = secET.fromstring('<start_scan ' +
334
                               'target="localhost" ports="80, 443">' +
335
                               '<scanner_params /><vt_selection><vt_single id="1234">' +
336
                               '<vt_value>200</vt_value>' +
337
                               '</vt_single></vt_selection></start_scan>')
338
        print(ET.tostring(cmd))
339
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
340
341
        # No error
342
        response = secET.fromstring(
343
            daemon.handle_command('<start_scan ' +
344
                                  'target="localhost" ports="80, 443">' +
345
                                  '<scanner_params /><vt_selection><vt_single id="1234">' +
346
                                  '<vt_value id="ABC">200' +
347
                                  '</vt_value></vt_single></vt_selection></start_scan>'))
348
        print(ET.tostring(response))
349
        scan_id = response.findtext('id')
350
        time.sleep(0.01)
351
        self.assertEqual(daemon.get_scan_vts(scan_id),
352
                         {'1234': {'ABC': '200'}, 'vt_groups': []})
353
354
355
        # Raise because no vtgroup filter attribute
356
        cmd = secET.fromstring('<start_scan ' +
357
                               'target="localhost" ports="80, 443">' +
358
                               '<scanner_params /><vt_selection><vt_group/>' +
359
                               '</vt_selection></start_scan>')
360
        print(ET.tostring(cmd))
361
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
362
363
        # No error
364
        response = secET.fromstring(
365
            daemon.handle_command('<start_scan ' +
366
                                  'target="localhost" ports="80, 443">' +
367
                                  '<scanner_params /><vt_selection>' +
368
                                  '<vt_group filter="a"/>' +
369
                                  '</vt_selection></start_scan>'))
370
        print(ET.tostring(response))
371
        scan_id = response.findtext('id')
372
        time.sleep(0.01)
373
        self.assertEqual(daemon.get_scan_vts(scan_id),
374
                         {'vt_groups': ['a']})
375
376
377
    def testBillonLaughs(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testBillonLaughs does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
378
        daemon = DummyWrapper([])
379
        lol = ('<?xml version="1.0"?>' +
380
               '<!DOCTYPE lolz [' +
381
               ' <!ENTITY lol "lol">' +
382
               ' <!ELEMENT lolz (#PCDATA)>' +
383
               ' <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">' +
384
               ' <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">' +
385
               ' <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">' +
386
               ' <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">' +
387
               ' <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">' +
388
               ' <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">' +
389
               ' <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">' +
390
               ' <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">' +
391
               ' <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">' +
392
               ']>')
393
        self.assertRaises(EntitiesForbidden, daemon.handle_command, lol)
394
395
    def testScanMultiTarget(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testScanMultiTarget does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
396
        daemon = DummyWrapper([])
397
        response = secET.fromstring(
398
            daemon.handle_command('<start_scan>' +
399
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
400
                                  '</vts>' +
401
                                  '<targets><target>' +
402
                                  '<hosts>localhosts</hosts>' +
403
                                  '<ports>80,443</ports>' +
404
                                  '</target>' +
405
                                  '<target><hosts>192.168.0.0/24</hosts>' +
406
                                  '<ports>22</ports></target></targets>' +
407
                                  '</start_scan>'))
408
        print(ET.tostring(response))
409
        self.assertEqual(response.get('status'), '200')
410
411
412
    def testMultiTargetWithCredentials(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testMultiTargetWithCredentials does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
413
        daemon = DummyWrapper([])
414
        response = secET.fromstring(
415
            daemon.handle_command('<start_scan>' +
416
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
417
                                  '</vts>' +
418
                                  '<targets><target><hosts>localhosts</hosts>' +
419
                                  '<ports>80,443</ports></target><target>' +
420
                                  '<hosts>192.168.0.0/24</hosts><ports>22' +
421
                                  '</ports><credentials>' +
422
                                  '<credential type="up" service="ssh" port="22">' +
423
                                  '<username>scanuser</username>' +
424
                                  '<password>mypass</password>' +
425
                                  '</credential><credential type="up" service="smb">' +
426
                                  '<username>smbuser</username>' +
427
                                  '<password>mypass</password></credential>' +
428
                                  '</credentials>' +
429
                                  '</target></targets>' +
430
                                  '</start_scan>'))
431
        print(ET.tostring(response))
432
        self.assertEqual(response.get('status'), '200')
433
        cred_dict = {'ssh': {'type': 'up', 'password':
434
                    'mypass', 'port': '22', 'username':
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
435
                    'scanuser'}, 'smb': {'type': 'up',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
436
                    'password': 'mypass', 'username': 'smbuser'}}
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 21 spaces).
Loading history...
437
        scan_id = response.findtext('id')
438
        response = daemon.get_scan_credentials(scan_id, "192.168.0.0/24")
439
        self.assertEqual(response, cred_dict)
440
441
    def testScanGetTarget(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testScanGetTarget does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
442
        daemon = DummyWrapper([])
443
        response = secET.fromstring(
444
            daemon.handle_command('<start_scan>' +
445
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
446
                                  '</vts>' +
447
                                  '<targets><target>' +
448
                                  '<hosts>localhosts</hosts>' +
449
                                  '<ports>80,443</ports>' +
450
                                  '</target>' +
451
                                  '<target><hosts>192.168.0.0/24</hosts>' +
452
                                  '<ports>22</ports></target></targets>' +
453
                                  '</start_scan>'))
454
        scan_id = response.findtext('id')
455
        response = secET.fromstring(
456
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
457
        print(ET.tostring(response))
458
        scan_res = response.find('scan')
459
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
460
461
    def testScanGetLegacyTarget(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testScanGetLegacyTarget does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
462
        daemon = DummyWrapper([])
463
464
        response = secET.fromstring(
465
            daemon.handle_command('<start_scan target="localhosts,192.168.0.0/24" ports="22">' +
466
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
467
                                  '</vts>' +
468
                                  '</start_scan>'))
469
        scan_id = response.findtext('id')
470
        response = secET.fromstring(
471
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
472
        print(ET.tostring(response))
473
        scan_res = response.find('scan')
474
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
475
476
    def testScanMultiTargetParallelWithError(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testScanMultiTargetParallelWithError does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
477
        daemon = DummyWrapper([])
478
        cmd = secET.fromstring('<start_scan parallel="100a">' +
479
                               '<scanner_params />' +
480
                               '<targets><target>' +
481
                               '<hosts>localhosts</hosts>' +
482
                               '<ports>22</ports>' +
483
                               '</target></targets>' +
484
                               '</start_scan>')
485
        time.sleep(1)
486
        print(ET.tostring(cmd))
487
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
488
489
    def testScanMultiTargetParallel100(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testScanMultiTargetParallel100 does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
490
        daemon = DummyWrapper([])
491
        response = secET.fromstring(
492
            daemon.handle_command('<start_scan parallel="100">' +
493
                                  '<scanner_params />' +
494
                                  '<targets><target>' +
495
                                  '<hosts>localhosts</hosts>' +
496
                                  '<ports>22</ports>' +
497
                                  '</target></targets>' +
498
                                  '</start_scan>'))
499
        time.sleep(1)
500
        print(ET.tostring(response))
501
        self.assertEqual(response.get('status'), '200')
502
503
    def testProgress(self):
0 ignored issues
show
Coding Style Naming introduced by
The name testProgress does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
504
        daemon = DummyWrapper([])
505
        response = secET.fromstring(
506
            daemon.handle_command('<start_scan parallel="2">' +
507
                                  '<scanner_params />' +
508
                                  '<targets><target>' +
509
                                  '<hosts>localhost1</hosts>' +
510
                                  '<ports>22</ports>' +
511
                                  '</target><target>' +
512
                                  '<hosts>localhost2</hosts>' +
513
                                  '<ports>22</ports>' +
514
                                  '</target></targets>' +
515
                                  '</start_scan>'))
516
        scan_id = response.findtext('id')
517
        daemon.set_scan_target_progress(scan_id, 'localhost1', 75)
518
        daemon.set_scan_target_progress(scan_id, 'localhost2', 25)
519
        self.assertEqual(daemon.calculate_progress(scan_id), 50)
520