| 
									
										
										
										
											2025-02-14 10:24:30 -05:00
										 |  |  | # Copyright (C) 2020-2025 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | 
					
						
							| 
									
										
										
										
											2024-06-07 10:20:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | Run clamscan tests. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | import shutil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sys.path.append('../unit_tests') | 
					
						
							|  |  |  | import testcase | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TC(testcase.TestCase): | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def setUpClass(cls): | 
					
						
							|  |  |  |         super(TC, cls).setUpClass() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def tearDownClass(cls): | 
					
						
							|  |  |  |         super(TC, cls).tearDownClass() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         super(TC, self).setUp() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def tearDown(self): | 
					
						
							|  |  |  |         super(TC, self).tearDown() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Remove scan temps directory between tests | 
					
						
							|  |  |  |         if (self.path_tmp / "TD").exists(): | 
					
						
							|  |  |  |             shutil.rmtree(self.path_tmp / "TD") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.verify_valgrind_log() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_save_links(self): | 
					
						
							|  |  |  |         self.step_name('Extract Links') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         tempdir=self.path_tmp / "TD" | 
					
						
							|  |  |  |         if not os.path.isdir(tempdir): | 
					
						
							| 
									
										
										
										
											2025-04-07 16:50:09 -07:00
										 |  |  |             os.makedirs(tempdir) | 
					
						
							| 
									
										
										
										
											2024-06-07 10:20:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         testfile = TC.path_source / 'unit_tests' / 'input' / 'other_scanfiles' / 'html' / 'index.html' | 
					
						
							|  |  |  |         command = '{valgrind} {valgrind_args} {clamscan} -d {path_db} --gen-json --leave-temps --tempdir={tempdir} {testfile}'.format( | 
					
						
							|  |  |  |             valgrind=TC.valgrind, valgrind_args=TC.valgrind_args, clamscan=TC.clamscan, | 
					
						
							|  |  |  |             path_db=TC.path_source / 'unit_tests' / 'input' / 'other_sigs' / 'Clamav-Unit-Test-Signature.ndb', | 
					
						
							|  |  |  |             tempdir=tempdir, | 
					
						
							|  |  |  |             testfile=testfile, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         output = self.execute_command(command) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         assert output.ec == 0  # clean | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-07 16:50:09 -07:00
										 |  |  |         expected_strings = [ | 
					
						
							|  |  |  |             'URIs', | 
					
						
							|  |  |  |             '"https://www.clamav.net/reports/malware"', | 
					
						
							|  |  |  |             '"http://www.google.com"' | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2024-06-07 10:20:57 -07:00
										 |  |  |         self.verify_metadata_json(tempdir, expected_strings) |