xref: /unit/test/test_python_isolation_chroot.py (revision 1771:94cf6c5fafbd)
1import pytest
2from unit.applications.lang.python import TestApplicationPython
3
4
5class TestPythonIsolation(TestApplicationPython):
6    prerequisites = {'modules': {'python': 'any'}}
7
8    def test_python_isolation_chroot(self, is_su, temp_dir):
9        if not is_su:
10            pytest.skip('requires root')
11
12        isolation = {
13            'rootfs': temp_dir,
14        }
15
16        self.load('ns_inspect', isolation=isolation)
17
18        assert (
19            self.getjson(url='/?path=' + temp_dir)['body']['FileExists']
20            == False
21        ), 'temp_dir does not exists in rootfs'
22
23        assert (
24            self.getjson(url='/?path=/proc/self')['body']['FileExists']
25            == True
26        ), 'no /proc/self'
27
28        assert (
29            self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False
30        ), 'no /dev/pts'
31
32        assert (
33            self.getjson(url='/?path=/sys/kernel')['body']['FileExists']
34            == False
35        ), 'no /sys/kernel'
36
37        ret = self.getjson(url='/?path=/app/python/ns_inspect')
38
39        assert (
40            ret['body']['FileExists'] == True
41        ), 'application exists in rootfs'
42