diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/oeqa/runtime/cases/suricata.py | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/lib/oeqa/runtime/cases/suricata.py b/lib/oeqa/runtime/cases/suricata.py index 17fc8c5..7f052ec 100644 --- a/lib/oeqa/runtime/cases/suricata.py +++ b/lib/oeqa/runtime/cases/suricata.py | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | # Copyright (C) 2019 Armin Kuster <akuster808@gmail.com> | 1 | # Copyright (C) 2019 Armin Kuster <akuster808@gmail.com> |
| 2 | # | 2 | # |
| 3 | import re | 3 | import re |
| 4 | from tempfile import mkstemp | ||
| 4 | 5 | ||
| 5 | from oeqa.runtime.case import OERuntimeTestCase | 6 | from oeqa.runtime.case import OERuntimeTestCase |
| 6 | from oeqa.core.decorator.depends import OETestDepends | 7 | from oeqa.core.decorator.depends import OETestDepends |
| @@ -9,6 +10,22 @@ from oeqa.runtime.decorator.package import OEHasPackage | |||
| 9 | 10 | ||
| 10 | class SuricataTest(OERuntimeTestCase): | 11 | class SuricataTest(OERuntimeTestCase): |
| 11 | 12 | ||
| 13 | @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 | |||
| 12 | @OEHasPackage(['suricata']) | 29 | @OEHasPackage(['suricata']) |
| 13 | @OETestDepends(['ssh.SSHTest.test_ssh']) | 30 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
| 14 | def test_suricata_help(self): | 31 | def test_suricata_help(self): |
| @@ -18,10 +35,42 @@ class SuricataTest(OERuntimeTestCase): | |||
| 18 | self.assertEqual(status, 1, msg = msg) | 35 | self.assertEqual(status, 1, msg = msg) |
| 19 | 36 | ||
| 20 | @OETestDepends(['suricata.SuricataTest.test_suricata_help']) | 37 | @OETestDepends(['suricata.SuricataTest.test_suricata_help']) |
| 21 | def test_suricata_unittest(self): | 38 | def test_ping_openinfosecfoundation_org(self): |
| 22 | status, output = self.target.run('suricata -u') | 39 | dst = '/etc/resolv.conf' |
| 23 | match = re.search('FAILED: 0 ', output) | 40 | self.tc.target.run('rm -f %s' % dst) |
| 24 | if not match: | 41 | (status, output) = self.tc.target.copyTo(self.tmp_path, dst) |
| 25 | msg = ('suricata unittest had an unexpected failure. ' | 42 | msg = 'File could not be copied. Output: %s' % output |
| 26 | 'Status and output:%s and %s' % (status, output)) | 43 | self.assertEqual(status, 0, msg=msg) |
| 27 | 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) | ||
