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_locked(self, ask_interactively): node = MagicMock() runres = RunResult() runres.return_code = 1 node.run.return_value = runres with self.assertRaises(NodeAlreadyLockedException): with NodeLock(node, False, ignore=False): pass
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_group_fail(self): bundle = MagicMock() group = groups.Group( bundle, "blockwart", { 'gid': 2345 }, ) grep_result = RunResult() grep_result.return_code = 1 bundle.node.run.return_value = grep_result status = group.get_status() self.assertFalse(status.correct) self.assertFalse(status.info['exists'])
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_passwd_fail(self): 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 = 1 bundle.node.run.return_value = passwd_grep_result status = user.get_status() self.assertFalse(status.correct) self.assertFalse(status.info['exists'])