Exemple #1
0
 def test_register(self):
     """ Register a new user """
     self.access.register('foo', 'bar')
     transaction.commit()
     user = self.db.query(User).first()
     self.assertEqual(user.username, 'foo')
     self.assertTrue(pwd_context.verify('bar', user.password))
Exemple #2
0
 def test_gen_password(self, getpass):
     """ Generate a password """
     passwds = ['foo', 'foo', 'bar', 'baz']
     getpass.getpass.side_effect = passwds.pop
     ret = scripts._gen_password()
     self.assertEqual(len(passwds), 0)
     self.assertTrue(pwd_context.verify('foo', ret))
Exemple #3
0
 def test_gen_password(self, getpass):
     """ Generate a password """
     passwds = ['foo', 'foo', 'bar', 'baz']
     getpass.getpass.side_effect = passwds.pop
     ret = scripts._gen_password()
     self.assertEqual(len(passwds), 0)
     self.assertTrue(pwd_context.verify('foo', ret))
 def test_register(self):
     """ Register a new user """
     self.access.register('foo', 'bar')
     transaction.commit()
     user = self.db.query(User).first()
     self.assertEqual(user.username, 'foo')
     self.assertTrue(pwd_context.verify('bar', user.password))
 def test_save_unicode(self):
     """ register() can accept a username with unicode """
     username, passw = 'foo™', 'bar™'
     self.access.register(username, passw)
     transaction.commit()
     user = self.db.query(User).first()
     self.assertEqual(user.username, username)
     self.assertTrue(pwd_context.verify(passw, user.password))
Exemple #6
0
    def test_dump(self):
        """ Can dump all data to json format """
        user1 = make_user('user1', 'user1', True)
        user2 = make_user('user2', 'user2', False)
        user3 = make_user('user3', 'user3', False)
        user3.admin = True
        self.db.add_all([user1, user2, user3])
        transaction.commit()
        self.access.set_allow_register(False)
        self.access.create_group('g1')
        self.access.create_group('g2')
        self.access.edit_user_group('user2', 'g1', True)
        self.access.edit_user_group('user2', 'g2', True)
        self.access.edit_user_group('user3', 'g2', True)
        self.access.edit_user_permission('pkg1', 'user2', 'read', True)
        self.access.edit_user_permission('pkg2', 'user3', 'read', True)
        self.access.edit_user_permission('pkg2', 'user3', 'write', True)
        self.access.edit_group_permission('pkg1', 'g1', 'read', True)
        self.access.edit_group_permission('pkg2', 'g2', 'read', True)
        self.access.edit_group_permission('pkg2', 'g2', 'write', True)

        data = self.access.dump()

        self.assertFalse(data['allow_register'])

        # users
        self.assertEqual(len(data['users']), 2)
        for user in data['users']:
            self.assertTrue(
                pwd_context.verify(user['username'], user['password']))
            self.assertFalse(user['admin'] ^ (user['username'] == 'user3'))

        # pending users
        self.assertEqual(len(data['pending_users']), 1)
        user = data['pending_users'][0]
        self.assertTrue(pwd_context.verify(user['username'], user['password']))

        # groups
        self.assertEqual(len(data['groups']), 2)
        self.assertItemsEqual(data['groups']['g1'], ['user2'])
        self.assertItemsEqual(data['groups']['g2'], ['user2', 'user3'])

        # user package perms
        self.assertEqual(
            data['packages']['users'], {
                'pkg1': {
                    'user2': ['read'],
                },
                'pkg2': {
                    'user3': ['read', 'write'],
                },
            })

        # group package perms
        self.assertEqual(data['packages']['groups'], {
            'pkg1': {
                'g1': ['read'],
            },
            'pkg2': {
                'g2': ['read', 'write'],
            },
        })
    def test_dump(self):
        """ Can dump all data to json format """
        user1 = make_user('user1', 'user1', True)
        user2 = make_user('user2', 'user2', False)
        user3 = make_user('user3', 'user3', False)
        user3.admin = True
        self.db.add_all([user1, user2, user3])
        transaction.commit()
        self.access.set_allow_register(False)
        self.access.create_group('g1')
        self.access.create_group('g2')
        self.access.edit_user_group('user2', 'g1', True)
        self.access.edit_user_group('user2', 'g2', True)
        self.access.edit_user_group('user3', 'g2', True)
        self.access.edit_user_permission('pkg1', 'user2', 'read', True)
        self.access.edit_user_permission('pkg2', 'user3', 'read', True)
        self.access.edit_user_permission('pkg2', 'user3', 'write', True)
        self.access.edit_group_permission('pkg1', 'g1', 'read', True)
        self.access.edit_group_permission('pkg2', 'g2', 'read', True)
        self.access.edit_group_permission('pkg2', 'g2', 'write', True)

        data = self.access.dump()

        self.assertFalse(data['allow_register'])

        # users
        self.assertEqual(len(data['users']), 2)
        for user in data['users']:
            self.assertTrue(pwd_context.verify(user['username'],
                                               user['password']))
            self.assertFalse(user['admin'] ^ (user['username'] == 'user3'))

        # pending users
        self.assertEqual(len(data['pending_users']), 1)
        user = data['pending_users'][0]
        self.assertTrue(pwd_context.verify(user['username'], user['password']))

        # groups
        self.assertEqual(len(data['groups']), 2)
        self.assertItemsEqual(data['groups']['g1'], ['user2'])
        self.assertItemsEqual(data['groups']['g2'], ['user2', 'user3'])

        # user package perms
        self.assertEqual(data['packages']['users'], {
            'pkg1': {
                'user2': ['read'],
            },
            'pkg2': {
                'user3': ['read', 'write'],
            },
        })

        # group package perms
        self.assertEqual(data['packages']['groups'], {
            'pkg1': {
                'g1': ['read'],
            },
            'pkg2': {
                'g2': ['read', 'write'],
            },
        })