'Test generating and validating a token.'

def testGenerateAndValidateToken(self):

    token = xsrfutil.generate_token(TEST_KEY, TEST_USER_ID_1, action_id=TEST_ACTION_ID_1, when=TEST_TIME)
    self.assertTrue(xsrfutil.validate_token(TEST_KEY, token, TEST_USER_ID_1, action_id=TEST_ACTION_ID_1, current_time=TEST_TIME))
    later15mins = (TEST_TIME + (15 * 60))
    self.assertTrue(xsrfutil.validate_token(TEST_KEY, token, TEST_USER_ID_1, action_id=TEST_ACTION_ID_1, current_time=later15mins))
    later2hours = (TEST_TIME + ((2 * 60) * 60))
    self.assertFalse(xsrfutil.validate_token(TEST_KEY, token, TEST_USER_ID_1, action_id=TEST_ACTION_ID_1, current_time=later2hours))
    self.assertFalse(xsrfutil.validate_token('another    key', token, TEST_USER_ID_1, action_id=TEST_ACTION_ID_1, current_time=later15mins))
    self.assertFalse(xsrfutil.validate_token(TEST_KEY, token, TEST_USER_ID_2, action_id=TEST_ACTION_ID_1, current_time=later15mins))
    self.assertFalse(xsrfutil.validate_token(TEST_KEY, token, TEST_USER_ID_1, action_id=TEST_ACTION_ID_2, current_time=later15mins))
    self.assertFalse(xsrfutil.validate_token(TEST_KEY, token[:(-1)], TEST_USER_ID_1, action_id=TEST_ACTION_ID_1, current_time=later15mins))
    self.assertFalse(xsrfutil.validate_token(TEST_KEY, (token + 'x'), TEST_USER_ID_1, action_id=TEST_ACTION_ID_1, current_time=later15mins))
    self.assertFalse(xsrfutil.validate_token(TEST_KEY, None, TEST_USER_ID_1, action_id=TEST_ACTION_ID_1))
