2010-03-26 10:27:19 +00:00
|
|
|
require 'test_helper'
|
2009-10-12 11:37:42 +00:00
|
|
|
|
2013-01-23 01:17:17 +00:00
|
|
|
class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
|
2010-11-20 14:54:01 +00:00
|
|
|
test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
|
|
|
|
create_user(:email => 'Foo@Bar.com')
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2010-11-20 14:54:01 +00:00
|
|
|
sign_in_as_user do
|
|
|
|
fill_in 'email', :with => 'foo@bar.com'
|
|
|
|
end
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2010-11-20 14:54:01 +00:00
|
|
|
assert warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'sign in with email of different case should fail when email is NOT the list of case insensitive keys' do
|
|
|
|
swap Devise, :case_insensitive_keys => [] do
|
|
|
|
create_user(:email => 'Foo@Bar.com')
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2010-11-20 14:54:01 +00:00
|
|
|
sign_in_as_user do
|
|
|
|
fill_in 'email', :with => 'foo@bar.com'
|
|
|
|
end
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2010-11-20 14:54:01 +00:00
|
|
|
assert_not warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
end
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2011-06-10 08:37:43 +00:00
|
|
|
test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do
|
|
|
|
create_user(:email => ' foo@bar.com ')
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2011-06-10 08:37:43 +00:00
|
|
|
sign_in_as_user do
|
|
|
|
fill_in 'email', :with => 'foo@bar.com'
|
|
|
|
end
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2011-06-10 08:37:43 +00:00
|
|
|
assert warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do
|
2011-06-10 09:10:56 +00:00
|
|
|
swap Devise, :strip_whitespace_keys => [] do
|
|
|
|
create_user(:email => 'foo@bar.com')
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2011-06-10 08:37:43 +00:00
|
|
|
sign_in_as_user do
|
2011-06-10 09:10:56 +00:00
|
|
|
fill_in 'email', :with => ' foo@bar.com '
|
2011-06-10 08:37:43 +00:00
|
|
|
end
|
2012-07-06 14:46:46 +00:00
|
|
|
|
2011-06-10 08:37:43 +00:00
|
|
|
assert_not warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
end
|
2010-11-20 14:54:01 +00:00
|
|
|
|
2010-02-06 00:33:32 +00:00
|
|
|
test 'sign in should not authenticate if not using proper authentication keys' do
|
2009-11-15 05:31:13 +00:00
|
|
|
swap Devise, :authentication_keys => [:username] do
|
|
|
|
sign_in_as_user
|
|
|
|
assert_not warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-06 00:33:32 +00:00
|
|
|
test 'sign in with invalid email should return to sign in form with error message' do
|
2012-12-13 07:43:43 +00:00
|
|
|
store_translations :en, :devise => { :failure => { :admin => { :not_found_in_database => 'Invalid email address' } } } do
|
2012-11-19 23:49:21 +00:00
|
|
|
sign_in_as_admin do
|
|
|
|
fill_in 'email', :with => 'wrongemail@test.com'
|
|
|
|
end
|
2009-10-12 11:37:42 +00:00
|
|
|
|
2012-11-19 23:49:21 +00:00
|
|
|
assert_contain 'Invalid email address'
|
|
|
|
assert_not warden.authenticated?(:admin)
|
|
|
|
end
|
2009-10-12 11:37:42 +00:00
|
|
|
end
|
|
|
|
|
2010-02-06 00:33:32 +00:00
|
|
|
test 'sign in with invalid pasword should return to sign in form with error message' do
|
2009-10-12 11:37:42 +00:00
|
|
|
sign_in_as_admin do
|
|
|
|
fill_in 'password', :with => 'abcdef'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_contain 'Invalid email or password'
|
|
|
|
assert_not warden.authenticated?(:admin)
|
|
|
|
end
|
|
|
|
|
2009-10-12 13:18:14 +00:00
|
|
|
test 'error message is configurable by resource name' do
|
2010-04-03 11:11:45 +00:00
|
|
|
store_translations :en, :devise => { :failure => { :admin => { :invalid => "Invalid credentials" } } } do
|
2009-10-12 13:18:14 +00:00
|
|
|
sign_in_as_admin do
|
|
|
|
fill_in 'password', :with => 'abcdef'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_contain 'Invalid credentials'
|
|
|
|
end
|
|
|
|
end
|
2012-07-06 14:46:46 +00:00
|
|
|
end
|