From 9bec5189160c542e094af468fd764d6f4212520d Mon Sep 17 00:00:00 2001 From: Guillaume Chanel <Guillaume.Chanel@unige.ch> Date: Wed, 23 Nov 2022 17:50:35 +0100 Subject: [PATCH] Change euid if root --- tests/test.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test.py b/tests/test.py index 2d4b450..d7ae9e1 100755 --- a/tests/test.py +++ b/tests/test.py @@ -11,6 +11,8 @@ import shutil from colorama import Fore import argparse import sys +import pwd + # TODO: How to include the folder creation in the test function instead of repeating it for all test functions # TODO: pass over EVERY ASSERTION ERROR (i.e. continu test). But seems unlikely to be done easily @@ -258,6 +260,17 @@ if __name__=="__main__": parser.add_argument('-p', '--no-zero-mode', dest='no_perms', action='store_false', help='tests will NOT include files without any permission (only applies to concerned tests)') parser.add_argument('-d', '--delete-tests', dest='delete_tests', action='store_true', help='delete the test folders when tests are over') args = parser.parse_args() + + + # If effective user id is root change to nobody user (should be available on most machines...) + print(os.geteuid()) + if os.geteuid() == 0: + try: + nobody = pwd.getpwnam('nobody') + except: + print("!!! Effective user id is root and user nobody could be be found: some test might be corrupted (e.g. umask)") + os.seteuid(nobody.pw_uid) + t = Test(args.prog_path, delete_root=args.delete_tests) t.test_listing(args.no_perms) t.test_file_copy() -- GitLab