Exemplo n.º 1
0
    def test_users_resumed(self):
        # Setup
        users.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        self.v1_test_db.database.roles.insert({'name' : 'new-to-v1', 'permissions' : {}})

        # Test
        report = users.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        v1_roles = list(self.v1_test_db.database.roles.find())
        v2_roles = list(self.tmp_test_db.database.roles.find())
        # Verify that all the roles except for consumer-users role are added to v2 db
        self.assertEqual(len(v1_roles), len(v2_roles)+1)

        v1_users = list(self.v1_test_db.database.users.find())
        v2_users = list(self.tmp_test_db.database.users.find())
        # Verify that all the users except for consumer user are added to v2 db
        self.assertEqual(len(v1_users), len(v2_users)+1)

        v1_perms = list(self.v1_test_db.database.permissions.find())
        v2_perms = list(self.tmp_test_db.database.permissions.find())
        self.assertEqual(len(v1_perms), len(v2_perms))
Exemplo n.º 2
0
    def test_users_resumed(self):
        # Setup
        users.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        self.v1_test_db.database.roles.insert({
            'name': 'new-to-v1',
            'permissions': {}
        })

        # Test
        report = users.upgrade(self.v1_test_db.database,
                               self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        v1_roles = list(self.v1_test_db.database.roles.find())
        v2_roles = list(self.tmp_test_db.database.roles.find())
        # Verify that all the roles except for consumer-users role are added to v2 db
        self.assertEqual(len(v1_roles), len(v2_roles) + 1)

        v1_users = list(self.v1_test_db.database.users.find())
        v2_users = list(self.tmp_test_db.database.users.find())
        # Verify that all the users except for consumer user are added to v2 db
        self.assertEqual(len(v1_users), len(v2_users) + 1)

        v1_perms = list(self.v1_test_db.database.permissions.find())
        v2_perms = list(self.tmp_test_db.database.permissions.find())
        self.assertEqual(len(v1_perms), len(v2_perms))
Exemplo n.º 3
0
    def test_users_idempotency(self):
        # Setup
        users.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Test
        report = users.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        v1_roles = list(self.v1_test_db.database.roles.find())
        v2_roles = list(self.tmp_test_db.database.roles.find())
        self.assertEqual(len(v1_roles), len(v2_roles))

        v1_users = list(self.v1_test_db.database.users.find())
        v2_users = list(self.tmp_test_db.database.users.find())
        self.assertEqual(len(v1_users), len(v2_users))

        v1_perms = list(self.v1_test_db.database.permissions.find())
        v2_perms = list(self.tmp_test_db.database.permissions.find())
        self.assertEqual(len(v1_perms), len(v2_perms))
Exemplo n.º 4
0
    def test_users(self):
        # Test
        report = users.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        # Verify that all the roles except for consumer-users role are added to v2 db
        v1_roles = list(self.v1_test_db.database.roles.find({ 'name': { '$ne' : 'consumer-users'}}).sort('name', 1))
        v2_roles = list(self.tmp_test_db.database.roles.find().sort('display_name', 1))

        self.assertEqual(len(v1_roles), len(v2_roles))

        for v1_role, v2_role in zip(v1_roles, v2_roles):
            self.assertTrue(v1_role['_id'] != v2_role['_id'])
            self.assertTrue(isinstance(v2_role['_id'], ObjectId))
            self.assertEqual(v1_role['name'], v2_role['display_name'])
            self.assertEqual(v1_role['permissions'], v2_role['permissions'])
            self.assertTrue('name' not in v2_role)

        # Verify that all the users except for consumer user are added to v2 db
        v1_users = list(self.v1_test_db.database.users.find({ 'roles': { '$ne' : ['consumer-users']}}).sort('login', 1))
        v2_users = list(self.tmp_test_db.database.users.find().sort('login', 1))
        self.assertEqual(len(v1_users), len(v2_users))

        for v1_user, v2_user in zip(v1_users, v2_users):
            self.assertEqual(v1_user['id'], v2_user['id'])
            self.assertEqual(v1_user['login'], v2_user['login'])
            self.assertEqual(v1_user['password'], v2_user['password'])
            self.assertEqual(v1_user['roles'], v2_user['roles'])

            # Check for new rules around name in v2
            self.assertTrue( (v2_user['name'] == v1_user['name']) or
                             (v2_user['name'] == v1_user['login']))

        # Verify Permissions
        v1_perms = list(self.v1_test_db.database.permissions.find().sort('_id'))
        v2_perms = list(self.tmp_test_db.database.permissions.find().sort('_id'))
        self.assertEqual(len(v1_perms), len(v2_perms))

        for v1_perm, v2_perm in zip(v1_perms, v2_perms):
            self.assertTrue(isinstance(v2_perm['_id'], ObjectId))
            self.assertEqual(v1_perm['resource'], v2_perm['resource'])
            # Check for all permissions except for ones related to consumer users
            if v1_perm['resource'] not in ['/consumers/','/repositories/','/errata/','/consumers/prosperity/']:
                self.assertEqual(v1_perm['users'], v2_perm['users'])
Exemplo n.º 5
0
    def test_users(self):
        # Test
        report = users.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        # Verify Roles
        v1_roles = list(self.v1_test_db.database.roles.find().sort('name', 1))
        v2_roles = list(self.tmp_test_db.database.roles.find().sort('display_name', 1))
        self.assertEqual(len(v1_roles), len(v2_roles))

        for v1_role, v2_role in zip(v1_roles, v2_roles):
            self.assertTrue(v1_role['_id'] != v2_role['_id'])
            self.assertTrue(isinstance(v2_role['_id'], ObjectId))
            self.assertEqual(v1_role['name'], v2_role['display_name'])
            self.assertEqual(v1_role['permissions'], v2_role['permissions'])
            self.assertTrue('name' not in v2_role)

        # Verify Users
        v1_users = list(self.v1_test_db.database.users.find().sort('login', 1))
        v2_users = list(self.tmp_test_db.database.users.find().sort('login', 1))
        self.assertEqual(len(v1_users), len(v2_users))

        for v1_user, v2_user in zip(v1_users, v2_users):
            self.assertEqual(v1_user['id'], v2_user['id'])
            self.assertEqual(v1_user['login'], v2_user['login'])
            self.assertEqual(v1_user['password'], v2_user['password'])
            self.assertEqual(v1_user['roles'], v2_user['roles'])

            # Check for new rules around name in v2
            self.assertTrue( (v2_user['name'] == v1_user['name']) or
                             (v2_user['name'] == v1_user['login']))

        # Verify Permissions
        v1_perms = list(self.v1_test_db.database.permissions.find().sort('_id'))
        v2_perms = list(self.tmp_test_db.database.permissions.find().sort('_id'))
        self.assertEqual(len(v1_perms), len(v2_perms))

        for v1_perm, v2_perm in zip(v1_perms, v2_perms):
            self.assertTrue(isinstance(v2_perm['_id'], ObjectId))
            self.assertEqual(v1_perm['resource'], v2_perm['resource'])
            self.assertEqual(v1_perm['users'], v2_perm['users'])
Exemplo n.º 6
0
    def test_users(self):
        # Test
        report = users.upgrade(self.v1_test_db.database,
                               self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        # Verify that all the roles except for consumer-users role are added to v2 db
        v1_roles = list(
            self.v1_test_db.database.roles.find({
                'name': {
                    '$ne': 'consumer-users'
                }
            }).sort('name', 1))
        v2_roles = list(self.tmp_test_db.database.roles.find().sort(
            'display_name', 1))

        self.assertEqual(len(v1_roles), len(v2_roles))

        for v1_role, v2_role in zip(v1_roles, v2_roles):
            self.assertTrue(v1_role['_id'] != v2_role['_id'])
            self.assertTrue(isinstance(v2_role['_id'], ObjectId))
            self.assertEqual(v1_role['name'], v2_role['display_name'])
            self.assertEqual(v1_role['permissions'], v2_role['permissions'])
            self.assertTrue('name' not in v2_role)

        # Verify that all the users except for consumer user are added to v2 db
        v1_users = list(
            self.v1_test_db.database.users.find({
                'roles': {
                    '$ne': ['consumer-users']
                }
            }).sort('login', 1))
        v2_users = list(self.tmp_test_db.database.users.find().sort(
            'login', 1))
        self.assertEqual(len(v1_users), len(v2_users))

        for v1_user, v2_user in zip(v1_users, v2_users):
            self.assertEqual(v1_user['id'], v2_user['id'])
            self.assertEqual(v1_user['login'], v2_user['login'])
            self.assertEqual(v1_user['password'], v2_user['password'])
            self.assertEqual(v1_user['roles'], v2_user['roles'])

            # Check for new rules around name in v2
            self.assertTrue((v2_user['name'] == v1_user['name'])
                            or (v2_user['name'] == v1_user['login']))

        # Verify Permissions
        v1_perms = list(
            self.v1_test_db.database.permissions.find().sort('_id'))
        v2_perms = list(
            self.tmp_test_db.database.permissions.find().sort('_id'))
        self.assertEqual(len(v1_perms), len(v2_perms))

        for v1_perm, v2_perm in zip(v1_perms, v2_perms):
            self.assertTrue(isinstance(v2_perm['_id'], ObjectId))
            self.assertEqual(v1_perm['resource'], v2_perm['resource'])
            # Check for all permissions except for ones related to consumer users
            if v1_perm['resource'] not in [
                    '/consumers/', '/repositories/', '/errata/',
                    '/consumers/prosperity/'
            ]:
                self.assertEqual(v1_perm['users'], v2_perm['users'])