Skip to content

Commit 3cf11b1

Browse files
HVSharma12richm
authored andcommitted
mock isfile in unit test for get config_lines
1 parent 038db5c commit 3cf11b1

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

library/scan_sudoers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def get_includes(path):
168168

169169
def get_config_lines(path, params):
170170
# Read sudoers file
171-
if not os.path.isfile(path):
171+
if not isfile(path):
172172
return {}
173173
fp = open(path, "r")
174174
all_lines = fp.read()

tests/unit/test_scan_sudoers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ def test_get_user_specs15(self):
334334
"scan_sudoers.get_includes",
335335
return_value={"include_files": ["/etc/sudoers.d/file1"]},
336336
)
337-
def test_get_config_lines01(self, mock_open, mock_get_includes):
337+
@patch("scan_sudoers.isfile", return_value=True)
338+
def test_get_config_lines01(self, mock_isfile, mock_open, mock_get_includes):
338339
# Arrange
339340

340341
params = {"output_raw_configs": True, "output_parsed_configs": True}
@@ -395,7 +396,8 @@ def test_get_config_lines01(self, mock_open, mock_get_includes):
395396
"scan_sudoers.get_includes",
396397
return_value={"include_files": ["/etc/sudoers.d/file1"]},
397398
)
398-
def test_get_config_lines02(self, mock_open, mock_get_includes):
399+
@patch("scan_sudoers.isfile", return_value=True)
400+
def test_get_config_lines02(self, mock_isfile, mock_open, mock_get_includes):
399401
# Arrange
400402
params = {"output_raw_configs": True, "output_parsed_configs": True}
401403
expected_output = {

0 commit comments

Comments
 (0)