#NEWLINE# def testGenerateAndValidateToken( self ) : #NEWLINE# #INDENT# 'Test generating and validating a token.' #NEWLINE# token = xsrfutil . generate_token ( TEST_KEY , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 , when = TEST_TIME ) #NEWLINE# self . assertTrue ( xsrfutil . validate_token ( TEST_KEY , token , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 , current_time = TEST_TIME ) ) #NEWLINE# later15mins = ( TEST_TIME + ( 15 * 60 ) ) #NEWLINE# self . assertTrue ( xsrfutil . validate_token ( TEST_KEY , token , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 , current_time = later15mins ) ) #NEWLINE# later2hours = ( TEST_TIME + ( ( 2 * 60 ) * 60 ) ) #NEWLINE# self . assertFalse ( xsrfutil . validate_token ( TEST_KEY , token , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 , current_time = later2hours ) ) #NEWLINE# self . assertFalse ( xsrfutil . validate_token ( 'another key' , token , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 , current_time = later15mins ) ) #NEWLINE# self . assertFalse ( xsrfutil . validate_token ( TEST_KEY , token , TEST_USER_ID_2 , action_id = TEST_ACTION_ID_1 , current_time = later15mins ) ) #NEWLINE# self . assertFalse ( xsrfutil . validate_token ( TEST_KEY , token , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_2 , current_time = later15mins ) ) #NEWLINE# self . assertFalse ( xsrfutil . validate_token ( TEST_KEY , token [ : ( - 1 ) ] , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 , current_time = later15mins ) ) #NEWLINE# self . assertFalse ( xsrfutil . validate_token ( TEST_KEY , ( token + b'x' ) , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 , current_time = later15mins ) ) #NEWLINE# self . assertFalse ( xsrfutil . validate_token ( TEST_KEY , None , TEST_USER_ID_1 , action_id = TEST_ACTION_ID_1 ) )