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')
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")
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')
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')
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")
def testVulnServiceLookup(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') visitor = VulnsLookupVisitor(vuln.getID()) host.accept(visitor) self.assertEquals(len(visitor.parents[0]), 3, "object hierarchy should be host, interface and service") self.assertIn(vuln, visitor.vulns)
def testVulnServiceLookup(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') visitor = VulnsLookupVisitor(vuln.getID()) host.accept(visitor) self.assertEquals( len(visitor.parents[0]), 3, "object hierarchy should be host, interface and service") self.assertIn(vuln, visitor.vulns)
def test_model_remove_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()} 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()) addedService = addedInterface.getService(serv.getID()) self.assertEquals(len(addedService.getVulns()), 0, 'Service vulns not removed')
def testAddNoteToService(self): """ This test case creates a host within the Model Controller context adds an interface to it then adds service then a 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() # Then self.assertIn(note, notes, 'Note not added')
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")
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')