<s> from datetime import date , timedelta <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User , AnonymousUser <EOL> from django . contrib . auth . tokens import PasswordResetTokenGenerator <EOL> from django . test import TestCase <EOL> class TokenGeneratorTest ( TestCase ) : <EOL> def test_make_token ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> p0 = PasswordResetTokenGenerator ( ) <EOL> tk1 = p0 . make_token ( user ) <EOL> self . assertTrue ( p0 . check_token ( user , tk1 ) ) <EOL> def test_10265 ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> p0 = PasswordResetTokenGenerator ( ) <EOL> tk1 = p0 . make_token ( user ) <EOL> reload = User . objects . get ( username = '<STR_LIT>' ) <EOL> tk2 = p0 . make_token ( reload ) <EOL> self . assertEqual ( tk1 , tk2 ) <EOL> def test_timeout ( self ) : <EOL> """<STR_LIT>""" <EOL> class Mocked ( PasswordResetTokenGenerator ) : <EOL> def __init__ ( self , today ) : <EOL> self . _today_val = today <EOL> def _today ( self ) : <EOL> return self . _today_val <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> p0 = PasswordResetTokenGenerator ( ) <EOL> tk1 = p0 . make_token ( user ) <EOL> p1 = Mocked ( date . today ( ) + timedelta ( settings . PASSWORD_RESET_TIMEOUT_DAYS ) ) <EOL> self . assertTrue ( p1 . check_token ( user , tk1 ) ) <EOL> p2 = Mocked ( date . today ( ) + timedelta ( settings . PASSWORD_RESET_TIMEOUT_DAYS + <NUM_LIT:1> ) ) <EOL> self . assertFalse ( p2 . check_token ( user , tk1 ) ) <EOL> def test_django12_hash ( self ) : <EOL> """<STR_LIT>""" <EOL> def _make_token ( user ) : <EOL> from django . utils . hashcompat import sha_constructor <EOL> from django . utils . http import int_to_base36 <EOL> timestamp = ( date . today ( ) - date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) . days <EOL> ts_b36 = int_to_base36 ( timestamp ) <EOL> hash = sha_constructor ( settings . SECRET_KEY + unicode ( user . id ) + <EOL> user . password + user . last_login . strftime ( '<STR_LIT>' ) + <EOL> unicode ( timestamp ) ) . hexdigest ( ) [ : : <NUM_LIT:2> ] <EOL> return "<STR_LIT>" % ( ts_b36 , hash ) <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> p0 = PasswordResetTokenGenerator ( ) <EOL> tk1 = _make_token ( user ) <EOL> self . assertTrue ( p0 . check_token ( user , tk1 ) ) <EOL> def test_date_length ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> p0 = PasswordResetTokenGenerator ( ) <EOL> tk1 = p0 . _make_token_with_timestamp ( user , <NUM_LIT> ) <EOL> self . assertFalse ( p0 . check_token ( user , tk1 ) ) </s>
