Commit b42ccfa5 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kirill Smelkov

trun: Add test for how /etc/{passwd,group} is setup for spawned job

Even if we don't want to spawn full sshd to verify that ptys work, we can
still minimally test that inside user/group database is setup as expected.

/reviewed-by @kirr
/reviewed-on nexedi/nxdtest!13
parent e6b7993c
......@@ -19,7 +19,9 @@
# verify general functionality
import grp
import os
import pwd
import sys
import re
import time
......@@ -261,6 +263,36 @@ TestCase('TESTCASE', ['mount', '-t', 'tmpfs', 'none', '/etc'])
assert "# leaked mount: none /etc tmpfs" in captured.out
# verify that inside environment, that nxdtest creates, user/group database is
# minimal.
@userns_only
def test_run_usermap(run_nxdtest, capsys):
tdumpusergroups = "%s/testprog/tdumpusergroups" % (dirname(__file__),)
run_nxdtest(
"""
TestCase('TESTCASE', %r)
""" % [tdumpusergroups])
captured = capsys.readouterr()
assert captured.err == ''
# we expect only current user, root and nobody/nogroup to be present
uok = [repr(u) for u in [
pwd.getpwuid(os.getuid()),
pwd.getpwnam('root'),
pwd.getpwnam('nobody')]]
gok = [repr(g) for g in [
grp.getgrgid(os.getgid()),
grp.getgrnam('root'),
grp.getgrnam('nogroup')]]
want = '---- 8< ----\n' # XXX won't need this scissors, if we would test trun directly
for _ in sorted(uok) + sorted(gok):
want += _+'\n'
want += '---- 8< ----'
assert want in captured.out
# verify that inside environment, that nxdtest creates, file permissions are
# still respected.
def test_run_writero(run_nxdtest, capsys):
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2021 Nexedi SA and Contributors.
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""Program tdumpusergroups helps to verify that nxdtest maps users and groups
in namespace.
It dumps content of user and group databases in raw form.
Database entries are printed in sorted order.
"""
from __future__ import absolute_import, print_function
import grp
import pwd
import sys
def main():
print('---- 8< ----')
uall = [repr(u) for u in pwd.getpwall()]
gall = [repr(g) for g in grp.getgrall()]
for u in sorted(uall):
print(u)
for g in sorted(gall):
print(g)
print('---- 8< ----')
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment