xref: /unit/test/test_python_isolation_chroot.py (revision 1848:4bd548074e2c)
1import pytest
2
3from unit.applications.lang.python import TestApplicationPython
4
5
6class TestPythonIsolation(TestApplicationPython):
7    prerequisites = {'modules': {'python': 'any'}}
8
9    def test_python_isolation_chroot(self, is_su, temp_dir):
10        if not is_su:
11            pytest.skip('requires root')
12
13        isolation = {
14            'rootfs': temp_dir,
15        }
16
17        self.load('ns_inspect', isolation=isolation)
18
19        assert (
20            self.getjson(url='/?path=' + temp_dir)['body']['FileExists']
21            == False
22        ), 'temp_dir does not exists in rootfs'
23
24        assert (
25            self.getjson(url='/?path=/proc/self')['body']['FileExists'] == 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