4
4
import logging
5
5
6
6
import pytest
7
+ import requests
8
+
9
+ from conftest import TrackedContainer
7
10
8
11
LOGGER = logging .getLogger (__name__ )
9
12
10
13
11
- def test_cli_args (container , http_client ) :
14
+ def test_cli_args (container : TrackedContainer , http_client : requests . Session ) -> None :
12
15
"""Container should respect notebook server command line args
13
16
(e.g., disabling token security)"""
14
17
c = container .run (command = ["start-notebook.sh" , "--NotebookApp.token=''" ])
@@ -26,7 +29,9 @@ def test_cli_args(container, http_client):
26
29
27
30
28
31
@pytest .mark .filterwarnings ("ignore:Unverified HTTPS request" )
29
- def test_unsigned_ssl (container , http_client ):
32
+ def test_unsigned_ssl (
33
+ container : TrackedContainer , http_client : requests .Session
34
+ ) -> None :
30
35
"""Container should generate a self-signed SSL certificate
31
36
and notebook server should use it to enable HTTPS.
32
37
"""
@@ -48,7 +53,7 @@ def test_unsigned_ssl(container, http_client):
48
53
assert warnings [0 ].startswith ("WARNING: Jupyter Notebook deprecation notice" )
49
54
50
55
51
- def test_uid_change (container ) :
56
+ def test_uid_change (container : TrackedContainer ) -> None :
52
57
"""Container should change the UID of the default user."""
53
58
c = container .run (
54
59
tty = True ,
@@ -65,7 +70,7 @@ def test_uid_change(container):
65
70
assert "uid=1010(jovyan)" in c .logs (stdout = True ).decode ("utf-8" )
66
71
67
72
68
- def test_gid_change (container ) :
73
+ def test_gid_change (container : TrackedContainer ) -> None :
69
74
"""Container should change the GID of the default user."""
70
75
c = container .run (
71
76
tty = True ,
@@ -82,7 +87,7 @@ def test_gid_change(container):
82
87
assert "groups=110(jovyan),100(users)" in logs
83
88
84
89
85
- def test_nb_user_change (container ) :
90
+ def test_nb_user_change (container : TrackedContainer ) -> None :
86
91
"""Container should change the user name (`NB_USER`) of the default user."""
87
92
nb_user = "nayvoj"
88
93
running_container = container .run (
@@ -131,7 +136,7 @@ def test_nb_user_change(container):
131
136
), f"Hidden folder .jupyter was not copied properly to { nb_user } home folder. stat: { output } , expected { expected_output } "
132
137
133
138
134
- def test_chown_extra (container ) :
139
+ def test_chown_extra (container : TrackedContainer ) -> None :
135
140
"""Container should change the UID/GID of a comma separated
136
141
CHOWN_EXTRA list of folders."""
137
142
c = container .run (
@@ -160,7 +165,7 @@ def test_chown_extra(container):
160
165
assert "/opt/conda/bin/jupyter:1010:101" in logs
161
166
162
167
163
- def test_chown_home (container ) :
168
+ def test_chown_home (container : TrackedContainer ) -> None :
164
169
"""Container should change the NB_USER home directory owner and
165
170
group to the current value of NB_UID and NB_GID."""
166
171
c = container .run (
@@ -183,7 +188,7 @@ def test_chown_home(container):
183
188
assert "/home/kitten/.bashrc:1010:101" in logs
184
189
185
190
186
- def test_sudo (container ) :
191
+ def test_sudo (container : TrackedContainer ) -> None :
187
192
"""Container should grant passwordless sudo to the default user."""
188
193
c = container .run (
189
194
tty = True ,
@@ -199,7 +204,7 @@ def test_sudo(container):
199
204
assert "uid=0(root)" in logs
200
205
201
206
202
- def test_sudo_path (container ) :
207
+ def test_sudo_path (container : TrackedContainer ) -> None :
203
208
"""Container should include /opt/conda/bin in the sudo secure_path."""
204
209
c = container .run (
205
210
tty = True ,
@@ -215,7 +220,7 @@ def test_sudo_path(container):
215
220
assert logs .rstrip ().endswith ("/opt/conda/bin/jupyter" )
216
221
217
222
218
- def test_sudo_path_without_grant (container ) :
223
+ def test_sudo_path_without_grant (container : TrackedContainer ) -> None :
219
224
"""Container should include /opt/conda/bin in the sudo secure_path."""
220
225
c = container .run (
221
226
tty = True ,
@@ -230,7 +235,7 @@ def test_sudo_path_without_grant(container):
230
235
assert logs .rstrip ().endswith ("/opt/conda/bin/jupyter" )
231
236
232
237
233
- def test_group_add (container ) :
238
+ def test_group_add (container : TrackedContainer ) -> None :
234
239
"""Container should run with the specified uid, gid, and secondary
235
240
group. It won't be possible to modify /etc/passwd since gid is nonzero, so
236
241
additionally verify that setting gid=0 is suggested in a warning.
@@ -252,7 +257,7 @@ def test_group_add(container):
252
257
assert "uid=1010 gid=1010 groups=1010,100(users)" in logs
253
258
254
259
255
- def test_set_uid (container ) :
260
+ def test_set_uid (container : TrackedContainer ) -> None :
256
261
"""Container should run with the specified uid and NB_USER.
257
262
The /home/jovyan directory will not be writable since it's owned by 1000:users.
258
263
Additionally verify that "--group-add=users" is suggested in a warning to restore
@@ -274,7 +279,7 @@ def test_set_uid(container):
274
279
assert "--group-add=users" in warnings [0 ]
275
280
276
281
277
- def test_set_uid_and_nb_user (container ) :
282
+ def test_set_uid_and_nb_user (container : TrackedContainer ) -> None :
278
283
"""Container should run with the specified uid and NB_USER."""
279
284
c = container .run (
280
285
user = "1010" ,
@@ -294,7 +299,7 @@ def test_set_uid_and_nb_user(container):
294
299
assert "user is kitten but home is /home/jovyan" in warnings [0 ]
295
300
296
301
297
- def test_container_not_delete_bind_mount (container , tmp_path ):
302
+ def test_container_not_delete_bind_mount (container : TrackedContainer , tmp_path ) -> None :
298
303
"""Container should not delete host system files when using the (docker)
299
304
-v bind mount flag and mapping to /home/jovyan.
300
305
"""
@@ -324,7 +329,9 @@ def test_container_not_delete_bind_mount(container, tmp_path):
324
329
325
330
326
331
@pytest .mark .parametrize ("enable_root" , [False , True ])
327
- def test_jupyter_env_vars_to_unset_as_root (container , enable_root ):
332
+ def test_jupyter_env_vars_to_unset_as_root (
333
+ container : TrackedContainer , enable_root : bool
334
+ ) -> None :
328
335
"""Environment variables names listed in JUPYTER_ENV_VARS_TO_UNSET
329
336
should be unset in the final environment."""
330
337
root_args = {"user" : "root" } if enable_root else {}
0 commit comments