def resultsetfp(self, id, resultids, fp): dbh = SpiderFootDb(self.config) if fp not in ["0", "1"]: return json.dumps( ["ERROR", "No FP flag set or not set correctly."]) ids = json.loads(resultids) if not ids: return json.dumps(["ERROR", "No IDs supplied."]) # Cannot set FPs if a scan is not completed status = dbh.scanInstanceGet(id) if status[5] not in ["ABORTED", "FINISHED", "ERROR-FAILED"]: return json.dumps(["WARNING", "Scan must be in a finished state when " + \ "setting False Positives."]) # Make sure the user doesn't set something as non-FP when the # parent is set as an FP. if fp == "0": data = dbh.scanElementSourcesDirect(id, ids) for row in data: if str(row[14]) == "1": return json.dumps(["WARNING", "You cannot unset an element as False Positive " + \ "if a parent element is still False Positive."]) # Set all the children as FPs too.. it's only logical afterall, right? childs = dbh.scanElementChildrenAll(id, ids) allIds = ids + childs ret = dbh.scanResultsUpdateFP(id, allIds, fp) if not ret: return json.dumps(["ERROR", "Exception encountered."]) else: return json.dumps(["SUCCESS", ""])
def resultsetfp(self, id, resultids, fp): dbh = SpiderFootDb(self.config) if fp not in ["0", "1"]: return json.dumps(["ERROR", "No FP flag set or not set correctly."]) ids = json.loads(resultids) if not ids: return json.dumps(["ERROR", "No IDs supplied."]) # Cannot set FPs if a scan is not completed status = dbh.scanInstanceGet(id) if status[5] not in [ "ABORTED", "FINISHED", "ERROR-FAILED" ]: return json.dumps(["WARNING", "Scan must be in a finished state when " + \ "setting False Positives."]) # Make sure the user doesn't set something as non-FP when the # parent is set as an FP. if fp == "0": data = dbh.scanElementSourcesDirect(id, ids) for row in data: if str(row[14]) == "1": return json.dumps(["WARNING", "You cannot unset an element as False Positive " + \ "if a parent element is still False Positive."]); # Set all the children as FPs too.. it's only logical afterall, right? childs = dbh.scanElementChildrenAll(id, ids) allIds = ids + childs ret = dbh.scanResultsUpdateFP(id, allIds, fp) if not ret: return json.dumps(["ERROR", "Exception encountered."]) else: return json.dumps(["SUCCESS", ""])
def test_scan_element_sources_direct_should_return_a_list(self): """ Test scanElementSourcesDirect(self, instanceId, elementIdList) """ sfdb = SpiderFootDb(self.default_options, False) scan_element_sources_direct = sfdb.scanElementSourcesDirect(None, None) self.assertIsInstance(scan_element_sources_direct, list) self.assertEqual('TBD', 'TBD')
def test_scan_element_sources_direct_invalid_instanceid_should_raise(self): """ Test scanElementSourcesDirect(self, instanceId, elementIdList) """ sfdb = SpiderFootDb(self.default_options, False) element_id_list = [] invalid_types = [None, list(), dict()] for invalid_type in invalid_types: with self.subTest(invalid_type=invalid_type): with self.assertRaises(TypeError) as cm: scan_element_sources_direct = sfdb.scanElementSourcesDirect(invalid_type, element_id_list)
def test_scanElementSourcesDirect_argument_elementIdList_of_invalid_type_should_raise_TypeError(self): """ Test scanElementSourcesDirect(self, instanceId, elementIdList) """ sfdb = SpiderFootDb(self.default_options, False) instance_id = "example instance id" invalid_types = [None, "", dict(), int()] for invalid_type in invalid_types: with self.subTest(invalid_type=invalid_type): with self.assertRaises(TypeError) as cm: scan_element_sources_direct = sfdb.scanElementSourcesDirect(instance_id, invalid_type)