Skip to content

Commit

Permalink
blah
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Jul 10, 2024
1 parent afc233d commit 594f4b1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
76 changes: 76 additions & 0 deletions unit_tests/clamscan/save_html_urls_test.py
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)



16 changes: 16 additions & 0 deletions unit_tests/input/other_scanfiles/html/index.html
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>

0 comments on commit 594f4b1

Please sign in to comment.