2015-07-24 08:07:13 +00:00
|
|
|
import unittest
|
|
|
|
import os
|
2019-01-05 19:37:56 +00:00
|
|
|
import os.path
|
|
|
|
import sys
|
2013-10-31 14:53:58 +00:00
|
|
|
from tempfile import mkdtemp
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2013-10-31 14:53:58 +00:00
|
|
|
class Audit2allowTests(unittest.TestCase):
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2013-10-31 14:53:58 +00:00
|
|
|
def assertDenied(self, err):
|
2015-07-21 00:38:19 +00:00
|
|
|
self.assertTrue('Permission denied' in err,
|
2015-07-24 08:07:13 +00:00
|
|
|
'"Permission denied" not found in %r' % err)
|
|
|
|
|
2013-10-31 14:53:58 +00:00
|
|
|
def assertNotFound(self, err):
|
2015-07-21 00:38:19 +00:00
|
|
|
self.assertTrue('not found' in err,
|
2015-07-24 08:07:13 +00:00
|
|
|
'"not found" not found in %r' % err)
|
2013-10-31 14:53:58 +00:00
|
|
|
|
|
|
|
def assertFailure(self, status):
|
2015-07-21 00:38:19 +00:00
|
|
|
self.assertTrue(status != 0,
|
2015-07-24 08:07:13 +00:00
|
|
|
'"Succeeded when it should have failed')
|
2013-10-31 14:53:58 +00:00
|
|
|
|
|
|
|
def assertSuccess(self, cmd, status, err):
|
2015-07-21 00:38:19 +00:00
|
|
|
self.assertTrue(status == 0,
|
2015-07-24 08:07:13 +00:00
|
|
|
'"%s should have succeeded for this test %r' % (cmd, err))
|
2013-10-31 14:53:58 +00:00
|
|
|
|
|
|
|
def test_sepolgen_ifgen(self):
|
|
|
|
"Verify sepolgen-ifgen works"
|
2019-01-05 19:37:56 +00:00
|
|
|
temp_directory = mkdtemp(suffix='audit2allow_test')
|
|
|
|
output_file = os.path.join(temp_directory, 'interface_info')
|
2019-01-05 19:37:57 +00:00
|
|
|
p = Popen([
|
|
|
|
sys.executable, './sepolgen-ifgen', '-p', 'test_dummy_policy', '-o', output_file,
|
|
|
|
'--attr-helper', './sepolgen-ifgen-attr-helper'
|
|
|
|
], stdout=PIPE)
|
2013-10-31 14:53:58 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
if err:
|
|
|
|
print(out, err)
|
|
|
|
self.assertSuccess("sepolgen-ifgen", p.returncode, err)
|
2019-01-05 19:37:56 +00:00
|
|
|
os.unlink(output_file)
|
|
|
|
os.rmdir(temp_directory)
|
2013-10-31 14:53:58 +00:00
|
|
|
|
|
|
|
def test_audit2allow(self):
|
|
|
|
"Verify audit2allow works"
|
2019-01-05 19:37:56 +00:00
|
|
|
p = Popen([sys.executable, './audit2allow', '-p', 'test_dummy_policy', '-i', 'test.log'], stdout=PIPE)
|
2013-10-31 14:53:58 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
if err:
|
|
|
|
print(out, err)
|
|
|
|
self.assertSuccess("audit2allow", p.returncode, err)
|
|
|
|
|
|
|
|
def test_audit2why(self):
|
|
|
|
"Verify audit2why works"
|
2019-01-05 19:37:56 +00:00
|
|
|
p = Popen([sys.executable, './audit2why', '-p', 'test_dummy_policy', '-i', 'test.log'], stdout=PIPE)
|
2013-10-31 14:53:58 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
if err:
|
|
|
|
print(out, err)
|
|
|
|
self.assertSuccess("audit2why", p.returncode, err)
|
|
|
|
|
2018-06-12 09:06:59 +00:00
|
|
|
def test_xperms(self):
|
|
|
|
"Verify that xperms generation works"
|
2019-01-05 19:37:56 +00:00
|
|
|
p = Popen([sys.executable, './audit2allow', '-x', '-p', 'test_dummy_policy', '-i', 'test.log'], stdout=PIPE)
|
2018-06-12 09:06:59 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
if err:
|
|
|
|
print(out, err)
|
|
|
|
self.assertTrue(b"allowxperm" in out)
|
|
|
|
self.assertSuccess("xperms", p.returncode, err)
|
|
|
|
|
2019-01-05 19:37:56 +00:00
|
|
|
|
2013-10-31 14:53:58 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|