Test about privileged action

This commit is contained in:
Fedor Gogolev
2014-03-11 09:24:42 +04:00
parent 8fc964ec43
commit 0518507fa4
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env python
from os import getuid, geteuid, getgid, getegid
from sys import argv
from time import sleep
from daemonize import Daemonize
pid = argv[1]
log = argv[2]
def priv():
return open(log, "w"),
def main(f):
uids = getuid(), geteuid()
gids = getgid(), getegid()
f.write(" ".join(map(str, uids + gids)))
daemon = Daemonize(app="test_app", pid=pid, action=main, user="nobody", group="nobody",
privileged_action=priv)
daemon.start()

View File

@@ -71,5 +71,17 @@ class UidGidTest(unittest.TestCase):
with open(self.logfile, "r") as f:
self.assertEqual(f.read(), " ".join(map(str, [nobody_uid] * 2 + [nobody_gid] * 2)))
@unittest.skipIf(os.getuid() != 0, "Requires supersuer privileges.")
def test_uid_gid_action(self):
nobody_uid = pwd.getpwnam("nobody").pw_uid
nobody_gid = grp.getgrnam("nobody").gr_gid
os.chown(self.pidfile, nobody_uid, nobody_gid)
os.system("python tests/daemon_uid_gid_action.py %s %s" % (self.pidfile, self.logfile))
sleep(.1)
with open(self.logfile, "r") as f:
self.assertEqual(f.read(), " ".join(map(str, [nobody_uid] * 2 + [nobody_gid] * 2)))
if __name__ == '__main__':
unittest.main()