1import unittest, os, shutil
2from tempfile import mkdtemp
3from subprocess import Popen, PIPE
4
5class Audit2allowTests(unittest.TestCase):
6    def assertDenied(self, err):
7        self.assert_('Permission denied' in err,
8                     '"Permission denied" not found in %r' % err)
9    def assertNotFound(self, err):
10        self.assert_('not found' in err,
11                     '"not found" not found in %r' % err)
12
13    def assertFailure(self, status):
14        self.assert_(status != 0,
15                     '"Succeeded when it should have failed')
16
17    def assertSuccess(self, cmd, status, err):
18        self.assert_(status == 0,
19                     '"%s should have succeeded for this test %r' %  (cmd, err))
20
21    def test_sepolgen_ifgen(self):
22        "Verify sepolgen-ifgen works"
23        p = Popen(['sudo', 'sepolgen-ifgen'], stdout = PIPE)
24        out, err = p.communicate()
25        if err:
26            print(out, err)
27        self.assertSuccess("sepolgen-ifgen", p.returncode, err)
28
29    def test_audit2allow(self):
30        "Verify audit2allow works"
31        p = Popen(['audit2allow',"-i","test.log"], stdout = PIPE)
32        out, err = p.communicate()
33        if err:
34            print(out, err)
35        self.assertSuccess("audit2allow", p.returncode, err)
36
37    def test_audit2why(self):
38        "Verify audit2why works"
39        p = Popen(['audit2why',"-i","test.log"], stdout = PIPE)
40        out, err = p.communicate()
41        if err:
42            print(out, err)
43        self.assertSuccess("audit2why", p.returncode, err)
44
45if __name__ == "__main__":
46    unittest.main()
47