Passed
Pull Request — master (#54)
by
unknown
01:35
created

FullTest.testGetDefaultScannerVersion()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 1
dl 0
loc 6
rs 10
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
        while True:
216
            response = secET.fromstring(
217
                daemon.handle_command(
218
                    '<get_scans scan_id="%s" details="0"/>' % scan_id))
219
            scans = response.findall('scan')
220
            self.assertEqual(1, len(scans))
221
            scan = scans[0]
222
            if int(scan.get('progress')) == 100:
223
                break
224
225
        response = secET.fromstring(
226
            daemon.handle_command('<delete_scan scan_id="%s" />' % scan_id))
227
        self.assertEqual(response.get('status'), '200')
228
        print(ET.tostring(response))
229
230
231
    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...
232
        daemon = DummyWrapper([])
233
        response = secET.fromstring(
234
            daemon.handle_command('<start_scan ' +
235
                                  'target="localhost" ports="80, 443">' +
236
                                  '<scanner_params /></start_scan>'))
237
        print(ET.tostring(response))
238
        scan_id = response.findtext('id')
239
240
        # Depending on the sistem this test can end with a race condition
241
        # because the scanner is already stopped when the <stop_scan> commmand
242
        # is run.
243
        time.sleep(3)
244
        cmd = secET.fromstring('<stop_scan scan_id="%s" />' % scan_id)
245
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
246
247
        cmd = secET.fromstring('<stop_scan />')
248
        self.assertRaises(OSPDError, daemon.handle_stop_scan_command, cmd)
249
250
251
    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...
252
        daemon = DummyWrapper([])
253
        cmd = secET.fromstring('<start_scan ' +
254
                               'target="localhost" ports="80, 443">' +
255
                               '<scanner_params /><vts /></start_scan>')
256
        print(ET.tostring(cmd))
257
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
258
259
        # With one VT, without params
260
        response = secET.fromstring(
261
            daemon.handle_command('<start_scan ' +
262
                                  'target="localhost" ports="80, 443">' +
263
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
264
                                  '</vts></start_scan>'))
265
        print(ET.tostring(response))
266
        scan_id = response.findtext('id')
267
        time.sleep(0.01)
268
        self.assertEqual(daemon.get_scan_vts(scan_id), {'1.2.3.4': {}, 'vtgroups': []})
269
        self.assertNotEqual(daemon.get_scan_vts(scan_id), {'1.2.3.6': {}})
270
271
        # With out VTS
272
        response = secET.fromstring(
273
            daemon.handle_command('<start_scan ' +
274
                                  'target="localhost" ports="80, 443">' +
275
                                  '<scanner_params /></start_scan>'))
276
        print(ET.tostring(response))
277
        scan_id = response.findtext('id')
278
        time.sleep(0.01)
279
        self.assertEqual(daemon.get_scan_vts(scan_id), {})
280
281
    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...
282
        daemon = DummyWrapper([])
283
284
        # Raise because no vt_param name attribute
285
        cmd = secET.fromstring('<start_scan ' +
286
                               'target="localhost" ports="80, 443">' +
287
                               '<scanner_params /><vts><vt id="1234">' +
288
                               '<vt_param type="entry">200</vt_param>' +
289
                               '</vt></vts></start_scan>')
290
        print(ET.tostring(cmd))
291
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
292
293
        # No error
294
        response = secET.fromstring(
295
            daemon.handle_command('<start_scan ' +
296
                                  'target="localhost" ports="80, 443">' +
297
                                  '<scanner_params /><vts><vt id="1234">' +
298
                                  '<vt_param name="ABC" type="entry">200' +
299
                                  '</vt_param></vt></vts></start_scan>'))
300
        print(ET.tostring(response))
301
        scan_id = response.findtext('id')
302
        time.sleep(0.01)
303
        self.assertEqual(daemon.get_scan_vts(scan_id),
304
                         {'1234': {'ABC': {'type': 'entry', 'value': '200'}}, 'vtgroups': []})
305
306
307
        # Raise because no vtgroup filter attribute
308
        cmd = secET.fromstring('<start_scan ' +
309
                               'target="localhost" ports="80, 443">' +
310
                               '<scanner_params /><vts><vtgroup/>' +
311
                               '</vts></start_scan>')
312
        print(ET.tostring(cmd))
313
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
314
315
        # No error
316
        response = secET.fromstring(
317
            daemon.handle_command('<start_scan ' +
318
                                  'target="localhost" ports="80, 443">' +
319
                                  '<scanner_params /><vts>' +
320
                                  '<vtgroup filter="a"/>' +
321
                                  '</vts></start_scan>'))
322
        print(ET.tostring(response))
323
        scan_id = response.findtext('id')
324
        time.sleep(0.01)
325
        self.assertEqual(daemon.get_scan_vts(scan_id),
326
                         {'vtgroups': ['a']})
327
328
329
    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...
330
        daemon = DummyWrapper([])
331
        lol = ('<?xml version="1.0"?>' +
332
               '<!DOCTYPE lolz [' +
333
               ' <!ENTITY lol "lol">' +
334
               ' <!ELEMENT lolz (#PCDATA)>' +
335
               ' <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">' +
336
               ' <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">' +
337
               ' <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">' +
338
               ' <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">' +
339
               ' <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">' +
340
               ' <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">' +
341
               ' <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">' +
342
               ' <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">' +
343
               ' <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">' +
344
               ']>')
345
        self.assertRaises(EntitiesForbidden, daemon.handle_command, lol)
346
347
    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...
348
        daemon = DummyWrapper([])
349
        response = secET.fromstring(
350
            daemon.handle_command('<start_scan>' +
351
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
352
                                  '</vts>' +
353
                                  '<targets><target>' +
354
                                  '<hosts>localhosts</hosts>' +
355
                                  '<ports>80,443</ports>' +
356
                                  '</target>' +
357
                                  '<target><hosts>192.168.0.0/24</hosts>' +
358
                                  '<ports>22</ports></target></targets>' +
359
                                  '</start_scan>'))
360
        print(ET.tostring(response))
361
        self.assertEqual(response.get('status'), '200')
362
363
364
    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...
365
        daemon = DummyWrapper([])
366
        response = secET.fromstring(
367
            daemon.handle_command('<start_scan>' +
368
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
369
                                  '</vts>' +
370
                                  '<targets><target><hosts>localhosts</hosts>' +
371
                                  '<ports>80,443</ports></target><target>' +
372
                                  '<hosts>192.168.0.0/24</hosts><ports>22' +
373
                                  '</ports><credentials>' +
374
                                  '<credential type="up" service="ssh" port="22">' +
375
                                  '<username>scanuser</username>' +
376
                                  '<password>mypass</password>' +
377
                                  '</credential><credential type="up" service="smb">' +
378
                                  '<username>smbuser</username>' +
379
                                  '<password>mypass</password></credential>' +
380
                                  '</credentials>' +
381
                                  '</target></targets>' +
382
                                  '</start_scan>'))
383
        print(ET.tostring(response))
384
        self.assertEqual(response.get('status'), '200')
385
        cred_dict = {'ssh': {'type': 'up', 'password':
386
                    'mypass', 'port': '22', 'username':
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
387
                    'scanuser'}, 'smb': {'type': 'up',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation in dict value.
Loading history...
388
                    'password': 'mypass', 'username': 'smbuser'}}
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 21 spaces).
Loading history...
389
        scan_id = response.findtext('id')
390
        response = daemon.get_scan_credentials(scan_id, "192.168.0.0/24")
391
        self.assertEqual(response, cred_dict)
392
393
    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...
394
        daemon = DummyWrapper([])
395
        response = secET.fromstring(
396
            daemon.handle_command('<start_scan>' +
397
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
398
                                  '</vts>' +
399
                                  '<targets><target>' +
400
                                  '<hosts>localhosts</hosts>' +
401
                                  '<ports>80,443</ports>' +
402
                                  '</target>' +
403
                                  '<target><hosts>192.168.0.0/24</hosts>' +
404
                                  '<ports>22</ports></target></targets>' +
405
                                  '</start_scan>'))
406
        scan_id = response.findtext('id')
407
        response = secET.fromstring(
408
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
409
        print(ET.tostring(response))
410
        scan_res = response.find('scan')
411
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
412
413
    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...
414
        daemon = DummyWrapper([])
415
416
        response = secET.fromstring(
417
            daemon.handle_command('<start_scan target="localhosts,192.168.0.0/24" ports="22">' +
418
                                  '<scanner_params /><vts><vt id="1.2.3.4" />' +
419
                                  '</vts>' +
420
                                  '</start_scan>'))
421
        scan_id = response.findtext('id')
422
        response = secET.fromstring(
423
            daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
424
        print(ET.tostring(response))
425
        scan_res = response.find('scan')
426
        self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')
427
428
    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...
429
        daemon = DummyWrapper([])
430
        cmd = secET.fromstring('<start_scan parallel="100a">' +
431
                               '<scanner_params />' +
432
                               '<targets><target>' +
433
                               '<hosts>localhosts</hosts>' +
434
                               '<ports>22</ports>' +
435
                               '</target></targets>' +
436
                               '</start_scan>')
437
        time.sleep(1)
438
        print(ET.tostring(cmd))
439
        self.assertRaises(OSPDError, daemon.handle_start_scan_command, cmd)
440
441
    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...
442
        daemon = DummyWrapper([])
443
        response = secET.fromstring(
444
            daemon.handle_command('<start_scan parallel="100">' +
445
                                  '<scanner_params />' +
446
                                  '<targets><target>' +
447
                                  '<hosts>localhosts</hosts>' +
448
                                  '<ports>22</ports>' +
449
                                  '</target></targets>' +
450
                                  '</start_scan>'))
451
        time.sleep(1)
452
        print(ET.tostring(response))
453
        self.assertEqual(response.get('status'), '200')
454
455
    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...
456
        daemon = DummyWrapper([])
457
        response = secET.fromstring(
458
            daemon.handle_command('<start_scan parallel="2">' +
459
                                  '<scanner_params />' +
460
                                  '<targets><target>' +
461
                                  '<hosts>localhost1</hosts>' +
462
                                  '<ports>22</ports>' +
463
                                  '</target><target>' +
464
                                  '<hosts>localhost2</hosts>' +
465
                                  '<ports>22</ports>' +
466
                                  '</target></targets>' +
467
                                  '</start_scan>'))
468
        scan_id = response.findtext('id')
469
        daemon.set_scan_target_progress(scan_id, 'localhost1', 75)
470
        daemon.set_scan_target_progress(scan_id, 'localhost2', 25)
471
        self.assertEqual(daemon.calculate_progress(scan_id), 50)
472