diff --git a/snare/tests/test_snare_helpers_check_privileges.py b/snare/tests/test_snare_helpers_check_privileges.py index c7229f0e..10a6205a 100644 --- a/snare/tests/test_snare_helpers_check_privileges.py +++ b/snare/tests/test_snare_helpers_check_privileges.py @@ -1,6 +1,8 @@ import unittest from argparse import ArgumentTypeError from os.path import expanduser, join +from os import geteuid +import shutil from snare.utils.page_path_generator import generate_unique_path from snare.utils.snare_helpers import check_privileges @@ -8,6 +10,9 @@ class TestStrToBool(unittest.TestCase): + def setUp(self): + self.euid = geteuid() + def test_privileges_in_root(self): self.path = '/' try: @@ -15,7 +20,10 @@ def test_privileges_in_root(self): self.privileges = True except PermissionError: self.privileges = False - assert self.privileges is False + if self.euid == 0: + assert self.privileges is True + else: + assert self.privileges is False def test_privileges_in_home(self): self.path = expanduser('~') @@ -33,7 +41,10 @@ def test_non_existent_root_path(self): self.privileges = True except PermissionError: self.privileges = False - assert self.privileges is False + if self.euid == 0: + assert self.privileges is True + else: + assert self.privileges is False def test_non_existent_home_path(self): self.path = join(expanduser('~'), 'snare') @@ -43,3 +54,13 @@ def test_non_existent_home_path(self): except PermissionError: self.privileges = False assert self.privileges is True + + def tearDown(self): + try: + shutil.rmtree(join(expanduser('~'), 'snare')) + except FileNotFoundError: + pass + try: + shutil.rmtree('/snare') + except (FileNotFoundError, PermissionError): + pass diff --git a/snare/utils/snare_helpers.py b/snare/utils/snare_helpers.py old mode 100755 new mode 100644