def _test_auditing(setting): """ Helper function to set an audit setting and assert that it was successful """ win_lgpo.set_computer_policy(name="Audit account management", setting=setting) # Clear the context so we're getting the actual settings from the machine win_lgpo._get_secedit_data(refresh=True) result = win_lgpo.get_policy( policy_name="Audit account management", policy_class="machine" ) assert result == setting
def _test_auditing(setting): """ Helper function to set an audit setting and assert that it was successful """ computer_policy = {"Audit Account Management": setting} win_lgpo_state.set_(name="junk", computer_policy=computer_policy) # Clear the context so we're getting the actual settings from the machine win_lgpo_module._get_secedit_data(refresh=True) result = win_lgpo_module.get_policy(policy_name="Audit Account Management", policy_class="machine") assert result == setting
def test__get_secedit_data(self): ''' Test getting secedit data and loading it into __context__ ''' expected = { 'AuditLogonEvents': '0', 'AuditSystemEvents': '0', r'MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Setup\RecoveryConsole\SecurityLevel': '4,0', r'MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Setup\RecoveryConsole\SetCommand': '4,0', 'MaximumPasswordAge': '42', 'MinimumPasswordAge': '0', 'Revision': '1', 'SeBackupPrivilege': '*S-1-5-32-544,*S-1-5-32-551', 'SeNetworkLogonRight': '*S-1-1-0,*S-1-5-32-544,*S-1-5-32-545,*S-1-5-32-551', 'Unicode': 'yes', 'signature': '"$CHICAGO$"' } with patch.object(win_lgpo, '_load_secedit_data', MagicMock(return_value=self.secedit_data)): result = win_lgpo._get_secedit_data() self.assertDictEqual(result, expected) self.assertDictEqual(win_lgpo.__context__['lgpo.secedit_data'], expected)
def test__write_secedit_data(self): ''' Test writing secedit data and updating the __context__ ''' mock_true = MagicMock(return_value=True) mock_false = MagicMock(return_value=False) mock_retcode = MagicMock(return_value=0) new_secedit_data = {'System Access': ['MaximumPasswordAge=100']} with patch.object(win_lgpo, '_load_secedit_data', MagicMock(return_value=self.secedit_data)),\ patch.dict(win_lgpo.__salt__, {'file.write': mock_true, 'file.file_exists': mock_false, 'cmd.retcode': mock_retcode}): # Populate __context__['lgpo.secedit_data'] # It will have been run before this function is called win_lgpo._get_secedit_data() self.assertEqual( win_lgpo.__context__['lgpo.secedit_data'] ['MaximumPasswordAge'], '42') result = win_lgpo._write_secedit_data(new_secedit_data) self.assertTrue(result) self.assertEqual( win_lgpo.__context__['lgpo.secedit_data'] ['MaximumPasswordAge'], '100')