Skip to content
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
2 changes: 1 addition & 1 deletion scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ class PasswHardening(object):
for normal_account in normal_accounts:
try:
chage_p_m = subprocess.Popen(('chage', chage_flag + str(curr_expiration), normal_account), stdout=subprocess.PIPE)
return_code_chage_p_m = chage_p_m.poll()
return_code_chage_p_m = chage_p_m.wait()
if return_code_chage_p_m != 0:
syslog.syslog(syslog.LOG_ERR, "failed: return code - {}".format(return_code_chage_p_m))

Expand Down
39 changes: 39 additions & 0 deletions tests/hostcfgd/hostcfgd_passwh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import subprocess
import syslog
import re

from parameterized import parameterized
Expand Down Expand Up @@ -180,3 +181,41 @@ def test_hostcfgd_passwh_classes(self, test_name, test_data):
"""

self.check_config(test_name, test_data, "enable_digits_class")

def test_passwd_aging_expire_modify_success(self):
"""
Test passwd_aging_expire_modify() does not log an error when chage succeeds
"""
passwh = hostcfgd.PasswHardening()
passwh.get_normal_accounts = mock.Mock(return_value=["testuser"])

with mock.patch('hostcfgd.subprocess.Popen') as mock_popen, \
mock.patch('hostcfgd.syslog.syslog') as mock_syslog:
mock_popen.return_value.wait.return_value = 0

passwh.passwd_aging_expire_modify(100, 'MAX_DAYS')

mock_popen.assert_called_once_with(('chage', '-M 100', 'testuser'), stdout=subprocess.PIPE)
mock_popen.return_value.wait.assert_called_once_with()

mock_syslog.assert_not_called()

def test_passwd_aging_expire_modify_failure(self):
"""
Test passwd_aging_expire_modify() logs an error when chage exits with a nonzero status
"""
passwh = hostcfgd.PasswHardening()
passwh.get_normal_accounts = mock.Mock(return_value=["testuser"])

with mock.patch('hostcfgd.subprocess.Popen') as mock_popen, \
mock.patch('hostcfgd.syslog.syslog') as mock_syslog:
mock_popen.return_value.wait.return_value = 1

passwh.passwd_aging_expire_modify(100, 'MAX_DAYS')

mock_popen.assert_called_once_with(('chage', '-M 100', 'testuser'), stdout=subprocess.PIPE)
mock_popen.return_value.wait.assert_called_once_with()
mock_syslog.assert_called_once_with(
syslog.LOG_ERR,
"failed: return code - 1"
)
Loading