119323693SBrad Bishop# Copyright (C) 2019 Armin Kuster <akuster808@gmail.com> 219323693SBrad Bishop# 319323693SBrad Bishopimport re 4*c342db35SBrad 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 13*c342db35SBrad Bishop @classmethod 14*c342db35SBrad Bishop def setUpClass(cls): 15*c342db35SBrad Bishop cls.tmp_fd, cls.tmp_path = mkstemp() 16*c342db35SBrad Bishop with os.fdopen(cls.tmp_fd, 'w') as f: 17*c342db35SBrad Bishop # use gooled public dns 18*c342db35SBrad Bishop f.write("nameserver 8.8.8.8") 19*c342db35SBrad Bishop f.write(os.linesep) 20*c342db35SBrad Bishop f.write("nameserver 8.8.4.4") 21*c342db35SBrad Bishop f.write(os.linesep) 22*c342db35SBrad Bishop f.write("nameserver 127.0.0.1") 23*c342db35SBrad Bishop f.write(os.linesep) 24*c342db35SBrad Bishop 25*c342db35SBrad Bishop @classmethod 26*c342db35SBrad Bishop def tearDownClass(cls): 27*c342db35SBrad Bishop os.remove(cls.tmp_path) 28*c342db35SBrad 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']) 38*c342db35SBrad Bishop @OEHasPackage(['openssh-scp', 'dropbear']) 39*c342db35SBrad Bishop def test_ping_clamav_net(self): 40*c342db35SBrad Bishop dst = '/etc/resolv.conf' 41*c342db35SBrad Bishop self.tc.target.run('rm -f %s' % dst) 42*c342db35SBrad Bishop (status, output) = self.tc.target.copyTo(self.tmp_path, dst) 43*c342db35SBrad Bishop msg = 'File could not be copied. Output: %s' % output 44*c342db35SBrad Bishop self.assertEqual(status, 0, msg=msg) 45*c342db35SBrad Bishop 46*c342db35SBrad Bishop status, output = self.target.run('ping -c 1 database.clamav.net') 47*c342db35SBrad Bishop msg = ('ping database.clamav.net failed: output is:\n%s' % output) 48*c342db35SBrad Bishop self.assertEqual(status, 0, msg = msg) 49*c342db35SBrad Bishop 50*c342db35SBrad 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 match = re.search('Database updated', output) 5419323693SBrad Bishop #match = re.search('main.cvd is up to date', output) 5519323693SBrad Bishop if not match: 5619323693SBrad Bishop msg = ('freshclam : DB dowbload failed. ' 5719323693SBrad Bishop 'Status and output:%s and %s' % (status, output)) 5819323693SBrad Bishop self.assertEqual(status, 1, msg = msg) 5919323693SBrad Bishop 6019323693SBrad Bishop @OETestDepends(['clamav.ClamavTest.test_freshclam_download']) 6119323693SBrad Bishop def test_freshclam_check_mirrors(self): 6219323693SBrad Bishop status, output = self.target.run('freshclam --list-mirrors') 6319323693SBrad Bishop match = re.search('Failures: 0', output) 6419323693SBrad Bishop if not match: 6519323693SBrad Bishop msg = ('freshclam --list-mirrors: failed. ' 6619323693SBrad Bishop 'Status and output:%s and %s' % (status, output)) 6719323693SBrad Bishop self.assertEqual(status, 1, msg = msg) 6819323693SBrad Bishop 69