def test_groups(self, _groups_for_user): _groups_for_user.return_value = ["group1", "group3"] bundle = MagicMock() user = users.User( bundle, "blockwart", { 'full_name': "Blöck Wart", 'gid': 2345, 'groups': ["group1", "group2"], 'home': "/home/blockwart", 'password_hash': "secret", 'shell': "/bin/bash", 'uid': 1123, }, ) passwd_grep_result = RunResult() passwd_grep_result.return_code = 0 passwd_grep_result.stdout = "blockwart:x:1123:2345:Blöck Wart:/home/blockwart:/bin/bash\n" shadow_grep_result = RunResult() shadow_grep_result.return_code = 0 shadow_grep_result.stdout = "blockwart:secret:::::::" results = [shadow_grep_result, passwd_grep_result] def pop_result(*args, **kwargs): return results.pop() bundle.node.run.side_effect = pop_result status = user.get_status() self.assertFalse(status.correct)
def test_not_installed(self): runresult = RunResult() runresult.return_code = 1 runresult.stdout = "error: package 'foo' was not found" node = MagicMock() node.run.return_value = runresult self.assertFalse(pkg_pacman.pkg_installed(node, "foo"))
def test_installed(self): runresult = RunResult() runresult.return_code = 0 runresult.stdout = "foo 1.0.0-1\n" node = MagicMock() node.run.return_value = runresult self.assertTrue(pkg_pacman.pkg_installed(node, "foo"))
def test_not_running(self): runresult = RunResult() runresult.return_code = 3 runresult.stdout = "whatever, does not matter" node = MagicMock() node.run.return_value = runresult self.assertFalse(svc_systemd.svc_running(node, "foo"))
def test_running(self): runresult = RunResult() runresult.return_code = 0 runresult.stdout = "foo start/running, process 1234\n" node = MagicMock() node.run.return_value = runresult self.assertTrue(svc_upstart.svc_running(node, "foo"))
def test_installed(self): runresult = RunResult() runresult.return_code = 0 runresult.stdout = "Status: install ok installed\n" node = MagicMock() node.run.return_value = runresult self.assertTrue(pkg_apt.pkg_installed(node, "foo"))
def test_groups(self): node = MagicMock() result = RunResult() result.stdout = "group1 group2\n" node.run.return_value = result groups = users._groups_for_user(node, "jdoe") node.run.assert_called_once_with("id -Gn jdoe") self.assertEqual(groups, ["group1", "group2"])
def test_not_installed(self): runresult = RunResult() runresult.return_code = 1 runresult.stdout = ( "Package `foo' is not installed and no info is available.\n" "Use dpkg --info (= dpkg-deb --info) to examine archive files,\n" "and dpkg --contents (= dpkg-deb --contents) to list their contents.\n" ) node = MagicMock() node.run.return_value = runresult self.assertFalse(pkg_apt.pkg_installed(node, "foo"))
def test_short_mode(self): node = MagicMock() run_result = RunResult() run_result.stdout = "user:group:666:4321" node.run.return_value = run_result stat_result = remote.stat(node, "/dev/null") self.assertEqual(stat_result, { 'owner': "user", 'group': "group", 'mode': "0666", 'size': 4321, })
def test_long_mode(self): node = MagicMock() run_result = RunResult() run_result.stdout = "user:group:7777:1234" node.run.return_value = run_result stat_result = remote.stat(node, "/dev/null") self.assertEqual(stat_result, { 'owner': "user", 'group': "group", 'mode': "7777", 'size': 1234, })
def test_gid(self): bundle = MagicMock() group = groups.Group( bundle, "blockwart", { 'gid': 2345 }, ) grep_result = RunResult() grep_result.return_code = 0 grep_result.stdout = "blockwart:x:5432:user1,user2\n" bundle.node.run.return_value = grep_result status = group.get_status() self.assertFalse(status.correct)
def test_delete(self): bundle = MagicMock() user = users.User( bundle, "blockwart", {'delete': True}, ) passwd_grep_result = RunResult() passwd_grep_result.return_code = 0 passwd_grep_result.stdout = "blockwart:x:1123:2345:Blöck Wart:/home/blockwart:/bin/bash\n" bundle.node.run.return_value = passwd_grep_result status = user.get_status() self.assertFalse(status.correct) self.assertTrue(status.info['exists'])
def test_not_running(self): runresult = RunResult() runresult.stdout = "foo stop/waiting\n" node = MagicMock() node.run.return_value = runresult self.assertFalse(svc_upstart.svc_running(node, "foo"))