Exemple #1
0
    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())
Exemple #2
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 #3
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 #4
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 #5
0
    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)
Exemple #6
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)
Exemple #7
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 #8
0
    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())
Exemple #9
0
    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)
Exemple #10
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 #11
0
    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)
Exemple #12
0
    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)
Exemple #13
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 #14
0
    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")
Exemple #15
0
 def testDelVulnFromHostASYNC(self):
     host = Host('coco')
     vuln = ModelObjectVuln("int_mock0") 
     host.addChild(vuln)
     self.genericDelTest(host, vuln,
             controller.ModelController.delVulnFromHostASYNC, process_pending=True)
Exemple #16
0
 def testDelNoteFromModelObjectSYNC(self):
     host = Host('coco')
     note = ModelObjectNote("int_mock0") 
     host.addChild(note)
     self.genericDelTest(host, note, 
             controller.ModelController.delNoteSYNC)
Exemple #17
0
 def testDelNoteFromHostSYNC(self):
     host = Host('coco')
     note = ModelObjectNote("int_mock0") 
     host.addChild(note)
     self.genericDelTest(host, note, 
             controller.ModelController.delNoteFromHostASYNC, process_pending=True)
Exemple #18
0
 def testDelVulnFromObjectSYNC(self):
     host = Host('coco')
     vuln = ModelObjectVuln("int_mock0") 
     host.addChild(vuln)
     self.genericDelTest(host, vuln,
             controller.ModelController.delVulnSYNC)
Exemple #19
0
 def testDeleteModelObjectRemovesChildFromParentASYNC(self): 
     host = Host('coco')
     interface = Interface("int_mock0") 
     self.genericDelTest(host, interface, controller.ModelController.delInterfaceASYNC, process_pending=True)
Exemple #20
0
 def testInterfaceFromHostRemovedSYNC(self):
     host = Host('coco')
     interface = Interface("int_mock0") 
     self.genericDelTest(host, interface,
             controller.ModelController.delInterfaceSYNC)