Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Add unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Sep 3, 2018
1 parent 0584a99 commit 0ece70a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/testSSHDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def testNoParamiko(self):
def testRunCommand(self):
ospd_ssh.paramiko = fakeparamiko
daemon = OSPDaemonSimpleSSH('cert', 'key', 'ca')
scanid = daemon.create_scan(None, ['host.example.com', '80, 443'],
scanid = daemon.create_scan(None, [['host.example.com', '80, 443']], None,
dict(port=5, ssh_timeout=15,
username_password='dummy:pw'), '')
res = daemon.run_command(scanid, 'host.example.com', 'cat /etc/passwd')
Expand Down
37 changes: 37 additions & 0 deletions tests/testScanAndResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def testScanMultiTarget(self):
print(ET.tostring(response))
self.assertEqual(response.get('status'), '200')


def testMultiTargetWithCredentials(self):
daemon = DummyWrapper([])
response = secET.fromstring(
Expand Down Expand Up @@ -295,3 +296,39 @@ def testMultiTargetWithCredentials(self):
scan_id = response.findtext('id')
response = daemon.get_scan_credentials(scan_id, "192.168.0.0/24")
self.assertEqual(response, cred_dict)

def testScanGetTarget(self):
daemon = DummyWrapper([])
response = secET.fromstring(
daemon.handle_command('<start_scan>' +
'<scanner_params /><vts><vt id="1.2.3.4" />' +
'</vts>' +
'<targets><target>' +
'<hosts>localhosts</hosts>' +
'<ports>80,443</ports>' +
'</target>' +
'<target><hosts>192.168.0.0/24</hosts>' +
'<ports>22</ports></target></targets>' +
'</start_scan>'))
scan_id = response.findtext('id')
response = secET.fromstring(
daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
print(ET.tostring(response))
scan_res = response.find('scan')
self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')

def testScanGetLegacyTarget(self):
daemon = DummyWrapper([])

response = secET.fromstring(
daemon.handle_command('<start_scan target="localhosts,192.168.0.0/24" ports="22">' +
'<scanner_params /><vts><vt id="1.2.3.4" />' +
'</vts>' +
'</start_scan>'))
scan_id = response.findtext('id')
response = secET.fromstring(
daemon.handle_command('<get_scans scan_id="%s"/>' % scan_id))
print(ET.tostring(response))
scan_res = response.find('scan')
self.assertEqual(scan_res.get('target'), 'localhosts,192.168.0.0/24')

0 comments on commit 0ece70a

Please sign in to comment.