-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright (C) 2020-2024 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | ||
|
||
""" | ||
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() | ||
|
||
# Find the metadata.json file and verify its contents. | ||
#TODO: REMOVE THIS WHEN https://github.com/Cisco-Talos/clamav/pull/1295 is merged | ||
def verify_metadata_json(self, tempdir, expected=[], unexpected=[]): | ||
for parent, dirs, files in os.walk(tempdir): | ||
for f in files: | ||
if "metadata.json" == f: | ||
with open(os.path.join(parent, f)) as handle: | ||
metadata_json = handle.read() | ||
self.verify_output(metadata_json, expected=expected, unexpected=unexpected) | ||
|
||
# There is only one metadata.json per scan. | ||
# We found it, so we can break out of the loop. | ||
break | ||
|
||
def test_save_links(self): | ||
self.step_name('Extract Links') | ||
|
||
tempdir=self.path_tmp / "TD" | ||
if not os.path.isdir(tempdir): | ||
os.makedirs(tempdir); | ||
|
||
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 | ||
|
||
expected_strings = [ 'HTMLUrls' | ||
, '"https://www.clamav.net/reports/malware"' | ||
, '"http://www.google.com"' | ||
] | ||
self.verify_metadata_json(tempdir, expected_strings) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h1>Save Links Unittest</h1> | ||
<p>Paragraph</p> | ||
<a href="https://www.clamav.net/reports/malware">Report Malware</a> | ||
|
||
<form action="http://www.google.com"> | ||
<input type="submit"> | ||
</form> | ||
|
||
|
||
</body> | ||
</html> | ||
|