예제 #1
0
 def test_make_token(self):
     """
     Ensure that we can make a token and that it is valid
     """
     user = User.objects.create_user('tokentestuser', '*****@*****.**', 'testpw')
     p0 = PasswordResetTokenGenerator()
     tk1 = p0.make_token(user)
     self.assertTrue(p0.check_token(user, tk1))
예제 #2
0
 def test_10265(self):
     """
     Ensure that the token generated for a user created in the same request
     will work correctly.
     """
     # See ticket #10265
     user = User.objects.create_user('comebackkid', '*****@*****.**', 'testpw')
     p0 = PasswordResetTokenGenerator()
     tk1 = p0.make_token(user)
     reload = User.objects.get(username='******')
     tk2 = p0.make_token(reload)
     self.assertEqual(tk1, tk2)
예제 #3
0
    def test_timeout(self):
        """
        Ensure we can use the token after n days, but no greater.
        """
        # Uses a mocked version of PasswordResetTokenGenerator so we can change
        # the value of 'today'
        class Mocked(PasswordResetTokenGenerator):
            def __init__(self, today):
                self._today_val = today
            def _today(self):
                return self._today_val

        user = User.objects.create_user('tokentestuser', '*****@*****.**', 'testpw')
        p0 = PasswordResetTokenGenerator()
        tk1 = p0.make_token(user)
        p1 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS))
        self.assertTrue(p1.check_token(user, tk1))

        p2 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1))
        self.assertFalse(p2.check_token(user, tk1))