def test_diff_between_different_hosts(self): """ This test case creates a host and the compares it with another different host using the ModelObjectDiff class """ h1 = Host(name='host1', os='Windows') h2 = Host(name='host1', os='Linux') diff = ModelObjectDiff(h1, h2) self.assertTrue(diff.existDiff())
def testAddInterfaceGetsMapperDispatchSaveSYNC(self): host = Host('coco') interface = Interface("int_mock0") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(interface.class_signature).thenReturn(objectMapper) when(objectMapper).save(interface).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.addInterfaceSYNC(host.getID(), interface) verify(mappersManager).getMapper(interface.class_signature) verify(objectMapper).save(interface)
def testAddNoteToModelObjectSYNC(self): host = Host("pepito") note = ModelObjectNote("a_note") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(note.class_signature).thenReturn(objectMapper) when(objectMapper).save(note).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.addNoteSYNC(host.getID(), note) verify(mappersManager).getMapper(note.class_signature) verify(objectMapper).save(note)
def testAddVulnToHostGetsMapperDispatchSaveSYNC(self): host = Host("pepito") vuln = ModelObjectVuln("a_vuln") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(vuln.class_signature).thenReturn(objectMapper) when(objectMapper).save(vuln).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.addVulnToHostSYNC(host.getID(), vuln) verify(mappersManager).getMapper(vuln.class_signature) verify(objectMapper).save(vuln)
def testGetHost(self): host = Host("coquito") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(host.__class__.__name__).thenReturn(objectMapper) when(objectMapper).find(host.getName()).thenReturn(host) model_controller = controller.ModelController(mock(), mappersManager) host_obt = model_controller.getHost('coquito') verify(objectMapper).find(host.getName()) verify(mappersManager).getMapper(host.__class__.__name__) self.assertEqual(host, host_obt)
def testAddNoteToHostGetsMapperDispatchSaveASYNC(self): host = Host("pepito") note = ModelObjectNote("a_note") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(note.class_signature).thenReturn(objectMapper) when(objectMapper).save(note).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.addNoteToHostASYNC(host.getID(), note) model_controller.processAllPendingActions() verify(mappersManager).getMapper(note.class_signature) verify(objectMapper).save(note)
def testAddObjectSavesChildInParent(self): host = Host('coco') interface = Interface("int_mock0") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(interface.class_signature).thenReturn(objectMapper) when(objectMapper).save(interface).thenReturn(True) when(mappersManager).find(host.getID()).thenReturn(host) model_controller = controller.ModelController(mock(), mappersManager) model_controller.addInterfaceSYNC(host.getID(), interface) verify(mappersManager).getMapper(interface.class_signature) verify(objectMapper).save(interface) self.assertEquals(interface, host.findChild(interface.getID()), "Orphan child, what happen papi?")
def testAddSavesObjectNameInTrie(self): host = Host('coco') mappersManager = self.createMapperMock() objectMapper = mock() triemock = mock() when(mappersManager).getMapper(host.class_signature).thenReturn(objectMapper) when(objectMapper).save(host).thenReturn(True) when(triemock).addWord(host.getName()).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.treeWordsTries = triemock model_controller.addHostSYNC(host) verify(mappersManager).getMapper(host.class_signature) verify(objectMapper).save(host) verify(triemock).addWord(host.getName())
def testAddHostGetsMapperDispatchSaveSYNC(self): host = Host('coco') mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(host.class_signature).thenReturn(objectMapper) when(objectMapper).save(host).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.addHostSYNC(host) verify(mappersManager).getMapper(host.class_signature) verify(objectMapper).save(host)
def testDeleteHostObjectDispatchRemoveSYNC(self): host = Host("coquito") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).find(host.getID()).thenReturn(host) when(mappersManager).remove(host.getID()).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.delHostSYNC(host.getID()) verify(mappersManager).remove(host.getID()) verify(mappersManager).find(host.getID())
def testGetAllHosts(self): hosts = [ Host("coquito%i" % i ) for i in range(10)] mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(Host.__name__).thenReturn(objectMapper) when(objectMapper).getAll().thenReturn(hosts) model_controller = controller.ModelController(mock(), mappersManager) hosts_obt = model_controller.getAllHosts() verify(objectMapper).getAll() verify(mappersManager).getMapper(Host.__name__) self.assertListEqual(hosts, hosts_obt)
def testAddCredGetsMapperDispatchSaveSYNC(self): host = Host("pepito") cred = ModelObjectCred("usr", "pass") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(cred.class_signature).thenReturn(objectMapper) when(objectMapper).save(cred).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.addCredSYNC(cred.getID(), cred) verify(mappersManager).getMapper(cred.class_signature) verify(objectMapper).save(cred)
def testDelRemovesObjectFromTrie(self): host = Host("coquito") mappersManager = self.createMapperMock() objectMapper = mock() triemock = mock() when(mappersManager).getMapper(host.class_signature).thenReturn(objectMapper) when(mappersManager).find(host.getID()).thenReturn(host) when(triemock).addWord(host.getName()).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.treeWordsTries = triemock model_controller.delHostSYNC(host.getID()) verify(mappersManager).remove(host.getID()) verify(triemock).removeWord(host.getName())
def testEditHostSyncGetsMapperDispatchedSYNC(self): host = Host("coquito") mappersManager = self.createMapperMock() dataMapper = mock() objectMapper = mock() triemock = mock() when(mappersManager).getMapper(host.class_signature).thenReturn(dataMapper) when(dataMapper).save(host).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.editHostSYNC(host, 'new_name', 'new_desc', 'new_os', True) verify(dataMapper).save(host) self.assertEquals(host.getName(), 'new_name', "Name not updated") self.assertEquals(host.getDescription(), 'new_desc', "Description not updated") self.assertEquals(host.getOS(), 'new_os', "OS not updated") self.assertEquals(host.isOwned(), True, "Owned status not updated")
def testDelVulnFromHostASYNC(self): host = Host('coco') vuln = ModelObjectVuln("int_mock0") host.addChild(vuln) self.genericDelTest(host, vuln, controller.ModelController.delVulnFromHostASYNC, process_pending=True)
def testDelNoteFromModelObjectSYNC(self): host = Host('coco') note = ModelObjectNote("int_mock0") host.addChild(note) self.genericDelTest(host, note, controller.ModelController.delNoteSYNC)
def testDelNoteFromHostSYNC(self): host = Host('coco') note = ModelObjectNote("int_mock0") host.addChild(note) self.genericDelTest(host, note, controller.ModelController.delNoteFromHostASYNC, process_pending=True)
def testDelVulnFromObjectSYNC(self): host = Host('coco') vuln = ModelObjectVuln("int_mock0") host.addChild(vuln) self.genericDelTest(host, vuln, controller.ModelController.delVulnSYNC)
def testDeleteModelObjectRemovesChildFromParentASYNC(self): host = Host('coco') interface = Interface("int_mock0") self.genericDelTest(host, interface, controller.ModelController.delInterfaceASYNC, process_pending=True)
def testInterfaceFromHostRemovedSYNC(self): host = Host('coco') interface = Interface("int_mock0") self.genericDelTest(host, interface, controller.ModelController.delInterfaceSYNC)