Passed
Pull Request — master (#42)
by
unknown
01:26
created

FullTest.testGetVTs_multiple_VTs()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nop 1
dl 0
loc 10
rs 9.9
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_error(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...
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
    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...
180
        daemon = DummyWrapper([])
181
        response = secET.fromstring(
182
            daemon.handle_command('<start_scan ' +
183
                                  'target="localhost" ports="80, 443">' +
184
                                  '<scanner_params /></start_scan>'))
185
        print(ET.tostring(response))
186
        scan_id = response.findtext('id')
187
188
        # Depending on the sistem this test can end with a race condition
189
        # because the scanner is already stopped when the <stop_scan> commmand
190
        # is run.
191
        time.sleep(3)
192
        cmd = secET.fromstring('<stop_scan scan_id="%s" />' % scan_id)
193
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
194
195
        cmd = secET.fromstring('<stop_scan />')
196
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
197
198
199
    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...
200
        daemon = DummyWrapper([])
201
        cmd = secET.fromstring('<start_scan ' +
202
                               'target="localhost" ports="80, 443">' +
203
                               '<scanner_params /><vts /></start_scan>')
204
        print(ET.tostring(cmd))
205
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
206
207
        # With one VT, without params
208
        response = secET.fromstring(
209
            daemon.handle_command('<start_scan ' +
210
                                  'target="localhost" ports="80, 443">' +
211
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
212
                                  '</vts></start_scan>'))
213
        print(ET.tostring(response))
214
        scan_id = response.findtext('id')
215
        time.sleep(0.01)
216
        self.assertEqual(daemon.get_scan_vts(scan_id), {'1.2.3.4': {}})
217
        self.assertNotEqual(daemon.get_scan_vts(scan_id), {'1.2.3.6': {}})
218
219
        # With out VTS
220
        response = secET.fromstring(
221
            daemon.handle_command('<start_scan ' +
222
                                  'target="localhost" ports="80, 443">' +
223
                                  '<scanner_params /></start_scan>'))
224
        print(ET.tostring(response))
225
        scan_id = response.findtext('id')
226
        time.sleep(0.01)
227
        self.assertEqual(daemon.get_scan_vts(scan_id), {})
228
229
    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...
230
        daemon = DummyWrapper([])
231
232
        # Raise because no vt_param name attribute
233
        cmd = secET.fromstring('<start_scan ' +
234
                               'target="localhost" ports="80, 443">' +
235
                               '<scanner_params /><vts><vt id="1234">' +
236
                               '<vt_param type="entry">200</vt_param>' +
237
                               '</vt></vts></start_scan>')
238
        print(ET.tostring(cmd))
239
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
240
241
        # No error
242
        response = secET.fromstring(
243
            daemon.handle_command('<start_scan ' +
244
                                  'target="localhost" ports="80, 443">' +
245
                                  '<scanner_params /><vts><vt id="1234">' +
246
                                  '<vt_param name="ABC" type="entry">200' +
247
                                  '</vt_param></vt></vts></start_scan>'))
248
        print(ET.tostring(response))
249
        scan_id = response.findtext('id')
250
        time.sleep(0.01)
251
        self.assertEqual(daemon.get_scan_vts(scan_id),
252
                         {'1234': {'ABC': {'type': 'entry', 'value': '200'}}})
253
254
    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...
255
        daemon = DummyWrapper([])
256
        lol = ('<?xml version="1.0"?>' +
257
               '<!DOCTYPE lolz [' +
258
               ' <!ENTITY lol "lol">' +
259
               ' <!ELEMENT lolz (#PCDATA)>' +
260
               ' <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">' +
261
               ' <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">' +
262
               ' <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">' +
263
               ' <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">' +
264
               ' <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">' +
265
               ' <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">' +
266
               ' <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">' +
267
               ' <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">' +
268
               ' <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">' +
269
               ']>')
270
        self.assertRaises(EntitiesForbidden, daemon.handle_command, lol)
271
272
    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...
273
        daemon = DummyWrapper([])
274
        response = secET.fromstring(
275
            daemon.handle_command('<start_scan>' +
276
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
277
                                  '</vts>' +
278
                                  '<targets><target>' +
279
                                  '<hosts>localhosts</hosts>' +
280
                                  '<ports>80,443</ports>' +
281
                                  '</target>' +
282
                                  '<target><hosts>192.168.0.0/24</hosts>' +
283
                                  '<ports>22</ports></target></targets>' +
284
                                  '</start_scan>'))
285
        print(ET.tostring(response))
286
        self.assertEqual(response.get('status'), '200')
287
288
289
    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...
290
        daemon = DummyWrapper([])
291
        response = secET.fromstring(
292
            daemon.handle_command('<start_scan>' +
293
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
294
                                  '</vts>' +
295
                                  '<targets><target><hosts>localhosts</hosts>' +
296
                                  '<ports>80,443</ports></target><target>' +
297
                                  '<hosts>192.168.0.0/24</hosts><ports>22' +
298
                                  '</ports><credentials>' +
299
                                  '<credential type="up" service="ssh" port="22">' +
300
                                  '<username>scanuser</username>' +
301
                                  '<password>mypass</password>' +
302
                                  '</credential><credential type="up" service="smb">' +
303
                                  '<username>smbuser</username>' +
304
                                  '<password>mypass</password></credential>' +
305
                                  '</credentials>' +
306
                                  '</target></targets>' +
307
                                  '</start_scan>'))
308
        print(ET.tostring(response))
309
        self.assertEqual(response.get('status'), '200')
310
        cred_dict = {'ssh': {'type': 'up', 'password':
311
                    'mypass', 'port': '22', 'username':
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
312
                    'scanuser'}, 'smb': {'type': 'up',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
313
                    'password': 'mypass', 'username': 'smbuser'}}
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 21 spaces).
Loading history...
314
        scan_id = response.findtext('id')
315
        response = daemon.get_scan_credentials(scan_id, "192.168.0.0/24")
316
        self.assertEqual(response, cred_dict)
317
318
    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...
319
        daemon = DummyWrapper([])
320
        response = secET.fromstring(
321
            daemon.handle_command('<start_scan>' +
322
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
323
                                  '</vts>' +
324
                                  '<targets><target>' +
325
                                  '<hosts>localhosts</hosts>' +
326
                                  '<ports>80,443</ports>' +
327
                                  '</target>' +
328
                                  '<target><hosts>192.168.0.0/24</hosts>' +
329
                                  '<ports>22</ports></target></targets>' +
330
                                  '</start_scan>'))
331
        scan_id = response.findtext('id')
332
        response = secET.fromstring(
333
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
334
        print(ET.tostring(response))
335
        scan_res = response.find('scan')
336
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
337
338
    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...
339
        daemon = DummyWrapper([])
340
341
        response = secET.fromstring(
342
            daemon.handle_command('<start_scan target="localhosts,192.168.0.0/24" ports="22">' +
343
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
344
                                  '</vts>' +
345
                                  '</start_scan>'))
346
        scan_id = response.findtext('id')
347
        response = secET.fromstring(
348
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
349
        print(ET.tostring(response))
350
        scan_res = response.find('scan')
351
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
352
353
    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...
354
        daemon = DummyWrapper([])
355
        cmd = secET.fromstring('<start_scan parallel="100a">' +
356
                               '<scanner_params />' +
357
                               '<targets><target>' +
358
                               '<hosts>localhosts</hosts>' +
359
                               '<ports>22</ports>' +
360
                               '</target></targets>' +
361
                               '</start_scan>')
362
        time.sleep(1)
363
        print(ET.tostring(cmd))
364
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
365
366
    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...
367
        daemon = DummyWrapper([])
368
        cmd = response = secET.fromstring(
369
            daemon.handle_command('<start_scan parallel="100">' +
370
                                  '<scanner_params />' +
371
                                  '<targets><target>' +
372
                                  '<hosts>localhosts</hosts>' +
373
                                  '<ports>22</ports>' +
374
                                  '</target></targets>' +
375
                                  '</start_scan>'))
376
        time.sleep(1)
377
        print(ET.tostring(cmd))
378
        self.assertEqual(response.get('status'), '200')
379
0 ignored issues
show
coding-style introduced by
Trailing newlines
Loading history...
380