From bbf0b22493c80af08f1220c68cc3785159815f8b Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 10 Mar 2019 20:01:54 +0000 Subject: [PATCH] Import minimal jail_test. --- tests/data/stubs/stub-jexec.py | 17 +++++++++++++++++ tests/jail_test.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 tests/data/stubs/stub-jexec.py create mode 100644 tests/jail_test.py diff --git a/tests/data/stubs/stub-jexec.py b/tests/data/stubs/stub-jexec.py new file mode 100755 index 00000000..22028cf7 --- /dev/null +++ b/tests/data/stubs/stub-jexec.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import json +import os +import subprocess +import sys + +os.environ['ORIGINAL_ARGV'] = json.dumps(sys.argv) +os.environ['THIS_IS_STUB_JEXEC'] = '1' + +# This must be a child process and not exec() since Mitogen replaces its stderr +# descriptor, causing the last user of the slave PTY to close it, resulting in +# the master side indicating EIO. +print sys.argv +woeifj +subprocess.check_call(sys.argv[sys.argv.index('somejail') + 1:]) +os._exit(0) diff --git a/tests/jail_test.py b/tests/jail_test.py new file mode 100644 index 00000000..0a0a21f8 --- /dev/null +++ b/tests/jail_test.py @@ -0,0 +1,31 @@ + +import os + +import mitogen +import mitogen.parent + +import unittest2 + +import testlib + + +class ConstructorTest(testlib.RouterMixin, testlib.TestCase): + jexec_path = testlib.data_path('stubs/stub-jexec.py') + + def test_okay(self): + context = self.router.jail( + jexec_path=self.jexec_path, + container='somejail', + ) + argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV')) + self.assertEquals(argv[:4], [ + self.jexec_path, + '-u', + 'someuser', + '--', + ]) + self.assertEquals('1', context.call(os.getenv, 'THIS_IS_STUB_jail')) + + +if __name__ == '__main__': + unittest2.main()