xref: /unit/test/test_go_isolation_rootfs.py (revision 1999:00d43b03d82f)
11490St.nateldemoura@f5.comimport os
21635Szelenkov@nginx.com
31596Szelenkov@nginx.comimport pytest
41490St.nateldemoura@f5.comfrom unit.applications.lang.go import TestApplicationGo
51490St.nateldemoura@f5.com
61490St.nateldemoura@f5.com
71490St.nateldemoura@f5.comclass TestGoIsolationRootfs(TestApplicationGo):
81490St.nateldemoura@f5.com    prerequisites = {'modules': {'go': 'all'}}
91490St.nateldemoura@f5.com
10*1999Smax.romanov@nginx.com    @pytest.fixture(autouse=True)
11*1999Smax.romanov@nginx.com    def setup_method_fixture(self, request, skip_alert):
12*1999Smax.romanov@nginx.com        skip_alert(r'\[unit\] close\(\d+\) failed: Bad file descriptor')
13*1999Smax.romanov@nginx.com
141654Szelenkov@nginx.com    def test_go_isolation_rootfs_chroot(self, is_su, temp_dir):
151596Szelenkov@nginx.com        if not is_su:
161596Szelenkov@nginx.com            pytest.skip('requires root')
171490St.nateldemoura@f5.com
181490St.nateldemoura@f5.com        if os.uname().sysname == 'Darwin':
191596Szelenkov@nginx.com            pytest.skip('chroot tests not supported on OSX')
201490St.nateldemoura@f5.com
211490St.nateldemoura@f5.com        isolation = {
221654Szelenkov@nginx.com            'rootfs': temp_dir,
231490St.nateldemoura@f5.com        }
241490St.nateldemoura@f5.com
251490St.nateldemoura@f5.com        self.load('ns_inspect', isolation=isolation)
261490St.nateldemoura@f5.com
271490St.nateldemoura@f5.com        obj = self.getjson(url='/?file=/go/app')['body']
281490St.nateldemoura@f5.com
291596Szelenkov@nginx.com        assert obj['FileExists'] == True, 'app relative to rootfs'
301490St.nateldemoura@f5.com
311490St.nateldemoura@f5.com        obj = self.getjson(url='/?file=/bin/sh')['body']
321596Szelenkov@nginx.com        assert obj['FileExists'] == False, 'file should not exists'
33