Skip to content

Instantly share code, notes, and snippets.

@ntodd
Created February 13, 2011 23:00
Show Gist options
  • Save ntodd/825261 to your computer and use it in GitHub Desktop.
Save ntodd/825261 to your computer and use it in GitHub Desktop.
# DOES NOT WORK
test 'authenticate with valid authentication token key and do not store if stateless and timeoutable are enabled' do
swap Devise, :token_authentication_key => :secret_token, :stateless_token => true do
user = sign_in_as_new_user_with_token
assert warden.authenticated?(:user)
get expire_user_path(user)
get_users_path_as_existing_user(user)
assert warden.authenticated?(:user)
end
end
# WORKS
test 'authenticate with valid authentication token key and do not store if stateless and timeoutable are enabled' do
swap Devise, :token_authentication_key => :secret_token, :stateless_token => true, :timeout_in => 1.second do
user = sign_in_as_new_user_with_token
assert warden.authenticated?(:user)
sleep 2
# get expire_user_path(user)
get_users_path_as_existing_user(user)
assert warden.authenticated?(:user)
end
end
# SUPPORT
def get_users_path_as_existing_user(user, options = {})
options[:auth_token_key] ||= Devise.token_authentication_key
if options[:http_auth]
header = "Basic #{ActiveSupport::Base64.encode64("#{VALID_AUTHENTICATION_TOKEN}:X")}"
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => header
else
get users_path(options[:auth_token_key].to_sym => user.authentication_token)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment