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