def test__run_scan(self, mock_nmap_factory): mock_nmap = MagicMock() mock_nmap_factory.return_value = mock_nmap mock_nmap.run.return_value = 0 mock_nmap.stdout = MOCK_SCAN_RESULT now = datetime(2015, 11, 4) res = [r for r in _run_scan(['1.1.1.1', '2.2.2.2'], now)] self.assertEquals(res, [ { 'observation_type': 'scan_observation_v1', 'time': now.isoformat(), 'source': '192.168.1.42', 'ports': '', 'info_type': 'services', 'result': '', }, { 'observation_type': 'scan_observation_v1', 'time': now.isoformat(), 'source': '192.168.1.1', 'ports': '22/closed, 80/open, 443/open', 'info_type': 'services', 'result': '', }, ])
def test__run_scan__bad_parse(self, mock_nmap_factory): mock_nmap = MagicMock() mock_nmap_factory.return_value = mock_nmap mock_nmap.run.return_value = 0 mock_nmap.stdout = 'foo' now = datetime(2015, 11, 4) self.assertIsNone(_run_scan(['1.1.1.1', '2.2.2.2'], now))
def test__run_scan__bad_parse(self, mock_nmap_factory): mock_nmap = MagicMock() mock_nmap_factory.return_value = mock_nmap mock_nmap.run.return_value = 0 mock_nmap.stdout = 'foo' now = datetime(2015, 11, 4) res = [r for r in _run_scan(['1.1.1.1', '2.2.2.2'], now)] self.assertEquals(res, [])