def test_groups(self): bundle = MagicMock() user = users.User( bundle, "blockwart", { 'full_name': "Blöck Wart", 'gid': 2345, 'groups': ["group1", "group2", "group3"], 'home': "/home/blockwart", 'password_hash': "secret", 'shell': "/bin/bash", 'uid': 1123, }, ) status = ItemStatus(correct=False) status.info = { 'exists': True, 'full_name': "Blöck Wart", 'gid': 2345, 'groups': ["group3", "group2", "group4", "group5"], 'home': "/home/blockwart", 'shadow_hash': "secret", 'shell': "/bin/bash", 'uid': 1123, } self.assertEqual( user.ask(status), "missing groups group1\n" + "extra groups group4, group5\n" )
def test_shadow_not_found(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, }, ) status = ItemStatus(correct=False) status.info = { 'exists': True, 'full_name': "Blöck Wart", 'gid': 2345, 'groups': ["group1", "group2"], 'home': "/home/blockwart", 'shadow_hash': None, 'shell': "/bin/bash", 'uid': 1123, } self.assertEqual( user.ask(status), "password hash not found in /etc/shadow\n" )
def test_group(self): bundle = MagicMock() group = groups.Group( bundle, "blockwart", { 'gid': 2345 }, ) status = ItemStatus(correct=False) status.info = { 'exists': True, 'gid': 2357, } self.assertEqual( group.ask(status), "GID 2357 → 2345\n", )
def get_status(self): # verify content of /etc/group grep_result = self.node.run( "grep -e '^{}:' /etc/group".format(self.name), may_fail=True, ) if grep_result.return_code != 0: return ItemStatus(correct=self.attributes['delete'], info={'exists': False}) status = ItemStatus(correct=not self.attributes['delete'], info={'exists': True}) status.info.update(_parse_group_line(grep_result.stdout)) if status.info['gid'] != self.attributes['gid']: status.correct = False return status
def get_status(self): value = debconf_selection(self.node, self.attributes['pkg_name'], self.name) value_exists = (value) item_status = (value == self.attributes['value']) return ItemStatus( correct=item_status, info={ 'exists': value_exists, 'value': value, }, )
def get_status(self): # verify content of /etc/passwd passwd_grep_result = self.node.run( "grep -e '^{}:' /etc/passwd".format(self.name), may_fail=True, ) if passwd_grep_result.return_code != 0: return ItemStatus( correct=self.attributes['delete'], info={'exists': False}, ) elif self.attributes['delete']: return ItemStatus(correct=False, info={'exists': True}) status = ItemStatus(correct=True, info={'exists': True}) status.info.update(_parse_passwd_line(passwd_grep_result.stdout)) if passwd_grep_result.stdout.strip() != self.line_passwd: status.correct = False if self.attributes['use_shadow']: # verify content of /etc/shadow shadow_grep_result = self.node.run( "grep -e '^{}:' /etc/shadow".format(self.name), may_fail=True, ) if shadow_grep_result.return_code != 0: status.correct = False status.info['shadow_hash'] = None else: status.info['shadow_hash'] = shadow_grep_result.stdout.split(":")[1] if status.info['shadow_hash'] != self.attributes['password_hash']: status.correct = False else: if status.info['passwd_hash'] != self.attributes['password_hash']: status.correct = False # verify content of /etc/group status.info['groups'] = _groups_for_user(self.node, self.name) if set(self.attributes['groups']) != set(status.info['groups']): status.correct = False return status
def test_passwd(self): bundle = MagicMock() user = users.User( bundle, "blockwart", { 'full_name': "Blöck Wart", 'gid': 2345, 'groups': ["group1", "group2"], 'password_hash': "topsecret", 'shell': "/bin/bash", 'uid': 1123, 'use_shadow': False, }, ) status = ItemStatus(correct=False) status.info = { 'exists': True, 'full_name': "Blockwart", 'gid': 2357, 'groups': ["group1", "group2"], 'home': "/home/blkwrt", 'passwd_hash': "secret", 'shell': "/bin/bsh", 'uid': 1113, } self.assertEqual( user.ask(status), "shell /bin/bsh → /bin/bash\n" "full name Blockwart → Blöck Wart\n" "GID 2357 → 2345\n" "home dir /home/blkwrt → /home/blockwart\n" "UID 1113 → 1123\n" "password hash secret\n" " → topsecret\n" )