Beispiel #1
0
    def test_generate_confirmation_token(self):
        user_role = Role.query.filter_by(name='User').first()
        user = User(email=forgery_py.internet.email_address(),
                    username=forgery_py.internet.user_name(),
                    password='******',
                    avatar_hash=None,
                    role=user_role,
                    confirmed=True)
        db.session.add(user)
        db.session.commit()

        token1 = user.generate_confirmation_token(expiration=3600)
        token2 = user.generate_confirmation_token(expiration=3601)

        self.assertNotEqual(token1, token2)
Beispiel #2
0
    def test_user_invite(self):
        user_role = Role.query.filter_by(name='User').first()
        User.generate_fake(count=1)
        user1 = User.query.first()
        user2 = User(email=forgery_py.internet.email_address(), role=user_role)
        db.session.add(user2)
        db.session.commit()

        valid_token = user2.generate_invite_token(expiration=3600)
        invalid_token = user2.generate_confirmation_token(expiration=3600)

        valid_invite = user2.accept_invite(token=valid_token,
                                           username='******',
                                           new_password='******')
        invalid_invite = user2.accept_invite(invalid_token, 'username2',
                                             'new_password')
        invalid_invite2 = user2.accept_invite('', 'username2', 'new_password')

        self.assertTrue(valid_invite)
        self.assertTrue(user2.username, 'username2')
        self.assertTrue(user2.verify_password('new_password'))

        self.assertFalse(invalid_invite)
        self.assertFalse(invalid_invite2)
Beispiel #3
0
    def test_user_reset_password(self):
        user_role = Role.query.filter_by(name='User').first()
        user = User(email=forgery_py.internet.email_address(),
                    username=forgery_py.internet.user_name(),
                    password='******',
                    avatar_hash=None,
                    role=user_role,
                    confirmed=True)
        db.session.add(user)
        db.session.commit()

        reset_token = user.generate_reset_token()
        confirmation_token = user.generate_confirmation_token()

        valid_result = user.reset_password(token=reset_token,
                                           new_password='******')
        invalid_result = user.reset_password(token='',
                                             new_password='******')
        invalid_result2 = user.reset_password(token=confirmation_token,
                                              new_password='******')

        self.assertTrue(valid_result)
        self.assertFalse(invalid_result)
        self.assertFalse(invalid_result2)