Exemple #1
0
    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())
Exemple #2
0
    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()) 
Exemple #3
0
    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?")
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    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)