repo2docker/tests/unit/test_users.py

38 wiersze
1.2 KiB
Python
Czysty Zwykły widok Historia

2017-12-19 21:00:55 +00:00
"""
Test that User name and ID mapping works
"""
import os
import subprocess
import tempfile
import time
def test_user():
"""
Validate user id and name setting
"""
ts = str(time.time())
# FIXME: Use arbitrary login here, We need it now since we wanna put things to volume.
username = os.getlogin()
userid = str(os.geteuid())
2017-12-19 21:00:55 +00:00
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = os.path.realpath(tmpdir)
2017-12-19 21:00:55 +00:00
subprocess.check_call([
'repo2docker',
'-v', '{}:/home/{}'.format(tmpdir, username),
'--user-id', userid,
2017-12-19 21:27:22 +00:00
'--user-name', username,
2017-12-19 21:00:55 +00:00
tmpdir,
'--',
'/bin/bash',
'-c', 'id -u > id && pwd > pwd && whoami > name && echo -n $USER > env_user'.format(ts)
2017-12-19 21:00:55 +00:00
])
with open(os.path.join(tmpdir, 'id')) as f:
assert f.read().strip() == userid
2017-12-19 21:00:55 +00:00
with open(os.path.join(tmpdir, 'pwd')) as f:
2017-12-19 21:27:22 +00:00
assert f.read().strip() == '/home/{}'.format(username)
2017-12-19 21:00:55 +00:00
with open(os.path.join(tmpdir, 'name')) as f:
2017-12-19 21:27:22 +00:00
assert f.read().strip() == username
with open(os.path.join(tmpdir, 'name')) as f:
assert f.read().strip() == username