Example #1
0
 def test_file_tag_add_remove(self):
     for tag in self.taglist:
         file_tag_add(self.file_sha256, tag.id)
         get_result = scan_proberesults(self.get_result.result_id)
         self.assertIn(tag.id,
                       [x.id for x in get_result.file_infos.tags])
     for tag in self.taglist:
         file_tag_remove(self.file_sha256, tag.id)
         get_result = scan_proberesults(self.get_result.result_id)
         self.assertNotIn(tag.id,
                          [x.id for x in get_result.file_infos.tags])
Example #2
0
 def setUp(self):
     if self.taglist is None:
         self.taglist = tag_list()
     if len(self.taglist) == 0:
         raise unittest.SkipTest("Skipping No tag found (please add some)")
     # Insure file is present (Force=False)
     scan = scan_files([self.file_path], False, blocking=True)
     self.get_result = scan_proberesults(scan.results[0].result_id)
     # Insure file got no tags for test
     self.former_tag = [x.id for x in self.get_result.file_infos.tags]
     if len(self.former_tag) != 0:
         for tagid in self.former_tag:
             file_tag_remove(self.file_sha256, tagid)
         self.get_result = scan_proberesults(scan.results[0].result_id)
Example #3
0
 def tearDown(self):
     self.assertEqual(self.file_sha256, self.get_result.file_sha256)
     self.assertEqual(self.file_sha256, self.get_result.file_infos.sha256)
     self.get_result = scan_proberesults(self.get_result.result_id)
     for tag in self.get_result.file_infos.tags:
         file_tag_remove(self.file_sha256, tag.id)
     for tagid in self.former_tag:
         file_tag_add(self.file_sha256, tagid)
Example #4
0
 def test_utf8(self):
     scan = self._make_scan(UTF8_PATHS)
     for get_result in scan.results:
         res = scan_proberesults(get_result.result_id)
         self.assertIn(res.name, UTF8_SAMPLES)
     for filename in UTF8_SAMPLES:
         (_, res) = file_search(filename, limit=1)
         self.assertEqual(type(res), list)
         self.assertEqual(len(res), 1)
         self.assertEqual(res[0].name, filename)
Example #5
0
 def test_file_results_not_formatted(self):
     force = False
     probes = probe_list()
     scan = scan_files(FILEPATHS, force, probes, blocking=True)
     for get_result in scan.results:
         self.assertTrue(self._validate_uuid(str(get_result.result_id)))
         res = scan_proberesults(get_result.result_id, formatted=False)
         self.assertIn(res.name, FILENAMES)
         self.assertEqual(type(res.probe_results), list)
         self.assertEqual(type(res.probe_results[0]), IrmaProbeResult)
         self.assertEqual(len(res.probe_results), res.probes_finished)
Example #6
0
 def test_utf8(self):
     force = False
     scan = scan_files(UTF8_PATHS, force, blocking=True)
     for get_result in scan.results:
         res = scan_proberesults(get_result.result_id)
         self.assertIn(res.name, UTF8_SAMPLES)
     for filename in UTF8_SAMPLES:
         (_, res) = file_search(filename, limit=1)
         self.assertEqual(type(res), list)
         self.assertEqual(len(res), 1)
         self.assertEqual(res[0].name, filename)
Example #7
0
    def _test_scan_file(self,
                        filelist,
                        probelist,
                        force=True,
                        mimetype_filtering=None,
                        resubmit_files=None,
                        timeout=SCAN_TIMEOUT_SEC):
        nb_probes = len(probelist)
        nb_files = len(filelist)
        nb_jobs = nb_probes * nb_files
        filenames = map(lambda f: os.path.basename(f), filelist)
        scan = scan_new(verbose=DEBUG)
        self.assertIsNot(scan.id, None)
        scanid = scan.id
        self.assertIsNot(scan.date, None)
        self.assertEqual(len(scan.results), 0)

        scan = scan_add(scan.id, filelist, verbose=DEBUG)
        self._check_results(scan.results, scanid, filenames, [0], [0],
                            True, True)

        scan = scan_launch(scan.id, force=force, probe=probelist,
                           mimetype_filtering=mimetype_filtering,
                           resubmit_files=resubmit_files,
                           verbose=DEBUG)
        start = time.time()
        while not scan.is_finished():
            self._check_results(scan.results, scanid, filenames,
                                range(nb_probes + 1), range(nb_jobs + 1),
                                True, True)
            time.sleep(BEFORE_NEXT_PROGRESS)
            now = time.time()
            self.assertLessEqual(now, start + timeout, "Results Timeout")
            scan = scan_get(scan.id)

        # Scan finished
        self._check_results(scan.results, scanid, filenames,
                            [scan.probes_total], [scan.probes_total],
                            True, True)
        res = {}
        for get_result in scan.results:
            file_result = scan_proberesults(get_result.result_id,
                                            formatted=True, verbose=DEBUG)
            self.assertIn(file_result.status, [-1, 0, 1])
            self.assertEqual(file_result.probes_finished,
                             file_result.probes_total)
            self.assertEqual(len(file_result.probe_results),
                             file_result.probes_total)
            res[get_result.name] = {}
            for pr in file_result.probe_results:
                res[get_result.name][pr.name] = pr
        return res
Example #8
0
 def test_file_results_formatted(self):
     force = False
     probes = probe_list()
     scan = scan_files(FILEPATHS, force, probes)
     while not scan.is_finished():
         time.sleep(1)
         scan = scan_get(scan.id)
     for get_result in scan.results:
         self.assertTrue(self._validate_uuid(str(get_result.result_id)))
         res = scan_proberesults(get_result.result_id)
         self.assertIn(res.name, FILENAMES)
         self.assertEqual(type(res.probe_results), list)
         self.assertEqual(type(res.probe_results[0]), IrmaProbeResult)
         self.assertEqual(len(res.probe_results), res.probes_finished)