2020-09-16 20:31:15 +00:00
|
|
|
import pytest
|
2020-05-28 13:59:52 +00:00
|
|
|
from unit.applications.lang.python import TestApplicationPython
|
|
|
|
|
|
|
|
|
|
|
|
class TestPythonIsolation(TestApplicationPython):
|
|
|
|
prerequisites = {'modules': {'python': 'any'}}
|
|
|
|
|
2020-10-19 21:25:29 +00:00
|
|
|
def test_python_isolation_chroot(self, is_su, temp_dir):
|
2020-09-16 20:31:15 +00:00
|
|
|
if not is_su:
|
|
|
|
pytest.skip('requires root')
|
2020-05-28 13:59:52 +00:00
|
|
|
|
|
|
|
isolation = {
|
2020-10-19 21:25:29 +00:00
|
|
|
'rootfs': temp_dir,
|
2020-05-28 13:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.load('ns_inspect', isolation=isolation)
|
|
|
|
|
2020-09-16 20:31:15 +00:00
|
|
|
assert (
|
2023-02-21 17:21:29 +00:00
|
|
|
self.getjson(url=f'/?path={temp_dir}')['body']['FileExists']
|
2020-09-16 20:31:15 +00:00
|
|
|
== False
|
|
|
|
), 'temp_dir does not exists in rootfs'
|
2020-05-28 13:59:52 +00:00
|
|
|
|
2020-09-16 20:31:15 +00:00
|
|
|
assert (
|
2021-04-05 13:03:05 +00:00
|
|
|
self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True
|
2020-09-16 20:31:15 +00:00
|
|
|
), 'no /proc/self'
|
|
|
|
|
|
|
|
assert (
|
|
|
|
self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False
|
|
|
|
), 'no /dev/pts'
|
2020-05-28 13:59:52 +00:00
|
|
|
|
2020-09-16 20:31:15 +00:00
|
|
|
assert (
|
|
|
|
self.getjson(url='/?path=/sys/kernel')['body']['FileExists']
|
|
|
|
== False
|
|
|
|
), 'no /sys/kernel'
|
2020-05-28 13:59:52 +00:00
|
|
|
|
2020-09-16 20:31:15 +00:00
|
|
|
ret = self.getjson(url='/?path=/app/python/ns_inspect')
|
2020-05-28 13:59:52 +00:00
|
|
|
|
2022-04-11 20:05:14 +00:00
|
|
|
assert ret['body']['FileExists'] == True, 'application exists in rootfs'
|