Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertion error for superuser #289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions snare/tests/test_snare_helpers_check_privileges.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
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


class TestStrToBool(unittest.TestCase):

def setUp(self):
self.euid = geteuid()

def test_privileges_in_root(self):
self.path = '/'
try:
check_privileges(self.path)
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('~')
Expand All @@ -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')
Expand All @@ -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
Empty file modified snare/utils/snare_helpers.py
100755 → 100644
Empty file.