blob: 7f052ecd764abbf8cec6f1a4f5747ee1b1e2ab62 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001# Copyright (C) 2019 Armin Kuster <akuster808@gmail.com>
2#
3import re
Brad Bishop9a533952019-12-19 16:39:26 -05004from tempfile import mkstemp
Brad Bishop19323692019-04-05 15:28:33 -04005
6from oeqa.runtime.case import OERuntimeTestCase
7from oeqa.core.decorator.depends import OETestDepends
8from oeqa.runtime.decorator.package import OEHasPackage
9
10
11class SuricataTest(OERuntimeTestCase):
12
Brad Bishop9a533952019-12-19 16:39:26 -050013 @classmethod
14 def setUpClass(cls):
15 cls.tmp_fd, cls.tmp_path = mkstemp()
16 with os.fdopen(cls.tmp_fd, 'w') as f:
17 # use google public dns
18 f.write("nameserver 8.8.8.8")
19 f.write(os.linesep)
20 f.write("nameserver 8.8.4.4")
21 f.write(os.linesep)
22 f.write("nameserver 127.0.0.1")
23 f.write(os.linesep)
24
25 @classmethod
26 def tearDownClass(cls):
27 os.remove(cls.tmp_path)
28
Brad Bishop19323692019-04-05 15:28:33 -040029 @OEHasPackage(['suricata'])
30 @OETestDepends(['ssh.SSHTest.test_ssh'])
31 def test_suricata_help(self):
32 status, output = self.target.run('suricata --help')
33 msg = ('suricata command does not work as expected. '
34 'Status and output:%s and %s' % (status, output))
35 self.assertEqual(status, 1, msg = msg)
36
37 @OETestDepends(['suricata.SuricataTest.test_suricata_help'])
Brad Bishop9a533952019-12-19 16:39:26 -050038 def test_ping_openinfosecfoundation_org(self):
39 dst = '/etc/resolv.conf'
40 self.tc.target.run('rm -f %s' % dst)
41 (status, output) = self.tc.target.copyTo(self.tmp_path, dst)
42 msg = 'File could not be copied. Output: %s' % output
43 self.assertEqual(status, 0, msg=msg)
44
45 status, output = self.target.run('ping -c 1 openinfosecfoundation.org')
46 msg = ('ping openinfosecfoundation.org failed: output is:\n%s' % output)
47 self.assertEqual(status, 0, msg = msg)
48
49 @OEHasPackage(['python3-suricata-update'])
50 @OETestDepends(['suricata.SuricataTest.test_ping_openinfosecfoundation_org'])
51 def test_suricata_update(self):
52 status, output = self.tc.target.run('suricata-update')
53 msg = ('suricata-update had an unexpected failure. '
54 'Status and output:%s and %s' % (status, output))
55 self.assertEqual(status, 0, msg = msg)
56
57 @OETestDepends(['suricata.SuricataTest.test_suricata_update'])
58 def test_suricata_update_sources_list(self):
59 status, output = self.tc.target.run('suricata-update list-sources')
60 msg = ('suricata-update list-sources had an unexpected failure. '
61 'Status and output:%s and %s' % (status, output))
62 self.assertEqual(status, 0, msg = msg)
63
64 @OETestDepends(['suricata.SuricataTest.test_suricata_update_sources_list'])
65 def test_suricata_update_sources(self):
66 status, output = self.tc.target.run('suricata-update update-sources')
67 msg = ('suricata-update update-sources had an unexpected failure. '
68 'Status and output:%s and %s' % (status, output))
69 self.assertEqual(status, 0, msg = msg)
70
71 @OETestDepends(['suricata.SuricataTest.test_suricata_update_sources'])
72 def test_suricata_update_enable_source(self):
73 status, output = self.tc.target.run('suricata-update enable-source oisf/trafficid')
74 msg = ('suricata-update enable-source oisf/trafficid had an unexpected failure. '
75 'Status and output:%s and %s' % (status, output))
76 self.assertEqual(status, 0, msg = msg)