Debian Codegraph @

unit_tests/clamscan/lzh_lha_archive_test.py

raw symbols SCIP
1 # Copyright (C) 2020-2024 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
2
3 """
4 Run clamscan tests.
5 """
6
7 import sys
8
9 sys.path.append('../unit_tests')
10 import testcase
11
12
13 class TC(testcase.TestCase):
14 @classmethod
15 def setUpClass(cls):
16 super(TC, cls).setUpClass()
17
18 # Testing with our logo png file.
19 TC.testfiles = list(TC.path_source.glob('unit_tests/input/other_scanfiles/lha_lzh/*.lzh'))
20
21 @classmethod
22 def tearDownClass(cls):
23 super(TC, cls).tearDownClass()
24
25 def setUp(self):
26 super(TC, self).setUp()
27
28 def tearDown(self):
29 super(TC, self).tearDown()
30 self.verify_valgrind_log()
31
32 def test_good_archives(self):
33 self.step_name('Verify that these LHA archives containing logo.png and cisco-logo.png correctly extract each.')
34
35 (TC.path_tmp / 'good.ldb').write_text(
36 "logo.png;Engine:150-255,Target:0;0;fuzzy_img#af2ad01ed42993c7#0\n"
37 "cisco-logo.png;Engine:150-255,Target:0;0;fuzzy_img#9463944473afd82f#0\n"
38 )
39
40 testfiles = ' '.join([str(testfile) for testfile in TC.testfiles])
41
42 command = '{valgrind} {valgrind_args} {clamscan} -d {path_db} {testfiles} --allmatch'.format(
43 valgrind=TC.valgrind, valgrind_args=TC.valgrind_args, clamscan=TC.clamscan,
44 path_db=TC.path_tmp / 'good.ldb',
45 testfiles=testfiles,
46 )
47 output = self.execute_command(command)
48
49 assert output.ec == 1 # virus
50 assert output.out.count(' logo.png.UNOFFICIAL FOUND') == len(TC.testfiles)
51 assert output.out.count(' cisco-logo.png.UNOFFICIAL FOUND') == len(TC.testfiles)
52
53 expected_stdout = [
54 'logo.png.UNOFFICIAL FOUND',
55 ]
56 unexpected_stdout = [
57 'OK',
58 ]
59 self.verify_output(output.out, expected=expected_stdout)