Tests: migrated to the pytest.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user