21
21
from tests_utils import *
22
22
import tempfile
23
23
import re
24
+ from typing import List , Optional
24
25
25
26
try :
26
27
import libmount
27
28
except Exception :
28
29
print ("1..0" )
29
30
sys .exit (0 )
30
31
31
- def helper_mount (options , tmpfs = True , userns = False , is_file = False ):
32
+ def helper_mount (options : str , tmpfs : bool = True , userns : bool = False , is_file : bool = False ) -> List [ Optional [ str ]] :
32
33
conf = base_config ()
33
34
conf ['process' ]['args' ] = ['/init' , 'cat' , '/proc/self/mountinfo' ]
34
35
add_all_namespaces (conf , userns = userns )
@@ -54,12 +55,12 @@ def helper_mount(options, tmpfs=True, userns=False, is_file=False):
54
55
sys .stderr .write ("# helper_mount failed: mount target '%s' not found in mountinfo\n " % target )
55
56
sys .stderr .write ("# mount options: %s, tmpfs=%s, userns=%s, is_file=%s\n " % (options , tmpfs , userns , is_file ))
56
57
sys .stderr .write ("# mountinfo output: %s\n " % out [:300 ])
57
- return - 1
58
+ return [ None , None ]
58
59
return [m .vfs_options , m .fs_options ]
59
60
except Exception as e :
60
61
sys .stderr .write ("# helper_mount failed with exception: %s\n " % str (e ))
61
62
sys .stderr .write ("# mount options: %s, tmpfs=%s, userns=%s, is_file=%s\n " % (options , tmpfs , userns , is_file ))
62
- return - 1
63
+ return [ None , None ]
63
64
64
65
def test_mount_symlink ():
65
66
conf = base_config ()
@@ -285,157 +286,157 @@ def test_mount_path_with_multiple_slashes():
285
286
def test_mount_ro ():
286
287
for userns in [True , False ]:
287
288
a = helper_mount ("ro" , userns = userns , is_file = True )[0 ]
288
- if "ro" not in a :
289
+ if a is None or "ro" not in a :
289
290
return - 1
290
291
a = helper_mount ("ro" , userns = userns )[0 ]
291
- if "ro" not in a :
292
+ if a is None or "ro" not in a :
292
293
return - 1
293
294
a = helper_mount ("ro" , userns = userns , tmpfs = False )[0 ]
294
- if "ro" not in a :
295
+ if a is None or "ro" not in a :
295
296
return - 1
296
297
return 0
297
298
298
299
def test_mount_rro ():
299
300
for userns in [True , False ]:
300
301
a = helper_mount ("rro" , userns = userns , is_file = True )[0 ]
301
- if "ro" not in a :
302
+ if a is None or "ro" not in a :
302
303
return - 1
303
304
a = helper_mount ("rro" , userns = userns )[0 ]
304
- if "ro" not in a :
305
+ if a is None or "ro" not in a :
305
306
return - 1
306
307
a = helper_mount ("rro" , userns = userns , tmpfs = False )[0 ]
307
- if "ro" not in a :
308
+ if a is None or "ro" not in a :
308
309
return - 1
309
310
return 0
310
311
311
312
def test_mount_rw ():
312
313
for userns in [True , False ]:
313
314
a = helper_mount ("rw" , tmpfs = False , userns = userns )[0 ]
314
- if "rw" not in a :
315
+ if a is None or "rw" not in a :
315
316
return - 1
316
317
a = helper_mount ("rw" , userns = userns , is_file = True )[0 ]
317
- if "rw" not in a :
318
+ if a is None or "rw" not in a :
318
319
return - 1
319
320
a = helper_mount ("rw" , userns = userns )[0 ]
320
- if "rw" not in a :
321
+ if a is None or "rw" not in a :
321
322
return - 1
322
323
return 0
323
324
324
325
def test_mount_relatime ():
325
326
for userns in [True , False ]:
326
327
a = helper_mount ("relatime" , tmpfs = False , userns = userns )[0 ]
327
- if "relatime" not in a :
328
+ if a is None or "relatime" not in a :
328
329
return - 1
329
330
a = helper_mount ("relatime" , is_file = True , userns = userns )[0 ]
330
- if "relatime" not in a :
331
+ if a is None or "relatime" not in a :
331
332
return - 1
332
333
a = helper_mount ("relatime" , userns = userns )[0 ]
333
- if "relatime" not in a :
334
+ if a is None or "relatime" not in a :
334
335
return - 1
335
336
return 0
336
337
337
338
def test_mount_strictatime ():
338
339
for userns in [True , False ]:
339
340
a = helper_mount ("strictatime" , is_file = True , userns = userns )[0 ]
340
- if "relatime" not in a :
341
+ if a is None or "relatime" not in a :
341
342
return 0
342
343
a = helper_mount ("strictatime" , tmpfs = False , userns = userns )[0 ]
343
- if "relatime" not in a :
344
+ if a is None or "relatime" not in a :
344
345
return 0
345
346
a = helper_mount ("strictatime" , userns = userns )[0 ]
346
- if "relatime" not in a :
347
+ if a is None or "relatime" not in a :
347
348
return 0
348
349
return - 1
349
350
350
351
def test_mount_exec ():
351
352
for userns in [True , False ]:
352
353
a = helper_mount ("exec" , is_file = True , userns = userns )[0 ]
353
- if "noexec" in a :
354
+ if a is not None and "noexec" in a :
354
355
return - 1
355
356
a = helper_mount ("exec" , tmpfs = False , userns = userns )[0 ]
356
- if "noexec" in a :
357
+ if a is not None and "noexec" in a :
357
358
return - 1
358
359
a = helper_mount ("exec" , userns = userns )[0 ]
359
- if "noexec" in a :
360
+ if a is not None and "noexec" in a :
360
361
return - 1
361
362
return 0
362
363
363
364
def test_mount_noexec ():
364
365
for userns in [True , False ]:
365
366
a = helper_mount ("noexec" , is_file = True , userns = userns )[0 ]
366
- if "noexec" not in a :
367
+ if a is None or "noexec" not in a :
367
368
return - 1
368
369
a = helper_mount ("noexec" , tmpfs = False , userns = userns )[0 ]
369
- if "noexec" not in a :
370
+ if a is None or "noexec" not in a :
370
371
return - 1
371
372
a = helper_mount ("noexec" , userns = userns )[0 ]
372
- if "noexec" not in a :
373
+ if a is None or "noexec" not in a :
373
374
return - 1
374
375
return 0
375
376
376
377
def test_mount_suid ():
377
378
for userns in [True , False ]:
378
379
a = helper_mount ("suid" , is_file = True , userns = userns )[0 ]
379
- if "nosuid" in a :
380
+ if a is not None and "nosuid" in a :
380
381
return - 1
381
382
a = helper_mount ("suid" , tmpfs = False , userns = userns )[0 ]
382
- if "nosuid" in a :
383
+ if a is not None and "nosuid" in a :
383
384
return - 1
384
385
a = helper_mount ("suid" , userns = userns )[0 ]
385
- if "nosuid" in a :
386
+ if a is not None and "nosuid" in a :
386
387
return - 1
387
388
return 0
388
389
389
390
def test_mount_nosuid ():
390
391
for userns in [True , False ]:
391
392
a = helper_mount ("nosuid" , is_file = True , userns = userns )[0 ]
392
- if "nosuid" not in a :
393
+ if a is None or "nosuid" not in a :
393
394
return - 1
394
395
a = helper_mount ("nosuid" , tmpfs = False , userns = userns )[0 ]
395
- if "nosuid" not in a :
396
+ if a is None or "nosuid" not in a :
396
397
return - 1
397
398
a = helper_mount ("nosuid" , userns = userns )[0 ]
398
- if "nosuid" not in a :
399
+ if a is None or "nosuid" not in a :
399
400
return - 1
400
401
return 0
401
402
402
403
def test_mount_sync ():
403
404
for userns in [True , False ]:
404
405
a = helper_mount ("sync" , userns = userns )[1 ]
405
- if "sync" not in a :
406
+ if a is None or "sync" not in a :
406
407
return - 1
407
408
return 0
408
409
409
410
def test_mount_dirsync ():
410
411
for userns in [True , False ]:
411
412
a = helper_mount ("dirsync" , userns = userns )[1 ]
412
- if "dirsync" not in a :
413
+ if a is None or "dirsync" not in a :
413
414
return - 1
414
415
return 0
415
416
416
417
def test_mount_nodev ():
417
418
for userns in [True , False ]:
418
419
a = helper_mount ("nodev" , is_file = True )[0 ]
419
- if "nodev" not in a :
420
+ if a is None or "nodev" not in a :
420
421
return - 1
421
422
a = helper_mount ("nodev" , tmpfs = False )[0 ]
422
- if "nodev" not in a :
423
+ if a is None or "nodev" not in a :
423
424
return - 1
424
425
a = helper_mount ("nodev" , userns = userns )[0 ]
425
- if "nodev" not in a :
426
+ if a is None or "nodev" not in a :
426
427
return - 1
427
428
return 0
428
429
429
430
def test_mount_dev ():
430
431
for userns in [True , False ]:
431
432
a = helper_mount ("dev" , userns = userns , tmpfs = False )[0 ]
432
- if "nodev" in a :
433
+ if a is not None and "nodev" in a :
433
434
return - 1
434
435
a = helper_mount ("dev" , userns = userns , is_file = True )[0 ]
435
- if "nodev" in a :
436
+ if a is not None and "nodev" in a :
436
437
return - 1
437
438
a = helper_mount ("dev" , userns = userns )[0 ]
438
- if "nodev" in a :
439
+ if a is not None and "nodev" in a :
439
440
return - 1
440
441
return 0
441
442
0 commit comments