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