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 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 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 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 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)