summaryrefslogtreecommitdiff
path: root/cloudinit/config/tests/test_set_passwords.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/config/tests/test_set_passwords.py')
-rw-r--r--cloudinit/config/tests/test_set_passwords.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/cloudinit/config/tests/test_set_passwords.py b/cloudinit/config/tests/test_set_passwords.py
index a2ea5ec4..639fb9ea 100644
--- a/cloudinit/config/tests/test_set_passwords.py
+++ b/cloudinit/config/tests/test_set_passwords.py
@@ -74,7 +74,7 @@ class TestSetPasswordsHandle(CiTestCase):
with_logs = True
- def test_handle_on_empty_config(self):
+ def test_handle_on_empty_config(self, *args):
"""handle logs that no password has changed when config is empty."""
cloud = self.tmp_cloud(distro='ubuntu')
setpass.handle(
@@ -108,4 +108,44 @@ class TestSetPasswordsHandle(CiTestCase):
'\n'.join(valid_hashed_pwds) + '\n')],
m_subp.call_args_list)
+ @mock.patch(MODPATH + "util.is_FreeBSD")
+ @mock.patch(MODPATH + "util.subp")
+ def test_freebsd_calls_custom_pw_cmds_to_set_and_expire_passwords(
+ self, m_subp, m_is_freebsd):
+ """FreeBSD calls custom pw commands instead of chpasswd and passwd"""
+ m_is_freebsd.return_value = True
+ cloud = self.tmp_cloud(distro='freebsd')
+ valid_pwds = ['ubuntu:passw0rd']
+ cfg = {'chpasswd': {'list': valid_pwds}}
+ setpass.handle(
+ 'IGNORED', cfg=cfg, cloud=cloud, log=self.logger, args=[])
+ self.assertEqual([
+ mock.call(['pw', 'usermod', 'ubuntu', '-h', '0'], data='passw0rd',
+ logstring="chpasswd for ubuntu"),
+ mock.call(['pw', 'usermod', 'ubuntu', '-p', '01-Jan-1970'])],
+ m_subp.call_args_list)
+
+ @mock.patch(MODPATH + "util.is_FreeBSD")
+ @mock.patch(MODPATH + "util.subp")
+ def test_handle_on_chpasswd_list_creates_random_passwords(self, m_subp,
+ m_is_freebsd):
+ """handle parses command set random passwords."""
+ m_is_freebsd.return_value = False
+ cloud = self.tmp_cloud(distro='ubuntu')
+ valid_random_pwds = [
+ 'root:R',
+ 'ubuntu:RANDOM']
+ cfg = {'chpasswd': {'expire': 'false', 'list': valid_random_pwds}}
+ with mock.patch(MODPATH + 'util.subp') as m_subp:
+ setpass.handle(
+ 'IGNORED', cfg=cfg, cloud=cloud, log=self.logger, args=[])
+ self.assertIn(
+ 'DEBUG: Handling input for chpasswd as list.',
+ self.logs.getvalue())
+ self.assertNotEqual(
+ [mock.call(['chpasswd'],
+ '\n'.join(valid_random_pwds) + '\n')],
+ m_subp.call_args_list)
+
+
# vi: ts=4 expandtab