From 244ffb2829cfbac26e013988474184d6050504fe Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Tue, 25 Aug 2020 13:48:33 +0100 Subject: Tests: PHP extension mounts. --- test/test_php_isolation.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'test/test_php_isolation.py') diff --git a/test/test_php_isolation.py b/test/test_php_isolation.py index 1b70ef02..abaf70a2 100644 --- a/test/test_php_isolation.py +++ b/test/test_php_isolation.py @@ -52,6 +52,60 @@ class TestPHPIsolation(TestApplicationPHP): self.assertEqual(self.get()['status'], 200, 'empty rootfs') + def test_php_isolation_rootfs_extensions(self): + isolation_features = self.available['features']['isolation'].keys() + + if not self.is_su: + if 'user' not in isolation_features: + print('requires unprivileged userns or root') + raise unittest.SkipTest() + + if not 'unprivileged_userns_clone' in isolation_features: + print('requires unprivileged userns or root') + raise unittest.SkipTest() + + if 'mnt' not in isolation_features: + print('requires mnt ns') + raise unittest.SkipTest() + + isolation = { + 'rootfs': self.current_dir, + 'namespaces': { + 'credential': not self.is_su, + 'mount': not self.is_su, + }, + } + + self.load('list-extensions', isolation=isolation) + + self.assertIn( + 'success', + self.conf( + '"/php/list-extensions"', 'applications/list-extensions/root' + ), + ) + + self.assertIn( + 'success', + self.conf( + {'file': '/php/list-extensions/php.ini'}, + 'applications/list-extensions/options', + ), + ) + + self.assertIn( + 'success', + self.conf( + '"/php/list-extensions"', + 'applications/list-extensions/working_directory', + ), + ) + + extensions = self.getjson()['body'] + + self.assertIn('json', extensions, 'json in extensions list') + self.assertIn('unit', extensions, 'unit in extensions list') + if __name__ == '__main__': TestPHPIsolation.main() -- cgit From d1bdaf98ba15cdba62e1f2ecb83c37e08728682c Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Tue, 25 Aug 2020 15:27:51 +0100 Subject: Tests: disable of language_deps. --- test/test_php_isolation.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'test/test_php_isolation.py') diff --git a/test/test_php_isolation.py b/test/test_php_isolation.py index abaf70a2..3004a7b8 100644 --- a/test/test_php_isolation.py +++ b/test/test_php_isolation.py @@ -107,5 +107,74 @@ class TestPHPIsolation(TestApplicationPHP): self.assertIn('unit', extensions, 'unit in extensions list') + def test_php_isolation_rootfs_no_language_libs(self): + isolation_features = self.available['features']['isolation'].keys() + + if not self.is_su: + if 'user' not in isolation_features: + print('requires unprivileged userns or root') + raise unittest.SkipTest() + + if not 'unprivileged_userns_clone' in isolation_features: + print('requires unprivileged userns or root') + raise unittest.SkipTest() + + if 'mnt' not in isolation_features: + print('requires mnt ns') + raise unittest.SkipTest() + + isolation = { + 'rootfs': self.current_dir, + 'automount': {'language_deps': False}, + 'namespaces': { + 'credential': not self.is_su, + 'mount': not self.is_su, + }, + } + + self.load('list-extensions', isolation=isolation) + + self.assertIn( + 'success', + self.conf( + '"/php/list-extensions"', 'applications/list-extensions/root' + ), + ) + + self.assertIn( + 'success', + self.conf( + {'file': '/php/list-extensions/php.ini'}, + 'applications/list-extensions/options', + ), + ) + + self.assertIn( + 'success', + self.conf( + '"/php/list-extensions"', + 'applications/list-extensions/working_directory', + ), + ) + + extensions = self.getjson()['body'] + + self.assertIn('unit', extensions, 'unit in extensions list') + self.assertNotIn('json', extensions, 'json not in extensions list') + + self.assertIn( + 'success', + self.conf( + {'language_deps': True}, + 'applications/list-extensions/isolation/automount', + ), + ) + + extensions = self.getjson()['body'] + + self.assertIn('unit', extensions, 'unit in extensions list 2') + self.assertIn('json', extensions, 'json in extensions list 2') + + if __name__ == '__main__': TestPHPIsolation.main() -- cgit From d5e915934066c77a59d211efafca10c117b73d05 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 16 Sep 2020 21:31:15 +0100 Subject: Tests: migrated to the pytest. --- test/test_php_isolation.py | 154 +++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 98 deletions(-) (limited to 'test/test_php_isolation.py') diff --git a/test/test_php_isolation.py b/test/test_php_isolation.py index 3004a7b8..f4170f1b 100644 --- a/test/test_php_isolation.py +++ b/test/test_php_isolation.py @@ -1,7 +1,8 @@ -import unittest +import pytest from unit.applications.lang.php import TestApplicationPHP from unit.feature.isolation import TestFeatureIsolation +from conftest import option class TestPHPIsolation(TestApplicationPHP): @@ -10,171 +11,128 @@ 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): + def test_php_isolation_rootfs_extensions(self, is_su): isolation_features = self.available['features']['isolation'].keys() - 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') if 'mnt' not in isolation_features: - print('requires mnt ns') - raise unittest.SkipTest() + pytest.skip('requires mnt ns') isolation = { - 'rootfs': self.current_dir, - 'namespaces': { - 'credential': not self.is_su, - 'mount': not self.is_su, - }, + 'rootfs': option.test_dir, + 'namespaces': {'credential': not is_su, 'mount': not is_su}, } self.load('list-extensions', isolation=isolation) - self.assertIn( - 'success', - self.conf( - '"/php/list-extensions"', 'applications/list-extensions/root' - ), + assert 'success' in self.conf( + '"/php/list-extensions"', 'applications/list-extensions/root' ) - self.assertIn( - 'success', - self.conf( - {'file': '/php/list-extensions/php.ini'}, - 'applications/list-extensions/options', - ), + assert 'success' in self.conf( + {'file': '/php/list-extensions/php.ini'}, + 'applications/list-extensions/options', ) - self.assertIn( - 'success', - self.conf( - '"/php/list-extensions"', - 'applications/list-extensions/working_directory', - ), + assert 'success' in self.conf( + '"/php/list-extensions"', + 'applications/list-extensions/working_directory', ) extensions = self.getjson()['body'] - self.assertIn('json', extensions, 'json in extensions list') - self.assertIn('unit', extensions, 'unit in extensions list') + assert 'json' in extensions, 'json in extensions list' + assert 'unit' in extensions, 'unit in extensions list' - - def test_php_isolation_rootfs_no_language_libs(self): + def test_php_isolation_rootfs_no_language_libs(self, is_su): isolation_features = self.available['features']['isolation'].keys() - 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') if 'mnt' not in isolation_features: - print('requires mnt ns') - raise unittest.SkipTest() + pytest.skip('requires mnt ns') isolation = { - 'rootfs': self.current_dir, + 'rootfs': option.test_dir, 'automount': {'language_deps': False}, - 'namespaces': { - 'credential': not self.is_su, - 'mount': not self.is_su, - }, + 'namespaces': {'credential': not is_su, 'mount': not is_su}, } self.load('list-extensions', isolation=isolation) - self.assertIn( - 'success', - self.conf( - '"/php/list-extensions"', 'applications/list-extensions/root' - ), + assert 'success' in self.conf( + '"/php/list-extensions"', 'applications/list-extensions/root' ) - self.assertIn( - 'success', - self.conf( - {'file': '/php/list-extensions/php.ini'}, - 'applications/list-extensions/options', - ), + assert 'success' in self.conf( + {'file': '/php/list-extensions/php.ini'}, + 'applications/list-extensions/options', ) - self.assertIn( - 'success', - self.conf( - '"/php/list-extensions"', - 'applications/list-extensions/working_directory', - ), + assert 'success' in self.conf( + '"/php/list-extensions"', + 'applications/list-extensions/working_directory', ) extensions = self.getjson()['body'] - self.assertIn('unit', extensions, 'unit in extensions list') - self.assertNotIn('json', extensions, 'json not in extensions list') + assert 'unit' in extensions, 'unit in extensions list' + assert 'json' not in extensions, 'json not in extensions list' - self.assertIn( - 'success', - self.conf( - {'language_deps': True}, - 'applications/list-extensions/isolation/automount', - ), + assert 'success' in self.conf( + {'language_deps': True}, + 'applications/list-extensions/isolation/automount', ) extensions = self.getjson()['body'] - self.assertIn('unit', extensions, 'unit in extensions list 2') - self.assertIn('json', extensions, 'json in extensions list 2') - + assert 'unit' in extensions, 'unit in extensions list 2' + assert 'json' in extensions, 'json in extensions list 2' -if __name__ == '__main__': - TestPHPIsolation.main() -- cgit From c2eb245b32870b6360079ff9a4b063a7cd84d585 Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Wed, 9 Sep 2020 19:28:44 +0100 Subject: PHP: fixed "rootfs" isolation dependency on system mounts. --- test/test_php_isolation.py | 51 ---------------------------------------------- 1 file changed, 51 deletions(-) (limited to 'test/test_php_isolation.py') diff --git a/test/test_php_isolation.py b/test/test_php_isolation.py index f4170f1b..556bd387 100644 --- a/test/test_php_isolation.py +++ b/test/test_php_isolation.py @@ -85,54 +85,3 @@ class TestPHPIsolation(TestApplicationPHP): assert 'json' in extensions, 'json in extensions list' assert 'unit' in extensions, 'unit in extensions list' - - def test_php_isolation_rootfs_no_language_libs(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, - 'automount': {'language_deps': False}, - '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'] - - assert 'unit' in extensions, 'unit in extensions list' - assert 'json' not in extensions, 'json not in extensions list' - - assert 'success' in self.conf( - {'language_deps': True}, - 'applications/list-extensions/isolation/automount', - ) - - extensions = self.getjson()['body'] - - assert 'unit' in extensions, 'unit in extensions list 2' - assert 'json' in extensions, 'json in extensions list 2' - -- cgit From 6ec0ff35964c7805712d978625949f72ff5a63bc Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 7 Oct 2020 23:18:43 +0100 Subject: Tests: minor fixes. --- test/test_php_isolation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_php_isolation.py') diff --git a/test/test_php_isolation.py b/test/test_php_isolation.py index 556bd387..8ab3419a 100644 --- a/test/test_php_isolation.py +++ b/test/test_php_isolation.py @@ -1,8 +1,8 @@ import pytest +from conftest import option from unit.applications.lang.php import TestApplicationPHP from unit.feature.isolation import TestFeatureIsolation -from conftest import option class TestPHPIsolation(TestApplicationPHP): -- cgit