diff options
author | Andrei Belov <defan@nginx.com> | 2020-10-08 19:19:31 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2020-10-08 19:19:31 +0300 |
commit | d586ac9fdc4a86c142b06a75dde4cdacad5b52f6 (patch) | |
tree | 9817282396f9d2cf5333050e4b5bf807d3617e40 /test/test_php_isolation.py | |
parent | 9be35d9b7418c041e5177f273c20f0fd2d3f00ad (diff) | |
parent | ad516735a65fe109773b60e26214a071411f1734 (diff) | |
download | unit-d586ac9fdc4a86c142b06a75dde4cdacad5b52f6.tar.gz unit-d586ac9fdc4a86c142b06a75dde4cdacad5b52f6.tar.bz2 |
Merged with the default branch.1.20.0-1
Diffstat (limited to 'test/test_php_isolation.py')
-rw-r--r-- | test/test_php_isolation.py | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/test/test_php_isolation.py b/test/test_php_isolation.py index 1b70ef02..8ab3419a 100644 --- a/test/test_php_isolation.py +++ b/test/test_php_isolation.py @@ -1,5 +1,6 @@ -import unittest +import pytest +from conftest import option from unit.applications.lang.php import TestApplicationPHP from unit.feature.isolation import TestFeatureIsolation @@ -10,48 +11,77 @@ class TestPHPIsolation(TestApplicationPHP): isolation = TestFeatureIsolation() @classmethod - def setUpClass(cls, complete_check=True): - unit = super().setUpClass(complete_check=False) + def setup_class(cls, complete_check=True): + unit = super().setup_class(complete_check=False) - TestFeatureIsolation().check(cls.available, unit.testdir) + TestFeatureIsolation().check(cls.available, unit.temp_dir) return unit if not complete_check else unit.complete() - def test_php_isolation_rootfs(self): + def test_php_isolation_rootfs(self, is_su): isolation_features = self.available['features']['isolation'].keys() if 'mnt' not in isolation_features: - print('requires mnt ns') - raise unittest.SkipTest() + pytest.skip('requires mnt ns') - if not self.is_su: + if not is_su: if 'user' not in isolation_features: - print('requires unprivileged userns or root') - raise unittest.SkipTest() + pytest.skip('requires unprivileged userns or root') if not 'unprivileged_userns_clone' in isolation_features: - print('requires unprivileged userns or root') - raise unittest.SkipTest() + pytest.skip('requires unprivileged userns or root') isolation = { - 'namespaces': {'credential': not self.is_su, 'mount': True}, - 'rootfs': self.current_dir, + 'namespaces': {'credential': not is_su, 'mount': True}, + 'rootfs': option.test_dir, } self.load('phpinfo', isolation=isolation) - self.assertIn( - 'success', self.conf('"/php/phpinfo"', 'applications/phpinfo/root') + assert 'success' in self.conf( + '"/php/phpinfo"', 'applications/phpinfo/root' ) - self.assertIn( - 'success', - self.conf( - '"/php/phpinfo"', 'applications/phpinfo/working_directory' - ), + assert 'success' in self.conf( + '"/php/phpinfo"', 'applications/phpinfo/working_directory' ) - self.assertEqual(self.get()['status'], 200, 'empty rootfs') + assert self.get()['status'] == 200, 'empty rootfs' + def test_php_isolation_rootfs_extensions(self, is_su): + isolation_features = self.available['features']['isolation'].keys() + + if not is_su: + if 'user' not in isolation_features: + pytest.skip('requires unprivileged userns or root') + + if not 'unprivileged_userns_clone' in isolation_features: + pytest.skip('requires unprivileged userns or root') + + if 'mnt' not in isolation_features: + pytest.skip('requires mnt ns') + + isolation = { + 'rootfs': option.test_dir, + 'namespaces': {'credential': not is_su, 'mount': not is_su}, + } + + self.load('list-extensions', isolation=isolation) + + assert 'success' in self.conf( + '"/php/list-extensions"', 'applications/list-extensions/root' + ) + + assert 'success' in self.conf( + {'file': '/php/list-extensions/php.ini'}, + 'applications/list-extensions/options', + ) + + assert 'success' in self.conf( + '"/php/list-extensions"', + 'applications/list-extensions/working_directory', + ) + + extensions = self.getjson()['body'] -if __name__ == '__main__': - TestPHPIsolation.main() + assert 'json' in extensions, 'json in extensions list' + assert 'unit' in extensions, 'unit in extensions list' |