Example #1
0
 def setUp(self):
     # setup test
     cwd = os.path.abspath(os.path.dirname(__file__))
     self.filepath = os.path.join(cwd, EICAR_FILE)
     self.filename = os.path.basename(self.filepath)
     self.probelist = probe_list(verbose=DEBUG)
     assert os.path.exists(self.filepath)
Example #2
0
 def test_file_search_hash(self):
     force = False
     probes = probe_list()
     scan_files(FILEPATHS, force, probes, blocking=True)
     for hash in HASHES:
         (_, res) = file_search(hash=hash)
         self.assertTrue(len(res) > 0)
         self.assertEqual(type(res[0]), IrmaResults)
Example #3
0
 def test_scan_get(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)
     self._check_scan(scan, scan.id, ["finished"],
                      FILENAMES, [scan.probes_total], [scan.probes_total],
                      scan.date, force, True, True)
Example #4
0
 def test_zip(self):
     probelist = probe_list()
     probe = u"Unarchive"
     if probe not in probelist:
         raise unittest.SkipTest("Skipping %s not present" % probe)
     force = True
     sample = os.path.join(SAMPLES_DIR, ZIP_SAMPLE)
     scan = scan_files([sample], force, probe=[probe], blocking=True)
     self.assertEqual(len(scan.results), 2)
     self.assertEqual(scan.probes_finished, 1)
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_scan_all_probes(self):
     filelist = [self.filepath]
     probelist = probe_list()
     # remove Virustotal from grouped scan as public API is limited
     # to 4 requests per minute
     try:
         probelist.remove('VirusTotal')
     except ValueError:
         pass
     res = self._test_scan_file(filelist, probelist, force=True)
     self.check_eicar_results(res[self.filename])
Example #7
0
 def test_file_search_name(self):
     force = False
     probes = probe_list()
     scan_files(FILEPATHS, force, probes, blocking=True)
     for name in FILENAMES:
         data = file_search(name=name)
         self.assertEqual(type(data), tuple)
         (total, res) = file_search(name, limit=1)
         self.assertEqual(type(res), list)
         self.assertEqual(type(res[0]), IrmaResults)
         self.assertEqual(len(res), 1)
         self.assertEqual(type(total), int)
Example #8
0
 def test_scan_files(self):
     force = True
     probes = probe_list()
     nb_jobs = len(FILENAMES) * len(probes)
     scan = scan_files(FILEPATHS, force, probe=probes)
     self._check_scan(scan, scan.id, ["ready", "uploaded", "launched"],
                      FILENAMES, range(nb_jobs), range(nb_jobs + 1),
                      scan.date, True, True, True)
     scan = scan_cancel(scan.id)
     self._check_scan(scan, scan.id, ["cancelled"],
                      FILENAMES, range(nb_jobs), range(nb_jobs + 1),
                      scan.date, True, True, True)
Example #9
0
 def test_scan_launch(self):
     scan = scan_new()
     date = scan.date
     scanid = scan.id
     scan = scan_add(scan.id, FILEPATHS)
     force = False
     probes = probe_list()
     nb_jobs = len(FILENAMES) * len(probes)
     scan = scan_launch(scan.id, force, probes)
     self._check_scan(scan, scanid, ["ready", "uploaded",
                                     "launched", "finished"],
                      FILENAMES, range(nb_jobs + 1), range(nb_jobs + 1),
                      date, force, True, True)
Example #10
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)
Example #11
0
 def test_resubmit_files(self):
     scan = scan_new()
     date = scan.date
     scanid = scan.id
     scan = scan_add(scan.id, FILEPATHS)
     force = True
     resubmit_files = False
     probes = probe_list()
     nb_jobs = len(FILENAMES) * len(probes)
     scan = scan_launch(scan.id, force, probe=probes,
                        resubmit_files=resubmit_files)
     self._check_scan(scan, scanid, ["ready", "uploaded", "launched"],
                      FILENAMES, range(nb_jobs), range(nb_jobs + 1),
                      date, force, True, resubmit_files)
     scan = scan_cancel(scan.id)
     self._check_scan(scan, scanid, ["cancelled"],
                      FILENAMES, range(nb_jobs), range(nb_jobs + 1),
                      date, force, True, resubmit_files)
Example #12
0
 def test_mimetype_filtering(self):
     scan = scan_new()
     date = scan.date
     scanid = scan.id
     scan = scan_add(scan.id, FILEPATHS)
     force = True
     mimetype_filtering = False
     probes = probe_list()
     nb_jobs = len(FILENAMES) * len(probes)
     scan = scan_launch(scan.id, force, probes,
                        mimetype_filtering=mimetype_filtering)
     self._check_scan(scan, scanid, ["ready", "uploaded", "launched"],
                      FILENAMES, range(nb_jobs), range(nb_jobs + 1),
                      date, force, mimetype_filtering, True)
     scan = scan_cancel(scan.id)
     self._check_scan(scan, scanid, ["cancelled"],
                      FILENAMES, range(nb_jobs), range(nb_jobs + 1),
                      date, force, mimetype_filtering, True)
Example #13
0
 def test_probe_list(self):
     probelist = probe_list()
     self.assertIs(type(probelist), list)
     self.assertNotEqual(len(probelist), 0)
Example #14
0
 def test_scan_files_timeout(self):
     force = True
     probes = probe_list()
     with self.assertRaises(IrmaError):
         scan_files(FILEPATHS, force, probe=[probes[0]], blocking=True,
                    blocking_timeout=0)