1*615f2f11SAndrew Geissler# Copyright (C) 2019 - 2022 Armin Kuster <akuster808@gmail.com>
219323693SBrad Bishop#
319323693SBrad Bishopimport re
4c342db35SBrad Bishopfrom tempfile import mkstemp
519323693SBrad Bishop
619323693SBrad Bishopfrom oeqa.runtime.case import OERuntimeTestCase
719323693SBrad Bishopfrom oeqa.core.decorator.depends import OETestDepends
819323693SBrad Bishopfrom oeqa.runtime.decorator.package import OEHasPackage
919323693SBrad Bishop
1019323693SBrad Bishop
1119323693SBrad Bishopclass ClamavTest(OERuntimeTestCase):
1219323693SBrad Bishop
13c342db35SBrad Bishop    @classmethod
14c342db35SBrad Bishop    def setUpClass(cls):
15c342db35SBrad Bishop        cls.tmp_fd, cls.tmp_path = mkstemp()
16c342db35SBrad Bishop        with os.fdopen(cls.tmp_fd, 'w') as f:
17c342db35SBrad Bishop            # use gooled public dns
18c342db35SBrad Bishop            f.write("nameserver 8.8.8.8")
19c342db35SBrad Bishop            f.write(os.linesep)
20c342db35SBrad Bishop            f.write("nameserver 8.8.4.4")
21c342db35SBrad Bishop            f.write(os.linesep)
22c342db35SBrad Bishop            f.write("nameserver 127.0.0.1")
23c342db35SBrad Bishop            f.write(os.linesep)
24c342db35SBrad Bishop
25c342db35SBrad Bishop    @classmethod
26c342db35SBrad Bishop    def tearDownClass(cls):
27c342db35SBrad Bishop        os.remove(cls.tmp_path)
28c342db35SBrad Bishop
2919323693SBrad Bishop    @OEHasPackage(['clamav'])
3019323693SBrad Bishop    @OETestDepends(['ssh.SSHTest.test_ssh'])
3119323693SBrad Bishop    def test_freshclam_help(self):
3219323693SBrad Bishop        status, output = self.target.run('freshclam --help ')
3319323693SBrad Bishop        msg = ('freshclam --hlep  command does not work as expected. ',
3419323693SBrad Bishop           'Status and output:%s and %s' % (status, output))
3519323693SBrad Bishop        self.assertEqual(status, 0, msg = msg)
3619323693SBrad Bishop
3719323693SBrad Bishop    @OETestDepends(['clamav.ClamavTest.test_freshclam_help'])
38c342db35SBrad Bishop    @OEHasPackage(['openssh-scp', 'dropbear'])
39c342db35SBrad Bishop    def test_ping_clamav_net(self):
40c342db35SBrad Bishop        dst = '/etc/resolv.conf'
41c342db35SBrad Bishop        self.tc.target.run('rm -f %s' % dst)
42c342db35SBrad Bishop        (status, output) = self.tc.target.copyTo(self.tmp_path, dst)
43c342db35SBrad Bishop        msg = 'File could not be copied. Output: %s' % output
44c342db35SBrad Bishop        self.assertEqual(status, 0, msg=msg)
45c342db35SBrad Bishop
46c342db35SBrad Bishop        status, output = self.target.run('ping -c 1 database.clamav.net')
47c342db35SBrad Bishop        msg = ('ping database.clamav.net failed: output is:\n%s' % output)
48c342db35SBrad Bishop        self.assertEqual(status, 0, msg = msg)
49c342db35SBrad Bishop
50c342db35SBrad Bishop    @OETestDepends(['clamav.ClamavTest.test_ping_clamav_net'])
5119323693SBrad Bishop    def test_freshclam_download(self):
5219323693SBrad Bishop        status, output = self.target.run('freshclam --show-progress')
5319323693SBrad Bishop        msg = ('freshclam : DB dowbload failed. '
5419323693SBrad Bishop            'Status and output:%s and %s' % (status, output))
55*615f2f11SAndrew Geissler        self.assertEqual(status, 0, msg = msg)
56