2015-07-24 08:07:13 +00:00
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
import shutil
|
2013-10-11 13:55:35 +00:00
|
|
|
from tempfile import mkdtemp
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2013-10-11 13:55:35 +00:00
|
|
|
class SepolicyTests(unittest.TestCase):
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2013-10-11 13:55:35 +00:00
|
|
|
def assertDenied(self, err):
|
|
|
|
self.assert_('Permission denied' in err,
|
|
|
|
'"Permission denied" not found in %r' % err)
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2013-10-11 13:55:35 +00:00
|
|
|
def assertNotFound(self, err):
|
|
|
|
self.assert_('not found' in err,
|
|
|
|
'"not found" not found in %r' % err)
|
|
|
|
|
|
|
|
def assertFailure(self, status):
|
2016-08-08 19:47:07 +00:00
|
|
|
self.assertNotEqual(status, 0,
|
|
|
|
'Succeeded when it should have failed')
|
2013-10-11 13:55:35 +00:00
|
|
|
|
|
|
|
def assertSuccess(self, status, err):
|
2016-08-08 19:47:07 +00:00
|
|
|
self.assertEqual(status, 0,
|
|
|
|
'sepolicy should have succeeded for this test %r' % err)
|
2013-10-11 13:55:35 +00:00
|
|
|
|
|
|
|
def test_man_domain(self):
|
|
|
|
"Verify sepolicy manpage -d works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'manpage', '-d', 'httpd_t'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_man_all(self):
|
|
|
|
"Verify sepolicy manpage -a works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'manpage', '-a'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_network_l(self):
|
|
|
|
"Verify sepolicy network -l works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'network', '-l'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_network_t(self):
|
|
|
|
"Verify sepolicy network -t works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'network', '-t', 'http_port_t'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_network_p(self):
|
|
|
|
"Verify sepolicy network -p works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'network', '-p', '80'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_network_d(self):
|
|
|
|
"Verify sepolicy network -d works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'network', '-d', 'httpd_t'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_transition_s(self):
|
2017-07-27 13:10:50 +00:00
|
|
|
"Verify sepolicy transition -s works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'transition', '-s', 'httpd_t'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_transition_t(self):
|
|
|
|
"Verify sepolicy transition -t works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'transition', '-s', 'httpd_t', '-t', 'sendmail_t'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_booleans_a(self):
|
|
|
|
"Verify sepolicy booleans -a works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'booleans', '-a'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_booleans_b_alias(self):
|
|
|
|
"Verify sepolicy booleans -b works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'booleans', '-b', 'allow_ypbind'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_booleans_b(self):
|
|
|
|
"Verify sepolicy booleans -b works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'booleans', '-b', 'nis_enabled'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_interface_l(self):
|
|
|
|
"Verify sepolicy interface -l works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'interface', '-l'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_interface_a(self):
|
|
|
|
"Verify sepolicy interface -a works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'interface', '-a'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_interface_p(self):
|
|
|
|
"Verify sepolicy interface -u works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'interface', '-u'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
def test_interface_ci(self):
|
|
|
|
"Verify sepolicy interface -c -i works"
|
2015-07-24 08:07:13 +00:00
|
|
|
p = Popen(['sepolicy', 'interface', '-c', '-i', 'apache_admin'], stdout=PIPE)
|
2013-10-11 13:55:35 +00:00
|
|
|
out, err = p.communicate()
|
|
|
|
self.assertSuccess(p.returncode, err)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import selinux
|
2017-01-14 14:40:24 +00:00
|
|
|
if selinux.is_selinux_enabled() and selinux.security_getenforce() == 1:
|
2013-10-11 13:55:35 +00:00
|
|
|
unittest.main()
|
|
|
|
else:
|
2016-08-08 19:47:07 +00:00
|
|
|
print("SELinux must be in enforcing mode for this test")
|