How to use the bundlewrap.items.ItemStatus function in bundlewrap

To help you get started, we’ve selected a few bundlewrap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bundlewrap / bundlewrap / tests_legacy / unit / items / groups_tests.py View on Github external
def test_group_shouldnt_exist(self):
        bundle = MagicMock()
        group = groups.Group(
            bundle,
            "bundlewrap",
            {'delete': True},
        )
        status = ItemStatus(correct=False, info={'exists': True})
        self.assertEqual(
            group.ask(status),
            "'bundlewrap' found in /etc/group. Will be deleted."
        )
github bundlewrap / bundlewrap / tests_legacy / unit / items / users_tests.py View on Github external
bundle = MagicMock()
        user = users.User(
            bundle,
            "bundlewrap",
            {
                'home': "/home/bundlewrap",
                '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': "BundleWrap",
            'gid': 2357,
            'groups': ["group1", "group2"],
            'home': "/home/blkwrt",
            'passwd_hash': "secret",
            'shell': "/bin/bsh",
            'uid': 1113,
            'needs_fixing': ['home', 'full_name', 'gid', 'password', 'shell', 'uid'],
        }
        self.assertEqual(
            user.ask(status),
            "home dir /home/blkwrt → /home/bundlewrap\n"
            "full name BundleWrap → Blöck Wart\n"
github bundlewrap / bundlewrap / tests_legacy / unit / items / users_tests.py View on Github external
def test_shadow_not_found(self):
        bundle = MagicMock()
        user = users.User(
            bundle,
            "bundlewrap",
            {
                'full_name': "Blöck Wart",
                'gid': 2345,
                'groups': ["group1", "group2"],
                'home': "/home/bundlewrap",
                '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/bundlewrap",
            'shadow_hash': None,
            'shell': "/bin/bash",
            'uid': 1123,
            'needs_fixing': ['password'],
        }
        self.assertEqual(
            user.ask(status),
            "password hash not found in /etc/shadow\n"
        )
github bundlewrap / bundlewrap / tests_legacy / unit / items / users_tests.py View on Github external
def test_user_doesnt_exist(self):
        bundle = MagicMock()
        user = users.User(
            bundle,
            "bundlewrap",
            {
                'full_name': "Blöck Wart",
                'gid': 2345,
                'groups': ["group1", "group2"],
                'home': "/home/bundlewrap",
                'password_hash': "secret",
                'shell': "/bin/bash",
                'uid': 1123,
            },
        )
        status = ItemStatus(correct=False, info={'exists': False})
        self.assertEqual(
            user.ask(status),
            "'bundlewrap' not found in /etc/passwd"
        )
github bundlewrap / bundlewrap / tests_legacy / unit / items / users_tests.py View on Github external
def test_groups(self):
        bundle = MagicMock()
        user = users.User(
            bundle,
            "bundlewrap",
            {
                'full_name': "Blöck Wart",
                'gid': 2345,
                'groups': ["group1", "group2", "group3"],
                'home': "/home/bundlewrap",
                '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/bundlewrap",
            'shadow_hash': "secret",
            'shell': "/bin/bash",
            'uid': 1123,
            'needs_fixing': ['groups'],
        }
        self.assertEqual(
            user.ask(status),
            "missing groups group1\n" +
            "extra groups group4, group5\n"
        )
github bundlewrap / bundlewrap / tests_legacy / unit / items / groups_tests.py View on Github external
def test_group_doesnt_exist(self):
        bundle = MagicMock()
        group = groups.Group(
            bundle,
            "bundlewrap",
            { 'gid': 2345 },
        )
        status = ItemStatus(correct=False, info={'exists': False})
        self.assertEqual(
            group.ask(status),
            "'bundlewrap' not found in /etc/group"
        )
github bundlewrap / bundlewrap / tests_legacy / unit / items / files_tests.py View on Github external
def test_combined(self, fix_type, fix_owner, fix_mode, fix_content):
        f = files.File(MagicMock(), "/foo", {})
        pinfo = MagicMock()
        pinfo.exists = False
        status = ItemStatus(correct=False, info={
            'path_info': pinfo,
            'needs_fixing': ['owner', 'mode'],
        })
        f.fix(status)
        self.assertFalse(fix_type.called)
        fix_owner.assert_called_once_with(status)
        fix_mode.assert_called_once_with(status)
        self.assertFalse(fix_content.called)
github bundlewrap / bundlewrap / tests_legacy / unit / items / directories_tests.py View on Github external
def test_owner(self, fix_type, fix_owner, fix_mode):
        f = directories.Directory(MagicMock(), "/", {})
        status = ItemStatus(correct=False, info={
            'needs_fixing': ['owner'],
        })
        f.fix(status)
        self.assertFalse(fix_type.called)
        fix_owner.assert_called_once_with(status)
        self.assertFalse(fix_mode.called)
github bundlewrap / bundlewrap / tests_legacy / unit / items / postgres_roles_tests.py View on Github external
def test_create(self):
        bundle = MagicMock()
        role = postgres_roles.PostgresRole(
            bundle,
            "bundlewrap",
            {},
        )
        status = ItemStatus(correct=False, info={
            'can_login': False,
            'exists': False,
            'needs_fixing': ['existence'],
            'password_hash': "foo",
            'superuser': False,
        })
        role.fix(status)
        self.assertEqual(
            bundle.node.run.call_args_list,
            [
                call("echo \"CREATE ROLE bundlewrap WITH LOGIN NOSUPERUSER\" | sudo -u postgres psql -nqw"),
            ],
github bundlewrap / bundlewrap / tests_legacy / unit / items / postgres_roles_tests.py View on Github external
def test_change_superuser(self):
        bundle = MagicMock()
        role = postgres_roles.PostgresRole(
            bundle,
            "bundlewrap",
            {'superuser': True},
        )
        status = ItemStatus(correct=False, info={
            'can_login': True,
            'exists': True,
            'needs_fixing': ['superuser'],
            'password_hash': "foo",
            'superuser': False,
        })
        role.fix(status)
        self.assertEqual(
            bundle.node.run.call_args_list,
            [
                call("echo \"ALTER ROLE bundlewrap WITH LOGIN SUPERUSER\""
                     " | sudo -u postgres psql -nqw"),