2014-02-28 23:12:34 +00:00
|
|
|
# Copyright (C) 2006-2014 Bastian Kleineidam
|
2008-05-20 08:57:37 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
2009-07-24 21:58:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-05-20 08:57:37 +00:00
|
|
|
"""
|
|
|
|
|
Test virus filter.
|
|
|
|
|
"""
|
|
|
|
|
import unittest
|
2010-02-22 07:02:19 +00:00
|
|
|
from tests import need_clamav
|
2014-02-28 23:12:34 +00:00
|
|
|
from linkcheck.plugins import viruscheck as clamav
|
2008-05-20 08:57:37 +00:00
|
|
|
|
|
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
class TestClamav(unittest.TestCase):
|
2014-02-28 23:12:34 +00:00
|
|
|
def setUp(self):
|
|
|
|
|
self.clamav_conf = clamav.get_clamav_conf("/etc/clamav/clamd.conf")
|
|
|
|
|
|
2010-02-22 07:02:19 +00:00
|
|
|
@need_clamav
|
2020-05-16 19:19:42 +00:00
|
|
|
def testClean(self):
|
2019-10-25 11:21:03 +00:00
|
|
|
data = b""
|
2014-02-28 23:12:34 +00:00
|
|
|
infected, errors = clamav.scan(data, self.clamav_conf)
|
2008-05-20 08:57:37 +00:00
|
|
|
self.assertFalse(infected)
|
|
|
|
|
self.assertFalse(errors)
|
|
|
|
|
|
2010-02-22 07:02:19 +00:00
|
|
|
@need_clamav
|
2020-05-16 19:19:42 +00:00
|
|
|
def testInfected(self):
|
2022-09-02 09:20:02 +00:00
|
|
|
# from the clamav test directory: the clamav test file as html data
|
2019-10-25 11:21:03 +00:00
|
|
|
data = (
|
2020-05-28 19:29:13 +00:00
|
|
|
b'<a href="data:application/octet-stream;base64,'
|
|
|
|
|
b"TVpQAAIAAAAEAA8A//8AALgAAAAhAAAAQAAaAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
|
|
|
|
b"AAAAAAAAAAAAAAAAAAAAEAALtxEEAAM8BQUIvzU1NQsClAMARmrHn5ujEAeA2t"
|
|
|
|
|
b"UP9mcA4fvjEA6eX/tAnNIbRMzSFiDAoBAnB2FwIeTgwEL9rMEAAAAAAAAAAAAA"
|
|
|
|
|
b"AAAAAAwBAAAIAQAAAAAAAAAAAAAAAAAADaEAAA9BAAAAAAAAAAAAAAAAAAAAAA"
|
|
|
|
|
b"AAAAAAAAS0VSTkVMMzIuRExMAABFeGl0UHJvY2VzcwBVU0VSMzIuRExMAENMQU"
|
|
|
|
|
b"1lc3NhZ2VCb3hBAOYQAAAAAAAAPz8/P1BFAABMAQEAYUNhQgAAAAAAAAAA4ACO"
|
|
|
|
|
b"gQsBAhkABAAAAAYAAAAAAABAEAAAABAAAEAAAAAAAEAAABAAAAACAAABAAAAAA"
|
|
|
|
|
b"AAAAMACgAAAAAAACAAAAAEAAAAAAAAAgAAAAAAEAAAIAAAAAAQAAAQAAAAAAAA"
|
|
|
|
|
b"EAAAAAAAAAAAAAAAhBAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
|
|
|
|
b"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
|
|
|
|
b"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAW0NMQU1BVl"
|
|
|
|
|
b'0AEAAAABAAAAACAAABAAAAAAAAAAAAAAAAAAAAAAAAwA==">t</a>'
|
2019-10-25 11:21:03 +00:00
|
|
|
)
|
2014-02-28 23:12:34 +00:00
|
|
|
infected, errors = clamav.scan(data, self.clamav_conf)
|
2019-10-22 14:04:09 +00:00
|
|
|
# different versions of clamav report different responses, apparently
|
|
|
|
|
acceptable_responses = (
|
2020-05-29 18:40:46 +00:00
|
|
|
[
|
|
|
|
|
"stream: ClamAV-Test-File(2d1206194bd704385e37000be6113f73:781) FOUND\n"
|
|
|
|
|
],
|
2020-05-28 19:29:13 +00:00
|
|
|
[
|
2020-05-28 19:29:13 +00:00
|
|
|
"stream: Clamav.Test.File-6(aa15bcf478d165efd2065190eb473bcb:544) FOUND\n"
|
2020-05-28 19:29:13 +00:00
|
|
|
],
|
2021-05-19 13:36:16 +00:00
|
|
|
[
|
|
|
|
|
"stream: Clamav.Test.File-6(2d1206194bd704385e37000be6113f73:781) FOUND\n"
|
|
|
|
|
],
|
2019-10-22 14:04:09 +00:00
|
|
|
)
|
|
|
|
|
self.assertIn(infected, acceptable_responses)
|
2008-05-20 08:57:37 +00:00
|
|
|
self.assertFalse(errors)
|