Example #1
0
    def test_add_host_and_generate_unsolvable_update(self):
        """
        This test case creates a host within the Model Controller
        context and then creates another with the same key elements,
        but different non-key attributes to generate an update to
        be resolved by the user
        """
        # When
        hostname = 'host'
        host1a = test_utils.create_host(self, host_name=hostname, os='windows')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(host.getOS(), 'windows',
                          'Host\'s OS should be windows')

        # Then, we generate an update
        host1b = test_utils.create_host(self, host_name=hostname, os='linux')

        self.assertEquals(host1a.getID(), host1b.getID(),
                          'Both hosts should have the same id')

        self.assertEquals(len(self.model_controller.getConflicts()), 1,
                          'Update was not generated')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(host.getOS(), 'windows',
                          'Host\'s OS should still be windows')

        self.assertEquals(len(host.getUpdates()), 1,
                          'The host should have a pending update')
Example #2
0
    def test_add_host_and_generate_solvable_update_with_edition(self):
        """
        This test case creates a host with a default value in a non-key
        attrribute within the Model Controller context and then creates
        another with the same key elements, but different non-key
        attributes to generate an automatic solvable update
        """
        # When
        hostname = 'host'
        host1a = test_utils.create_host(self, host_name=hostname, os='unknown')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(host.getOS(), 'unknown',
                          'Host\'s OS should be unknown')

        # Then, we generate an update
        host1b = test_utils.create_host(self, host_name=hostname, os='windows')

        self.assertEquals(host1a.getID(), host1b.getID(),
                          'Both hosts should have the same id')

        self.assertEquals(len(self.model_controller.getConflicts()), 0,
                          'Update was generated')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(host.getOS(), 'windows',
                          'Host\'s OS should now be windows')
Example #3
0
    def testAddHost(self):
        """ This test case creates a host within the Model Controller context
        then checks it's vality"""
        # When
        hostname = 'host'
        test_utils.create_host(self, host_name=hostname, os='windows')
        # Then, we generate an update
        test_utils.create_host(self, host_name=hostname, os='linux')

        self.assertEquals(len(self.model_controller.getConflicts()), 1,
                          'Update not generated')

        conflict = self.model_controller.getConflicts()[0]
Example #4
0
    def testAddHost(self):
        """ This test case creates a host within the Model Controller context
        then checks it's vality"""
        # When
        hostname = 'host'
        test_utils.create_host(self, host_name=hostname, os='windows')
        # Then, we generate an update
        test_utils.create_host(self, host_name=hostname, os='linux')

        self.assertEquals(len(self.model_controller.getConflicts()), 1,
                          'Update not generated')

        conflict = self.model_controller.getConflicts()[0]
Example #5
0
    def testDelVulnFromService(self):
        """ This test case creates a host within the Model Controller context
        adds an interface to it then adds service then a Vuln, then removes the
        Vuln"""

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)
        service = test_utils.create_service(self, host, interface)

        vuln = ModelObjectVuln(name='VulnTest', desc='TestDescription',
                                severity='high')

        self.model_controller.addVulnToServiceSYNC(host.getID(),
                                service.getID(), vuln)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        vulns = added_service.getVulns()
        self.assertIn(vuln, vulns, 'Vuln not added')

        # Then

        self.model_controller.delVulnFromServiceSYNC(host.getID(),
                            service.getID(), vuln.getID())

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        vulns = added_service.getVulns()
        self.assertNotIn(vuln, vulns, 'Vuln not removed')
Example #6
0
    def test_model_edit_serv_vuln(self):
        host = test_utils.create_host(self)
        inter = test_utils.create_interface(self, host)
        serv = test_utils.create_service(self, host, inter)
        vuln = test_utils.create_serv_vuln(self, host, serv, 'vuln', 'desc',
                                           'high')

        data = {
            "vulnid": vuln.getID(),
            "hostid": host.getID(),
            'name': 'coco',
            'desc': 'newdesc',
            'severity': 'low'
        }

        response = requests.post(self.url_model_edit_vulns,
                                 data=json.dumps(data),
                                 headers=self.headers)

        self.assertEquals(response.status_code, 200,
                          "Status Code should be 200: OK")

        addedhost = self.model_controller.getHost(host.getID())
        addedInterface = addedhost.getInterface(inter.getID())
        addedService = addedInterface.getService(serv.getID())
        addedvuln = addedService.getVuln(vuln.getID())

        self.assertEquals(addedvuln.name, 'coco', 'Name not updated')
        self.assertEquals(addedvuln.desc, 'newdesc', 'Desc not updated')
        self.assertEquals(addedvuln.severity, 'low', 'Severity not updated')
Example #7
0
    def testAddVulnWebToInterface(self):
        """ This test case creates a host within the Model Controller context
        adds an interface to it then adds a VulnWeb"""

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)

        vuln = ModelObjectVulnWeb(name='VulnTest', desc='TestDescription',
                                severity='high')

        self.model_controller.addVulnToInterfaceSYNC(host.getID(),
                                interface.getID(), vuln)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        vulns = added_interface.getVulns()
        self.assertIn(vuln, vulns, 'Vuln not added')

        self.temp_workspace.load()

        # Then
        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        vulns = added_interface.getVulns()
        self.assertIn(vuln.getID(), [v.getID() for v in vulns],
                'Vuln not reloaded')
Example #8
0
    def testAddVulnWebToInterface(self):
        """ This test case creates a host within the Model Controller context
        adds an interface to it then adds a VulnWeb"""

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)

        vuln = ModelObjectVulnWeb(name='VulnTest',
                                  desc='TestDescription',
                                  severity='high')

        self.model_controller.addVulnToInterfaceSYNC(host.getID(),
                                                     interface.getID(), vuln)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        vulns = added_interface.getVulns()
        self.assertIn(vuln, vulns, 'Vuln not added')

        self.temp_workspace.load()

        # Then
        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        vulns = added_interface.getVulns()
        self.assertIn(vuln.getID(), [v.getID() for v in vulns],
                      'Vuln not reloaded')
Example #9
0
    def testDelNoteFromService(self):
        """ Creates a Hosts, adds an Interface, a Service and a Note, then removes the
        note """

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)
        service = test_utils.create_service(self, host, interface)

        note = ModelObjectNote(name='NoteTest', text='TestDescription')

        self.model_controller.addNoteToServiceSYNC(host.getID(),
                                service.getID(), note)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        notes = added_service.getNotes()
        self.assertIn(note, notes, 'Note not added')

        # Then

        self.model_controller.delNoteFromServiceSYNC(host.getID(),
                            service.getID(), note.getID())

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        notes = added_service.getNotes()
        self.assertNotIn(note, notes, 'Note not removed')
Example #10
0
    def testDeleteService(self):
        """ Creates a Host an Interface and a Service, then deletes the Service
        to test it's removal from the controllers list """

        host1 = test_utils.create_host(self, "coquito")
        interface1 = test_utils.create_interface(self, host1, iname="pepito")
        service1 = test_utils.create_service(self, host1, interface1)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]
        self.assertIn(host1.getID(), hosts_ids, "Host not in controller")

        host1 = self.model_controller.getHost(host1.getID())
        interfaces_ids = [i.getID() for i in host1.getAllInterfaces()]
        self.assertIn(interface1.getID(), interfaces_ids,
                      "Interface not in host!")

        services_ids = [s.getID() for s in \
                            self.model_controller.getHost(host1.getID())
                            .getInterface(interface1.getID()).getAllServices()]

        self.assertIn(service1.getID(), services_ids,
                      "Service not in Interface!")

        self.model_controller.delServiceFromInterfaceSYNC(
            host1.getID(), interface1.getID(), service1.getID())

        services_ids = [s.getID() for s in \
                            self.model_controller.getHost(host1.getID())
                            .getInterface(interface1.getID()).getAllServices()]

        self.assertNotIn(service1.getID(), services_ids, \
                        "Service not deleted")
Example #11
0
    def testDelVulnFromService(self):
        """ This test case creates a host within the Model Controller context
        adds an interface to it then adds service then a Vuln, then removes the
        Vuln"""

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)
        service = test_utils.create_service(self, host, interface)

        vuln = ModelObjectVuln(name='VulnTest',
                               desc='TestDescription',
                               severity='high')

        self.model_controller.addVulnToServiceSYNC(host.getID(),
                                                   service.getID(), vuln)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        vulns = added_service.getVulns()
        self.assertIn(vuln, vulns, 'Vuln not added')

        # Then

        self.model_controller.delVulnFromServiceSYNC(host.getID(),
                                                     service.getID(),
                                                     vuln.getID())

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        vulns = added_service.getVulns()
        self.assertNotIn(vuln, vulns, 'Vuln not removed')
Example #12
0
    def testDeleteService(self):
        """ Creates a Host an Interface and a Service, then deletes the Service
        to test it's removal from the controllers list """

        host1 = test_utils.create_host(self, "coquito")
        interface1 = test_utils.create_interface(self, host1, iname="pepito")
        service1 = test_utils.create_service(self, host1, interface1)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]
        self.assertIn(host1.getID(), hosts_ids,
                                "Host not in controller")

        host1 = self.model_controller.getHost(host1.getID())
        interfaces_ids = [i.getID() for i in host1.getAllInterfaces()]
        self.assertIn(interface1.getID(), interfaces_ids,
                                "Interface not in host!")

        services_ids = [s.getID() for s in \
                            self.model_controller.getHost(host1.getID())
                            .getInterface(interface1.getID()).getAllServices()]

        self.assertIn(service1.getID(), services_ids,
                                "Service not in Interface!")

        self.model_controller.delServiceFromInterfaceSYNC(host1.getID(),
                                    interface1.getID(), service1.getID())

        services_ids = [s.getID() for s in \
                            self.model_controller.getHost(host1.getID())
                            .getInterface(interface1.getID()).getAllServices()]

        self.assertNotIn(service1.getID(), services_ids, \
                        "Service not deleted")
Example #13
0
    def testDelNoteFromService(self):
        """ Creates a Hosts, adds an Interface, a Service and a Note, then removes the
        note """

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)
        service = test_utils.create_service(self, host, interface)

        note = ModelObjectNote(name='NoteTest', text='TestDescription')

        self.model_controller.addNoteToServiceSYNC(host.getID(),
                                                   service.getID(), note)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        notes = added_service.getNotes()
        self.assertIn(note, notes, 'Note not added')

        # Then

        self.model_controller.delNoteFromServiceSYNC(host.getID(),
                                                     service.getID(),
                                                     note.getID())

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        added_service = added_interface.getService(service.getID())
        notes = added_service.getNotes()
        self.assertNotIn(note, notes, 'Note not removed')
Example #14
0
    def testVulnHostLookup(self):
        host = test_utils.create_host(self)
        vuln = test_utils.create_host_vuln(self, host, 'vuln', 'desc', 'high')
        visitor = VulnsLookupVisitor(vuln.getID())
        host.accept(visitor)

        self.assertEquals(len(visitor.parents[0]), 1,
                          "object hierarchy should be only host")
        self.assertIn(vuln, visitor.vulns)
Example #15
0
    def testVulnInterfaceLookup(self):
        host = test_utils.create_host(self)
        inter = test_utils.create_interface(self, host)
        vuln = test_utils.create_int_vuln(self, host, inter, 'vuln', 'desc', 'high')
        visitor = VulnsLookupVisitor(vuln.getID())
        host.accept(visitor) 

        self.assertEquals(len(visitor.parents[0]), 2,
                "object hierarchy should be host and interface")
        self.assertIn(vuln, visitor.vulns)
Example #16
0
    def testVulnHostLookup(self):
        host = test_utils.create_host(self)
        vuln = test_utils.create_host_vuln(self, host, 'vuln', 'desc', 'high')
        visitor = VulnsLookupVisitor(vuln.getID())
        host.accept(visitor)


        self.assertEquals(len(visitor.parents[0]), 1,
                "object hierarchy should be only host")
        self.assertIn(vuln, visitor.vulns)
Example #17
0
    def test_add_host_and_generate_unsolvable_update(self):
        """
        This test case creates a host within the Model Controller
        context and then creates another with the same key elements,
        but different non-key attributes to generate an update to
        be resolved by the user
        """
        # When
        hostname = 'host'
        host1a = test_utils.create_host(self, host_name=hostname, os='windows')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(
            host.getOS(),
            'windows',
            'Host\'s OS should be windows')

        # Then, we generate an update
        host1b = test_utils.create_host(self, host_name=hostname, os='linux')

        self.assertEquals(
            host1a.getID(),
            host1b.getID(),
            'Both hosts should have the same id')

        self.assertEquals(
            len(self.model_controller.getConflicts()),
            1,
            'Update was not generated')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(
            host.getOS(),
            'windows',
            'Host\'s OS should still be windows')

        self.assertEquals(
            len(host.getUpdates()),
            1,
            'The host should have a pending update')
Example #18
0
    def testVulnInterfaceLookup(self):
        host = test_utils.create_host(self)
        inter = test_utils.create_interface(self, host)
        vuln = test_utils.create_int_vuln(self, host, inter, 'vuln', 'desc',
                                          'high')
        visitor = VulnsLookupVisitor(vuln.getID())
        host.accept(visitor)

        self.assertEquals(len(visitor.parents[0]), 2,
                          "object hierarchy should be host and interface")
        self.assertIn(vuln, visitor.vulns)
Example #19
0
    def testAddHost(self):
        """ This test case creates a host within the Model Controller context
        then checks it's vality"""
        # When
        hostname = 'host'
        _ = test_utils.create_host(self, host_name=hostname, os='windows')

        # #Then
        added_host = self.model_controller.getHost(hostname)

        self.assertEquals(added_host.getName(), hostname,
                          'Saved object name is not correctly saved')
Example #20
0
    def testDeleteHost(self):
        """ Creates a Host to test it's removal from the controllers list """

        host1 = test_utils.create_host(self, "coquito")
        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]

        self.assertIn(host1.getID(), hosts_ids, "Host not in controller")

        self.model_controller.delHostSYNC(host1.name)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]
        self.assertNotIn(host1.getID(), hosts_ids, "Host not deleted")
Example #21
0
    def testAddHost(self):
        """ This test case creates a host within the Model Controller context
        then checks it's vality"""
        # When
        hostname = 'host'
        _ = test_utils.create_host(self, host_name=hostname, os='windows')

        # #Then
        added_host = self.model_controller.getHost(hostname)

        self.assertEquals(added_host.getName(), hostname,
                'Saved object name is not correctly saved')
Example #22
0
    def testAddNoteToHost(self):
        """ This test case creates a host within the Model Controller context
        then adds a Note"""

        # When
        h = test_utils.create_host(self)
        note = ModelObjectNote(name='NoteTest', text='TestDescription')
        self.model_controller.addNoteToHostSYNC(h.getID(), note)

        # Then
        added_host = self.model_controller.getHost(h.getName())
        notes = added_host.getNotes()
        self.assertIn(note, notes, 'Note not added')
Example #23
0
    def testAddNoteToHost(self):
        """ This test case creates a host within the Model Controller context
        then adds a Note"""

        # When
        h = test_utils.create_host(self)
        note = ModelObjectNote(name='NoteTest', text='TestDescription')
        self.model_controller.addNoteToHostSYNC(h.getID(), note)

        # Then
        added_host = self.model_controller.getHost(h.getName())
        notes = added_host.getNotes()
        self.assertIn(note, notes, 'Note not added')
Example #24
0
    def testDeleteHost(self):
        """ Creates a Host to test it's removal from the controllers list """

        host1 = test_utils.create_host(self, "coquito")
        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]

        self.assertIn(host1.getID(), hosts_ids,
                                "Host not in controller")

        self.model_controller.delHostSYNC(host1.name)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]
        self.assertNotIn(host1.getID(), hosts_ids,
                                "Host not deleted")
Example #25
0
    def testAddVulnToHost(self):
        """ This test case creates a host within the Model Controller context
        then adds a VULN"""

        # When
        h = test_utils.create_host(self)
        vuln = ModelObjectVuln(name='VulnTest', desc='TestDescription',
                                severity='high')
        self.model_controller.addVulnToHostSYNC(h.getID(), vuln)

        added_host = self.model_controller.getHost(h.getName())
        vulns = added_host.getVulns()
        #Then
        self.assertIn(vuln, vulns, 'Vuln not added')
Example #26
0
    def test_add_host_and_generate_solvable_update_with_edition(self):
        """
        This test case creates a host with a default value in a non-key
        attrribute within the Model Controller context and then creates
        another with the same key elements, but different non-key
        attributes to generate an automatic solvable update
        """
        # When
        hostname = 'host'
        host1a = test_utils.create_host(self, host_name=hostname, os='unknown')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(
            host.getOS(),
            'unknown',
            'Host\'s OS should be unknown')

        # Then, we generate an update
        host1b = test_utils.create_host(self, host_name=hostname, os='windows')

        self.assertEquals(
            host1a.getID(),
            host1b.getID(),
            'Both hosts should have the same id')

        self.assertEquals(
            len(self.model_controller.getConflicts()),
            0,
            'Update was generated')

        host = self._mappers_manager.find(host1a.getID())

        self.assertEquals(
            host.getOS(),
            'windows',
            'Host\'s OS should now be windows')
Example #27
0
    def testAddVulnToHost(self):
        """ This test case creates a host within the Model Controller context
        then adds a VULN"""

        # When
        h = test_utils.create_host(self)
        vuln = ModelObjectVuln(name='VulnTest',
                               desc='TestDescription',
                               severity='high')
        self.model_controller.addVulnToHostSYNC(h.getID(), vuln)

        added_host = self.model_controller.getHost(h.getName())
        vulns = added_host.getVulns()
        #Then
        self.assertIn(vuln, vulns, 'Vuln not added')
Example #28
0
    def test_model_del_int_vuln(self):
        host = test_utils.create_host(self)
        inter = test_utils.create_interface(self, host)
        vuln = test_utils.create_int_vuln(self, host, inter, 'vuln', 'desc', 'high')

        data = {"vulnid": vuln.getID(), "hostid": host.getID()}

        response = requests.delete(self.url_model_del_vulns,
                                 data=json.dumps(data),
                                 headers=self.headers)

        self.assertEquals(response.status_code, 200, "Status Code should be 200: OK")

        addedhost = self.model_controller.getHost(host.getID())
        addedInterface = addedhost.getInterface(inter.getID())
        self.assertEquals(len(addedInterface.getVulns()), 0, 'Interface vulns not deleted')
Example #29
0
    def test_model_remove_host_vuln(self):
        host = test_utils.create_host(self)
        vuln = test_utils.create_host_vuln(self, host, 'vuln', 'desc', 'high')

        data = {"vulnid": vuln.getID(), "hostid": host.getID(), 'name': 'coco',
                'desc': 'newdesc', 'severity': 'low'}

        response = requests.delete(self.url_model_del_vulns,
                                 data=json.dumps(data),
                                 headers=self.headers)

        self.assertEquals(response.status_code, 200, "Status Code should be 200: OK")

        addedhost = self.model_controller.getHost(host.getID())
        addedvuln = addedhost.getVulns()

        self.assertEquals(len(addedvuln), 0, 'Vuln not removed from Host')
Example #30
0
    def testDeleteNoteFromHost(self):
        """ Creates a Host adds a Note then removes """

        host1 = test_utils.create_host(self, "coquito")

        note = ModelObjectNote(name='NoteTest', text='TestDescription')

        self.model_controller.addNoteToHostSYNC(host1.getID(), note)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]

        self.assertIn(host1.getID(), hosts_ids, "Host not in controller")

        self.model_controller.delNoteFromHostSYNC(host1.getID(), note.getID())

        added_host = self.model_controller.getHost(host1.getName())

        self.assertNotIn(note, added_host.getNotes(), 'Note not removed')
Example #31
0
    def testAddNoteToInterface(self):
        """ This test case creates a host within the Model Controller context
        adds an interface to it then adds a Note"""

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)

        note = ModelObjectNote(name='NoteTest', text='TestDescription')

        self.model_controller.addNoteToInterfaceSYNC(host.getID(),
                                interface.getID(), note)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        notes = added_interface.getNotes()
        # Then
        self.assertIn(note, notes, 'Note not added')
Example #32
0
    def testAddNoteToInterface(self):
        """ This test case creates a host within the Model Controller context
        adds an interface to it then adds a Note"""

        # When
        host = test_utils.create_host(self)
        interface = test_utils.create_interface(self, host)

        note = ModelObjectNote(name='NoteTest', text='TestDescription')

        self.model_controller.addNoteToInterfaceSYNC(host.getID(),
                                                     interface.getID(), note)

        added_host = self.model_controller.getHost(host.getName())
        added_interface = added_host.getInterface(interface.getID())
        notes = added_interface.getNotes()
        # Then
        self.assertIn(note, notes, 'Note not added')
Example #33
0
    def test_model_edit_host_vuln(self):
        host = test_utils.create_host(self)
        vuln = test_utils.create_host_vuln(self, host, 'vuln', 'desc', 'high')

        data = {"vulnid": vuln.getID(), "hostid": host.getID(), 'name': 'coco',
                'desc': 'newdesc', 'severity': 'low'}

        response = requests.post(self.url_model_edit_vulns,
                                 data=json.dumps(data),
                                 headers=self.headers)

        self.assertEquals(response.status_code, 200, "Status Code should be 200: OK")

        addedhost = self.model_controller.getHost(host.getID())
        addedvuln = addedhost.getVuln(vuln.getID())

        self.assertEquals(addedvuln.name, 'coco', 'Name not updated')
        self.assertEquals(addedvuln.desc, 'newdesc', 'Desc not updated')
        self.assertEquals(addedvuln.severity, 'low', 'Severity not updated')
Example #34
0
    def test_model_del_int_vuln(self):
        host = test_utils.create_host(self)
        inter = test_utils.create_interface(self, host)
        vuln = test_utils.create_int_vuln(self, host, inter, 'vuln', 'desc',
                                          'high')

        data = {"vulnid": vuln.getID(), "hostid": host.getID()}

        response = requests.delete(self.url_model_del_vulns,
                                   data=json.dumps(data),
                                   headers=self.headers)

        self.assertEquals(response.status_code, 200,
                          "Status Code should be 200: OK")

        addedhost = self.model_controller.getHost(host.getID())
        addedInterface = addedhost.getInterface(inter.getID())
        self.assertEquals(len(addedInterface.getVulns()), 0,
                          'Interface vulns not deleted')
Example #35
0
    def testDeleteNoteFromHost(self):
        """ Creates a Host adds a Note then removes """

        host1 = test_utils.create_host(self, "coquito")

        note = ModelObjectNote(name='NoteTest', text='TestDescription')

        self.model_controller.addNoteToHostSYNC(host1.getID(), note)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]

        self.assertIn(host1.getID(), hosts_ids,
                                "Host not in controller")

        self.model_controller.delNoteFromHostSYNC(host1.getID(), note.getID())

        added_host = self.model_controller.getHost(host1.getName())

        self.assertNotIn(note, added_host.getNotes(), 'Note not removed')
Example #36
0
    def testDeleteVulnFromHost(self):
        """ Creates a Host adds a Vuln then removes """

        host1 = test_utils.create_host(self, "coquito")

        vuln = ModelObjectVuln(name='VulnTest', desc='TestDescription',
                                severity='high')

        self.model_controller.addVulnToHostSYNC(host1.getID(), vuln)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]

        self.assertIn(host1.getID(), hosts_ids,
                                "Host not in controller")

        self.model_controller.delVulnFromHostSYNC(host1.getID(), vuln.getID())

        added_host = self.model_controller.getHost(host1.getName())

        self.assertNotIn(vuln, added_host.getVulns(), 'Vuln not removed')
Example #37
0
    def testDeleteVulnFromHost(self):
        """ Creates a Host adds a Vuln then removes """

        host1 = test_utils.create_host(self, "coquito")

        vuln = ModelObjectVuln(name='VulnTest',
                               desc='TestDescription',
                               severity='high')

        self.model_controller.addVulnToHostSYNC(host1.getID(), vuln)

        hosts_ids = [h.getID() for h in self.model_controller.getAllHosts()]

        self.assertIn(host1.getID(), hosts_ids, "Host not in controller")

        self.model_controller.delVulnFromHostSYNC(host1.getID(), vuln.getID())

        added_host = self.model_controller.getHost(host1.getName())

        self.assertNotIn(vuln, added_host.getVulns(), 'Vuln not removed')
Example #38
0
    def testMultipleVulnLookup(self):
        host = test_utils.create_host(self)
        inter = test_utils.create_interface(self, host)
        service = test_utils.create_service(self, host, inter)
        vuln = test_utils.create_serv_vuln(self, host, service, 'vuln', 'desc',
                                           'high')
        vuln2 = test_utils.create_int_vuln(self, host, inter, 'vuln', 'desc',
                                           'high')
        visitor = VulnsLookupVisitor(vuln.getID())
        host.accept(visitor)

        parents1 = visitor.parents[0]
        parents2 = visitor.parents[1]

        self.assertIn(host, parents1, "Host should be in parents")

        self.assertIn(host, parents2, "Host should be in parents")

        self.assertIn(inter, parents2, "Interface should be in parents")

        self.assertIn(inter, parents2, "Interface should be in parents")
Example #39
0
    def testMultipleVulnLookup(self):
        host = test_utils.create_host(self)
        inter = test_utils.create_interface(self, host)
        service = test_utils.create_service(self, host, inter)
        vuln = test_utils.create_serv_vuln(self, host, service, 'vuln', 'desc', 'high')
        vuln2 = test_utils.create_int_vuln(self, host, inter, 'vuln', 'desc', 'high')
        visitor = VulnsLookupVisitor(vuln.getID())
        host.accept(visitor) 

        parents1 = visitor.parents[0]
        parents2 = visitor.parents[1]

        self.assertIn(host, parents1,
                "Host should be in parents")

        self.assertIn(host, parents2,
                "Host should be in parents")

        self.assertIn(inter, parents2,
                "Interface should be in parents")

        self.assertIn(inter, parents2,
                "Interface should be in parents")
Example #40
0
    def test_model_remove_host_vuln(self):
        host = test_utils.create_host(self)
        vuln = test_utils.create_host_vuln(self, host, 'vuln', 'desc', 'high')

        data = {
            "vulnid": vuln.getID(),
            "hostid": host.getID(),
            'name': 'coco',
            'desc': 'newdesc',
            'severity': 'low'
        }

        response = requests.delete(self.url_model_del_vulns,
                                   data=json.dumps(data),
                                   headers=self.headers)

        self.assertEquals(response.status_code, 200,
                          "Status Code should be 200: OK")

        addedhost = self.model_controller.getHost(host.getID())
        addedvuln = addedhost.getVulns()

        self.assertEquals(len(addedvuln), 0, 'Vuln not removed from Host')