|
1 | 1 | # Copyright (c) Jupyter Development Team.
|
2 | 2 | # Distributed under the terms of the Modified BSD License.
|
3 | 3 | import time
|
| 4 | +import logging |
4 | 5 |
|
5 | 6 | import pytest
|
6 | 7 |
|
| 8 | +LOGGER = logging.getLogger(__name__) |
| 9 | + |
7 | 10 |
|
8 | 11 | def test_cli_args(container, http_client):
|
9 | 12 | """Container should respect notebook server command line args
|
@@ -61,6 +64,37 @@ def test_gid_change(container):
|
61 | 64 | assert 'groups=110(jovyan),100(users)' in logs
|
62 | 65 |
|
63 | 66 |
|
| 67 | +def test_nb_user_change(container): |
| 68 | + """Container should change the user name (`NB_USER`) of the default user.""" |
| 69 | + nb_user = "nayvoj" |
| 70 | + running_container = container.run( |
| 71 | + tty=True, |
| 72 | + user="root", |
| 73 | + environment=[f"NB_USER={nb_user}", |
| 74 | + "CHOWN_HOME=yes"], |
| 75 | + working_dir=f"/home/{nb_user}", |
| 76 | + command=['start.sh', 'bash', '-c', 'sleep infinity'] |
| 77 | + ) |
| 78 | + |
| 79 | + LOGGER.info(f"Checking if the user is changed to {nb_user} by the start script ...") |
| 80 | + output = running_container.logs(stdout=True).decode("utf-8") |
| 81 | + assert f"Set username to: {nb_user}" in output, f"User is not changed to {nb_user}" |
| 82 | + |
| 83 | + LOGGER.info(f"Checking {nb_user} id ...") |
| 84 | + command = "id" |
| 85 | + expected_output = f"uid=1000({nb_user}) gid=100(users) groups=100(users)" |
| 86 | + cmd = running_container.exec_run(command, user=nb_user) |
| 87 | + output = cmd.output.decode("utf-8").strip("\n") |
| 88 | + assert output == expected_output, f"Bad user {output}, expected {expected_output}" |
| 89 | + |
| 90 | + LOGGER.info(f"Checking if {nb_user} owns his home folder ...") |
| 91 | + command = f'stat -c "%U %G" /home/{nb_user}/' |
| 92 | + expected_output = f"{nb_user} users" |
| 93 | + cmd = running_container.exec_run(command) |
| 94 | + output = cmd.output.decode("utf-8").strip("\n") |
| 95 | + assert output == expected_output, f"Bad owner for the {nb_user} home folder {output}, expected {expected_output}" |
| 96 | + |
| 97 | + |
64 | 98 | def test_chown_extra(container):
|
65 | 99 | """Container should change the UID/GID of CHOWN_EXTRA."""
|
66 | 100 | c = container.run(
|
|
0 commit comments