Passed
Pull Request — master (#47)
by
unknown
23:25 queued 22:00
created

FullTest.testScanWithVTs_and_param()   B

Complexity

Conditions 1

Size

Total Lines 46
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 37
nop 1
dl 0
loc 46
rs 8.9919
c 0
b 0
f 0
1
from __future__ import print_function
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...
Coding Style introduced by
This module 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...
2
3
4
import time
5
import unittest
6
import xml.etree.ElementTree as ET
7
import defusedxml.lxml as secET
8
from defusedxml.common import EntitiesForbidden
9
10
from ospd.ospd import OSPDaemon, OSPDError
11
12
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...
13
    def __init__(self, type_, **kwargs):
14
        self.result_type = type_
15
        self.host = ''
16
        self.name = ''
17
        self.value = ''
18
        self.port = ''
19
        self.test_id = ''
20
        self.severity = ''
21
        self.qod = ''
22
        for name, value in kwargs.items():
23
            setattr(self, name, value)
24
25
26
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...
27
    def __init__(self, results, checkresult=True):
28
        OSPDaemon.__init__(self, 'cert', 'key', 'ca')
29
        self.checkresult = checkresult
30
        self.results = results
31
32
    def check(self):
33
        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...
34
35
    def get_custom_vt_as_xml_str(self, custom):
36
        return '<mytest>static test</mytest>'
37
38
    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...
39
        return ('<vt_param id="abc" type="string">'
40
                '<name>ABC</name><description>Test ABC</description><default>yes</default>'
41
                '</vt_param>'
42
                '<vt_param id="def" type="string">'
43
                '<name>DEF</name><description>Test DEF</description><default>no</default>'
44
                '</vt_param>')
45
46
    def exec_scan(self, scan_id, target):
47
        time.sleep(0.01)
48
        for res in self.results:
49
            if res.result_type == 'log':
50
                self.add_scan_log(scan_id, res.host or target, res.name, res.value, res.port)
51
            if res.result_type == 'error':
52
                self.add_scan_error(scan_id, res.host or target, res.name, res.value, res.port)
53
            elif res.result_type == 'host-detail':
54
                self.add_scan_host_detail(scan_id, res.host or target, res.name, res.value)
55
            elif res.result_type == 'alarm':
56
                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...
57
            else:
58
                raise ValueError(res.result_type)
59
60
61
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 (21/20)
Loading history...
62
    # 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...
63
64
    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...
65
        daemon = DummyWrapper([])
66
        response = secET.fromstring(daemon.handle_command('<get_scanner_details />'))
67
        # The status of the response must be success (i.e. 200)
68
        self.assertEqual(response.get('status'), '200')
69
        # The response root element must have the correct name
70
        self.assertEqual(response.tag, 'get_scanner_details_response')
71
        # The response must contain a 'scanner_params' element
72
        print(ET.tostring(response))
73
        self.assertIsNotNone(response.find('scanner_params'))
74
75
    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...
76
        daemon = DummyWrapper([])
77
        response = secET.fromstring(daemon.handle_command('<help />'))
78
        print(ET.tostring(response))
79
        self.assertEqual(response.get('status'), '200')
80
        response = secET.fromstring(daemon.handle_command('<help format="xml" />'))
81
        print(ET.tostring(response))
82
        self.assertEqual(response.get('status'), '200')
83
        self.assertEqual(response.tag, 'help_response')
84
85
    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...
86
        daemon = DummyWrapper([])
87
        response = secET.fromstring(daemon.handle_command('<get_version />'))
88
        print(ET.tostring(response))
89
        self.assertEqual(response.get('status'), '200')
90
        self.assertIsNotNone(response.find('protocol'))
91
92
    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...
93
        daemon = DummyWrapper([])
94
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
95
        print(ET.tostring(response))
96
        self.assertEqual(response.get('status'), '200')
97
        self.assertIsNotNone(response.find('vts'))
98
99
    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...
100
        daemon = DummyWrapper([])
101
        daemon.add_vt('1.2.3.4', 'A vulnerability test')
102
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
103
        print(ET.tostring(response))
104
        self.assertEqual(response.get('status'), '200')
105
        vts = response.find('vts')
106
        self.assertIsNotNone(vts.find('vt'))
107
        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...
108
        self.assertEqual(vt.get('id'), '1.2.3.4')
109
110
    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...
111
        daemon = DummyWrapper([])
112
        daemon.add_vt('1.2.3.4', 'A vulnerability test')
113
        daemon.add_vt('some id', 'Another vulnerability test')
114
        daemon.add_vt('123456789', 'Yet another vulnerability test')
115
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
116
        print(ET.tostring(response))
117
        self.assertEqual(response.get('status'), '200')
118
        vts = response.find('vts')
119
        self.assertIsNotNone(vts.find('vt'))
120
121
    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...
122
        daemon = DummyWrapper([])
123
        daemon.add_vt('1.2.3.4', 'A vulnerability test')
124
        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...
125
        daemon.add_vt('123456789', 'Yet another vulnerability test')
126
        response = secET.fromstring(daemon.handle_command('<get_vts />'))
127
        print(ET.tostring(response))
128
129
    def testGetVTs_VTs_with_params(self):
0 ignored issues
show
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...
130
        daemon = DummyWrapper([])
131
        daemon.add_vt('1.2.3.4', 'A vulnerability test', vt_params="a", custom="b")
132
        response = secET.fromstring(daemon.handle_command('<get_vts vt_id="1.2.3.4"></get_vts>'))
133
        print(ET.tostring(response))
134
        # The status of the response must be success (i.e. 200)
135
        self.assertEqual(response.get('status'), '200')
136
        # The response root element must have the correct name
137
        self.assertEqual(response.tag, 'get_vts_response')
138
        # The response must contain a 'scanner_params' element
139
        self.assertIsNotNone(response.find('vts'))
140
        vt_params = response[0][0].findall('vt_params')
141
        self.assertEqual(1, len(vt_params))
142
        custom = response[0][0].findall('custom')
143
        self.assertEqual(1, len(custom))
144
        params = response.findall('vts/vt/vt_params/vt_param')
145
        self.assertEqual(2, len(params))
146
147
    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...
148
        daemon = DummyWrapper([
149
            Result('error', value='something went wrong'),
150
        ])
151
152
        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...
153
        print(ET.tostring(response))
154
        scan_id = response.findtext('id')
155
        finished = False
156
        while not finished:
157
            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...
158
            print(ET.tostring(response))
159
            scans = response.findall('scan')
160
            self.assertEqual(1, len(scans))
161
            scan = scans[0]
162
            if int(scan.get('progress')) != 100:
163
                self.assertEqual('0', scan.get('end_time'))
164
                time.sleep(.010)
165
            else:
166
                finished = True
167
        response = secET.fromstring(daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
168
        print(ET.tostring(response))
169
        response = secET.fromstring(daemon.handle_command('<get_scans />'))
170
        print(ET.tostring(response))
171
        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...
172
        self.assertEqual(response.findtext('scan/results/result'), 'something went wrong')
173
        print(ET.tostring(response))
174
175
        response = secET.fromstring(daemon.handle_command('<delete_scan scan_id="%s" />' % scan_id))
176
        self.assertEqual(response.get('status'), '200')
177
        print(ET.tostring(response))
178
179
180
    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...
181
        daemon = DummyWrapper([
182
            Result('host-detail', value='Some Host Detail'),
183
        ])
184
185
        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...
186
        print(ET.tostring(response))
187
        scan_id = response.findtext('id')
188
        time.sleep(1)
189
190
        response = secET.fromstring(
191
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
192
        self.assertEqual(response.findtext('scan/results/result'),
193
                         'Some Host Detail')
194
195
        response = secET.fromstring(
196
            daemon.handle_command(
197
                '<get_scans details="0" pop_results="1"/>'))
198
        self.assertEqual(response.findtext('scan/results/result'),
199
                         None)
200
201
        response = secET.fromstring(
202
            daemon.handle_command(
203
                '<get_scans scan_id="%s" pop_results="1"/>' % scan_id))
204
        self.assertEqual(response.findtext('scan/results/result'),
205
                         'Some Host Detail')
206
207
        response = secET.fromstring(
208
            daemon.handle_command(
209
                '<get_scans scan_id="%s" pop_results="1"/>' % scan_id))
210
        self.assertNotEqual(response.findtext('scan/results/result'),
211
                         'Some Host Detail')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 3 spaces).
Loading history...
212
        self.assertEqual(response.findtext('scan/results/result'),
213
                         None)
214
215
        time.sleep(1)
216
        response = secET.fromstring(
217
            daemon.handle_command('<delete_scan scan_id="%s" />' % scan_id))
218
        self.assertEqual(response.get('status'), '200')
219
        print(ET.tostring(response))
220
221
222
    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...
223
        daemon = DummyWrapper([])
224
        response = secET.fromstring(
225
            daemon.handle_command('<start_scan ' +
226
                                  'target="localhost" ports="80, 443">' +
227
                                  '<scanner_params /></start_scan>'))
228
        print(ET.tostring(response))
229
        scan_id = response.findtext('id')
230
231
        # Depending on the sistem this test can end with a race condition
232
        # because the scanner is already stopped when the <stop_scan> commmand
233
        # is run.
234
        time.sleep(3)
235
        cmd = secET.fromstring('<stop_scan scan_id="%s" />' % scan_id)
236
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
237
238
        cmd = secET.fromstring('<stop_scan />')
239
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
240
241
242
    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...
243
        daemon = DummyWrapper([])
244
        cmd = secET.fromstring('<start_scan ' +
245
                               'target="localhost" ports="80, 443">' +
246
                               '<scanner_params /><vts /></start_scan>')
247
        print(ET.tostring(cmd))
248
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
249
250
        # With one VT, without params
251
        response = secET.fromstring(
252
            daemon.handle_command('<start_scan ' +
253
                                  'target="localhost" ports="80, 443">' +
254
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
255
                                  '</vts></start_scan>'))
256
        print(ET.tostring(response))
257
        scan_id = response.findtext('id')
258
        time.sleep(0.01)
259
        self.assertEqual(daemon.get_scan_vts(scan_id), {'1.2.3.4': {}, 'vtgroups': []})
260
        self.assertNotEqual(daemon.get_scan_vts(scan_id), {'1.2.3.6': {}})
261
262
        # With out VTS
263
        response = secET.fromstring(
264
            daemon.handle_command('<start_scan ' +
265
                                  'target="localhost" ports="80, 443">' +
266
                                  '<scanner_params /></start_scan>'))
267
        print(ET.tostring(response))
268
        scan_id = response.findtext('id')
269
        time.sleep(0.01)
270
        self.assertEqual(daemon.get_scan_vts(scan_id), {})
271
272
    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...
273
        daemon = DummyWrapper([])
274
275
        # Raise because no vt_param name attribute
276
        cmd = secET.fromstring('<start_scan ' +
277
                               'target="localhost" ports="80, 443">' +
278
                               '<scanner_params /><vts><vt id="1234">' +
279
                               '<vt_param type="entry">200</vt_param>' +
280
                               '</vt></vts></start_scan>')
281
        print(ET.tostring(cmd))
282
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
283
284
        # No error
285
        response = secET.fromstring(
286
            daemon.handle_command('<start_scan ' +
287
                                  'target="localhost" ports="80, 443">' +
288
                                  '<scanner_params /><vts><vt id="1234">' +
289
                                  '<vt_param name="ABC" type="entry">200' +
290
                                  '</vt_param></vt></vts></start_scan>'))
291
        print(ET.tostring(response))
292
        scan_id = response.findtext('id')
293
        time.sleep(0.01)
294
        self.assertEqual(daemon.get_scan_vts(scan_id),
295
                         {'1234': {'ABC': {'type': 'entry', 'value': '200'}}, 'vtgroups': []})
296
297
298
        # Raise because no vtgroup filter attribute
299
        cmd = secET.fromstring('<start_scan ' +
300
                               'target="localhost" ports="80, 443">' +
301
                               '<scanner_params /><vts><vtgroup/>' +
302
                               '</vts></start_scan>')
303
        print(ET.tostring(cmd))
304
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
305
306
        # No error
307
        response = secET.fromstring(
308
            daemon.handle_command('<start_scan ' +
309
                                  'target="localhost" ports="80, 443">' +
310
                                  '<scanner_params /><vts>' +
311
                                  '<vtgroup filter="a"/>' +
312
                                  '</vts></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),
317
                         {'vtgroups': ['a']})
318
319
320
    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...
321
        daemon = DummyWrapper([])
322
        lol = ('<?xml version="1.0"?>' +
323
               '<!DOCTYPE lolz [' +
324
               ' <!ENTITY lol "lol">' +
325
               ' <!ELEMENT lolz (#PCDATA)>' +
326
               ' <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">' +
327
               ' <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">' +
328
               ' <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">' +
329
               ' <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">' +
330
               ' <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">' +
331
               ' <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">' +
332
               ' <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">' +
333
               ' <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">' +
334
               ' <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">' +
335
               ']>')
336
        self.assertRaises(EntitiesForbidden, daemon.handle_command, lol)
337
338
    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...
339
        daemon = DummyWrapper([])
340
        response = secET.fromstring(
341
            daemon.handle_command('<start_scan>' +
342
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
343
                                  '</vts>' +
344
                                  '<targets><target>' +
345
                                  '<hosts>localhosts</hosts>' +
346
                                  '<ports>80,443</ports>' +
347
                                  '</target>' +
348
                                  '<target><hosts>192.168.0.0/24</hosts>' +
349
                                  '<ports>22</ports></target></targets>' +
350
                                  '</start_scan>'))
351
        print(ET.tostring(response))
352
        self.assertEqual(response.get('status'), '200')
353
354
355
    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...
356
        daemon = DummyWrapper([])
357
        response = secET.fromstring(
358
            daemon.handle_command('<start_scan>' +
359
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
360
                                  '</vts>' +
361
                                  '<targets><target><hosts>localhosts</hosts>' +
362
                                  '<ports>80,443</ports></target><target>' +
363
                                  '<hosts>192.168.0.0/24</hosts><ports>22' +
364
                                  '</ports><credentials>' +
365
                                  '<credential type="up" service="ssh" port="22">' +
366
                                  '<username>scanuser</username>' +
367
                                  '<password>mypass</password>' +
368
                                  '</credential><credential type="up" service="smb">' +
369
                                  '<username>smbuser</username>' +
370
                                  '<password>mypass</password></credential>' +
371
                                  '</credentials>' +
372
                                  '</target></targets>' +
373
                                  '</start_scan>'))
374
        print(ET.tostring(response))
375
        self.assertEqual(response.get('status'), '200')
376
        cred_dict = {'ssh': {'type': 'up', 'password':
377
                    'mypass', 'port': '22', 'username':
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
378
                    'scanuser'}, 'smb': {'type': 'up',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
379
                    'password': 'mypass', 'username': 'smbuser'}}
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 21 spaces).
Loading history...
380
        scan_id = response.findtext('id')
381
        response = daemon.get_scan_credentials(scan_id, "192.168.0.0/24")
382
        self.assertEqual(response, cred_dict)
383
384
    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...
385
        daemon = DummyWrapper([])
386
        response = secET.fromstring(
387
            daemon.handle_command('<start_scan>' +
388
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
389
                                  '</vts>' +
390
                                  '<targets><target>' +
391
                                  '<hosts>localhosts</hosts>' +
392
                                  '<ports>80,443</ports>' +
393
                                  '</target>' +
394
                                  '<target><hosts>192.168.0.0/24</hosts>' +
395
                                  '<ports>22</ports></target></targets>' +
396
                                  '</start_scan>'))
397
        scan_id = response.findtext('id')
398
        response = secET.fromstring(
399
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
400
        print(ET.tostring(response))
401
        scan_res = response.find('scan')
402
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
403
404
    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...
405
        daemon = DummyWrapper([])
406
407
        response = secET.fromstring(
408
            daemon.handle_command('<start_scan target="localhosts,192.168.0.0/24" ports="22">' +
409
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
410
                                  '</vts>' +
411
                                  '</start_scan>'))
412
        scan_id = response.findtext('id')
413
        response = secET.fromstring(
414
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
415
        print(ET.tostring(response))
416
        scan_res = response.find('scan')
417
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
418
419
    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...
420
        daemon = DummyWrapper([])
421
        cmd = secET.fromstring('<start_scan parallel="100a">' +
422
                               '<scanner_params />' +
423
                               '<targets><target>' +
424
                               '<hosts>localhosts</hosts>' +
425
                               '<ports>22</ports>' +
426
                               '</target></targets>' +
427
                               '</start_scan>')
428
        time.sleep(1)
429
        print(ET.tostring(cmd))
430
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
431
432
    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...
433
        daemon = DummyWrapper([])
434
        response = secET.fromstring(
435
            daemon.handle_command('<start_scan parallel="100">' +
436
                                  '<scanner_params />' +
437
                                  '<targets><target>' +
438
                                  '<hosts>localhosts</hosts>' +
439
                                  '<ports>22</ports>' +
440
                                  '</target></targets>' +
441
                                  '</start_scan>'))
442
        time.sleep(1)
443
        print(ET.tostring(response))
444
        self.assertEqual(response.get('status'), '200')
445
446
    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...
447
        daemon = DummyWrapper([])
448
        response = secET.fromstring(
449
            daemon.handle_command('<start_scan parallel="2">' +
450
                                  '<scanner_params />' +
451
                                  '<targets><target>' +
452
                                  '<hosts>localhost1</hosts>' +
453
                                  '<ports>22</ports>' +
454
                                  '</target><target>' +
455
                                  '<hosts>localhost2</hosts>' +
456
                                  '<ports>22</ports>' +
457
                                  '</target></targets>' +
458
                                  '</start_scan>'))
459
        scan_id = response.findtext('id')
460
        daemon.set_scan_target_progress(scan_id, 'localhost1', 75)
461
        daemon.set_scan_target_progress(scan_id, 'localhost2', 25)
462
        self.assertEqual(daemon.calculate_progress(scan_id), 50)
463