Merge pull request #50796 from dwoz/issue48801

Fix #48801 min, max, inact, and warn changes
This commit is contained in:
Mike Place 2018-12-10 09:30:13 -07:00 committed by GitHub
commit 12a8447741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 4 deletions

View file

@ -141,13 +141,13 @@ def _changes(name,
change['empty_password'] = True
if date is not None and lshad['lstchg'] != date:
change['date'] = date
if mindays and mindays is not 0 and lshad['min'] != mindays:
if mindays is not None and lshad['min'] != mindays:
change['mindays'] = mindays
if maxdays and maxdays is not 999999 and lshad['max'] != maxdays:
if maxdays is not None and lshad['max'] != maxdays:
change['maxdays'] = maxdays
if inactdays and inactdays is not 0 and lshad['inact'] != inactdays:
if inactdays is not None and lshad['inact'] != inactdays:
change['inactdays'] = inactdays
if warndays and warndays is not 7 and lshad['warn'] != warndays:
if warndays is not None and lshad['warn'] != warndays:
change['warndays'] = warndays
if expire and lshad['expire'] != expire:
change['expire'] = expire

View file

@ -5,6 +5,7 @@
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import logging
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
@ -20,6 +21,8 @@ from tests.support.mock import (
# Import Salt Libs
import salt.states.user as user
log = logging.getLogger(__name__)
@skipIf(NO_MOCK, NO_MOCK_REASON)
class UserTestCase(TestCase, LoaderModuleMockMixin):
@ -209,3 +212,47 @@ class UserTestCase(TestCase, LoaderModuleMockMixin):
ret.update({'comment': 'User salt is not present',
'result': True})
self.assertDictEqual(user.absent('salt'), ret)
def test_changes(self):
'''
Test salt.states.user._changes
'''
mock_info = MagicMock(
return_value={
'uid': 5000,
'gid': 5000,
'groups': ['foo'],
'home': '/home/foo',
'fullname': 'Foo Bar',
}
)
shadow_info = MagicMock(
return_value={
'min': 2,
'max': 88888,
'inact': 77,
'warn': 14,
}
)
shadow_hash = MagicMock(return_value='abcd')
dunder_salt = {'user.info': mock_info,
'shadow.info': shadow_info,
'shadow.default_hash': shadow_hash,
'file.group_to_gid': MagicMock(side_effect=['foo']),
'file.gid_to_group': MagicMock(side_effect=[5000])}
def mock_exists(*args):
return True
# side_effect used because these mocks should only be called once
with patch.dict(user.__grains__, {'kernel': 'Linux'}), \
patch.dict(user.__salt__, dunder_salt), \
patch.dict(user.__opts__, {"test": False}), \
patch('os.path.isdir', mock_exists):
ret = user._changes('foo', maxdays=999999, inactdays=0, warndays=7)
assert ret == {
'maxdays': 999999,
'mindays': 0,
'fullname': '',
'warndays': 7,
'inactdays': 0
}