devise 1.1.9 → 1.2.rc
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +34 -26
- data/README.rdoc +134 -100
- data/app/controllers/devise/confirmations_controller.rb +1 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +1 -1
- data/app/controllers/devise/registrations_controller.rb +59 -6
- data/app/controllers/devise/sessions_controller.rb +3 -2
- data/app/controllers/devise/unlocks_controller.rb +1 -1
- data/app/helpers/devise_helper.rb +4 -2
- data/app/mailers/devise/mailer.rb +27 -10
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +2 -2
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +1 -1
- data/app/views/devise/shared/_links.erb +6 -0
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +9 -2
- data/lib/devise.rb +116 -58
- data/lib/devise/controllers/helpers.rb +103 -107
- data/lib/devise/controllers/internal_helpers.rb +23 -7
- data/lib/devise/controllers/scoped_views.rb +4 -6
- data/lib/devise/controllers/url_helpers.rb +3 -5
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
- data/lib/devise/failure_app.rb +29 -21
- data/lib/devise/hooks/forgetable.rb +2 -1
- data/lib/devise/hooks/rememberable.rb +11 -9
- data/lib/devise/mapping.rb +12 -5
- data/lib/devise/models.rb +0 -14
- data/lib/devise/models/authenticatable.rb +40 -30
- data/lib/devise/models/confirmable.rb +11 -15
- data/lib/devise/models/database_authenticatable.rb +23 -35
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +8 -7
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +5 -3
- data/lib/devise/models/registerable.rb +13 -0
- data/lib/devise/models/rememberable.rb +38 -30
- data/lib/devise/models/timeoutable.rb +20 -3
- data/lib/devise/models/token_authenticatable.rb +19 -7
- data/lib/devise/models/validatable.rb +16 -4
- data/lib/devise/modules.rb +15 -8
- data/lib/devise/omniauth.rb +47 -0
- data/lib/devise/omniauth/config.rb +30 -0
- data/lib/devise/omniauth/test_helpers.rb +57 -0
- data/lib/devise/omniauth/url_helpers.rb +29 -0
- data/lib/devise/orm/active_record.rb +2 -0
- data/lib/devise/orm/mongoid.rb +4 -2
- data/lib/devise/rails.rb +26 -46
- data/lib/devise/rails/routes.rb +64 -20
- data/lib/devise/rails/warden_compat.rb +18 -20
- data/lib/devise/schema.rb +13 -14
- data/lib/devise/strategies/authenticatable.rb +33 -7
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +1 -1
- data/lib/devise/strategies/token_authenticatable.rb +6 -2
- data/lib/devise/test_helpers.rb +11 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -0
- data/lib/generators/devise/orm_helpers.rb +3 -2
- data/lib/generators/templates/devise.rb +70 -39
- data/test/controllers/helpers_test.rb +43 -67
- data/test/controllers/internal_helpers_test.rb +29 -8
- data/test/controllers/url_helpers_test.rb +2 -1
- data/test/failure_app_test.rb +56 -21
- data/test/generators/generators_test_helper.rb +4 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/views_generator_test.rb +37 -0
- data/test/integration/authenticatable_test.rb +147 -62
- data/test/integration/database_authenticatable_test.rb +22 -0
- data/test/integration/http_authenticatable_test.rb +12 -2
- data/test/integration/omniauthable_test.rb +107 -0
- data/test/integration/recoverable_test.rb +39 -20
- data/test/integration/registerable_test.rb +30 -4
- data/test/integration/rememberable_test.rb +57 -34
- data/test/integration/timeoutable_test.rb +10 -1
- data/test/integration/token_authenticatable_test.rb +12 -17
- data/test/mailers/confirmation_instructions_test.rb +4 -0
- data/test/mailers/reset_password_instructions_test.rb +4 -0
- data/test/mailers/unlock_instructions_test.rb +4 -0
- data/test/mapping_test.rb +37 -3
- data/test/models/confirmable_test.rb +3 -3
- data/test/models/database_authenticatable_test.rb +14 -71
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +17 -1
- data/test/models/recoverable_test.rb +17 -0
- data/test/models/rememberable_test.rb +186 -125
- data/test/models/token_authenticatable_test.rb +1 -13
- data/test/models_test.rb +5 -5
- data/test/omniauth/url_helpers_test.rb +47 -0
- data/test/rails_app/app/active_record/admin.rb +4 -1
- data/test/rails_app/app/active_record/user.rb +5 -4
- data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
- data/test/rails_app/app/controllers/home_controller.rb +9 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
- data/test/rails_app/app/mongoid/admin.rb +4 -1
- data/test/rails_app/app/mongoid/shim.rb +16 -3
- data/test/rails_app/app/mongoid/user.rb +5 -5
- data/test/rails_app/config/initializers/devise.rb +52 -28
- data/test/rails_app/config/routes.rb +14 -6
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
- data/test/rails_app/db/schema.rb +17 -51
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +23 -0
- data/test/routes_test.rb +42 -9
- data/test/support/integration.rb +3 -3
- data/test/support/webrat/integrations/rails.rb +7 -0
- data/test/test_helper.rb +2 -0
- data/test/test_helpers_test.rb +29 -0
- metadata +60 -30
- data/Gemfile +0 -27
- data/Gemfile.lock +0 -115
- data/Rakefile +0 -55
- data/TODO +0 -3
- data/lib/devise/encryptors/bcrypt.rb +0 -19
- data/lib/generators/devise_install_generator.rb +0 -4
- data/lib/generators/devise_views_generator.rb +0 -4
- data/test/indifferent_hash.rb +0 -33
- data/test/support/test_silencer.rb +0 -5
@@ -1,6 +1,28 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class DatabaseAuthenticationTest < ActionController::IntegrationTest
|
4
|
+
test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
|
5
|
+
create_user(:email => 'Foo@Bar.com')
|
6
|
+
|
7
|
+
sign_in_as_user do
|
8
|
+
fill_in 'email', :with => 'foo@bar.com'
|
9
|
+
end
|
10
|
+
|
11
|
+
assert warden.authenticated?(:user)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'sign in with email of different case should fail when email is NOT the list of case insensitive keys' do
|
15
|
+
swap Devise, :case_insensitive_keys => [] do
|
16
|
+
create_user(:email => 'Foo@Bar.com')
|
17
|
+
|
18
|
+
sign_in_as_user do
|
19
|
+
fill_in 'email', :with => 'foo@bar.com'
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_not warden.authenticated?(:user)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
4
26
|
test 'sign in should not authenticate if not using proper authentication keys' do
|
5
27
|
swap Devise, :authentication_keys => [:username] do
|
6
28
|
sign_in_as_user
|
@@ -47,6 +47,16 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
test 'sign in should authenticate with really long token' do
|
51
|
+
token = "token_containing_so_many_characters_that_the_base64_encoding_will_wrap"
|
52
|
+
user = create_user
|
53
|
+
user.update_attribute :authentication_token, token
|
54
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{ActiveSupport::Base64.encode64("#{token}:x")}"
|
55
|
+
assert_response :success
|
56
|
+
assert_match "<email>user@test.com</email>", response.body
|
57
|
+
assert warden.authenticated?(:user)
|
58
|
+
end
|
59
|
+
|
50
60
|
private
|
51
61
|
|
52
62
|
def sign_in_as_new_user_with_http(username="user@test.com", password="123456")
|
@@ -54,11 +64,11 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
54
64
|
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}"
|
55
65
|
user
|
56
66
|
end
|
57
|
-
|
67
|
+
|
58
68
|
# Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication
|
59
69
|
def add_oauth2_header
|
60
70
|
user = create_user
|
61
71
|
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{ActiveSupport::Base64.encode64("#{user.email}:123456")}"
|
62
72
|
end
|
63
73
|
|
64
|
-
end
|
74
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OmniauthableIntegrationTest < ActionController::IntegrationTest
|
4
|
+
FACEBOOK_INFO = {
|
5
|
+
:id => '12345',
|
6
|
+
:link => 'http://facebook.com/josevalim',
|
7
|
+
:email => 'user@example.com',
|
8
|
+
:first_name => 'Jose',
|
9
|
+
:last_name => 'Valim',
|
10
|
+
:website => 'http://blog.plataformatec.com.br'
|
11
|
+
}
|
12
|
+
|
13
|
+
ACCESS_TOKEN = {
|
14
|
+
:access_token => "plataformatec"
|
15
|
+
}
|
16
|
+
|
17
|
+
setup do
|
18
|
+
stub_facebook!
|
19
|
+
Devise::OmniAuth.short_circuit_authorizers!
|
20
|
+
end
|
21
|
+
|
22
|
+
teardown do
|
23
|
+
Devise::OmniAuth.unshort_circuit_authorizers!
|
24
|
+
Devise::OmniAuth.reset_stubs!
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_facebook!
|
28
|
+
Devise::OmniAuth.stub!(:facebook) do |b|
|
29
|
+
b.post('/oauth/access_token') { [200, {}, ACCESS_TOKEN.to_json] }
|
30
|
+
b.get('/me?access_token=plataformatec') { [200, {}, FACEBOOK_INFO.to_json] }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
test "can access omniauth.auth in the env hash" do
|
35
|
+
visit "/users/sign_in"
|
36
|
+
click_link "Sign in with Facebook"
|
37
|
+
|
38
|
+
json = ActiveSupport::JSON.decode(response.body)
|
39
|
+
|
40
|
+
assert_equal "12345", json["uid"]
|
41
|
+
assert_equal "facebook", json["provider"]
|
42
|
+
assert_equal "josevalim", json["user_info"]["nickname"]
|
43
|
+
assert_equal FACEBOOK_INFO, json["extra"]["user_hash"].symbolize_keys
|
44
|
+
assert_equal "plataformatec", json["credentials"]["token"]
|
45
|
+
end
|
46
|
+
|
47
|
+
test "cleans up session on sign up" do
|
48
|
+
assert_no_difference "User.count" do
|
49
|
+
visit "/users/sign_in"
|
50
|
+
click_link "Sign in with Facebook"
|
51
|
+
end
|
52
|
+
|
53
|
+
assert session["devise.facebook_data"]
|
54
|
+
|
55
|
+
assert_difference "User.count" do
|
56
|
+
visit "/users/sign_up"
|
57
|
+
fill_in "Password", :with => "123456"
|
58
|
+
fill_in "Password confirmation", :with => "123456"
|
59
|
+
click_button "Sign up"
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_current_url "/"
|
63
|
+
assert_contain "You have signed up successfully."
|
64
|
+
assert_contain "Hello User user@example.com"
|
65
|
+
assert_not session["devise.facebook_data"]
|
66
|
+
end
|
67
|
+
|
68
|
+
test "cleans up session on cancel" do
|
69
|
+
assert_no_difference "User.count" do
|
70
|
+
visit "/users/sign_in"
|
71
|
+
click_link "Sign in with Facebook"
|
72
|
+
end
|
73
|
+
|
74
|
+
assert session["devise.facebook_data"]
|
75
|
+
visit "/users/cancel"
|
76
|
+
assert !session["devise.facebook_data"]
|
77
|
+
end
|
78
|
+
|
79
|
+
test "cleans up session on sign in" do
|
80
|
+
assert_no_difference "User.count" do
|
81
|
+
visit "/users/sign_in"
|
82
|
+
click_link "Sign in with Facebook"
|
83
|
+
end
|
84
|
+
|
85
|
+
assert session["devise.facebook_data"]
|
86
|
+
user = sign_in_as_user
|
87
|
+
assert !session["devise.facebook_data"]
|
88
|
+
end
|
89
|
+
|
90
|
+
test "handles callback error parameter according to the specification" do
|
91
|
+
visit "/users/auth/facebook/callback?error=access_denied"
|
92
|
+
assert_current_url "/users/sign_in"
|
93
|
+
assert_contain 'Could not authorize you from Facebook because "Access denied".'
|
94
|
+
end
|
95
|
+
|
96
|
+
test "handles other exceptions from omniauth" do
|
97
|
+
Devise::OmniAuth.stub!(:facebook) do |b|
|
98
|
+
b.post('/oauth/access_token') { [401, {}, {}.to_json] }
|
99
|
+
end
|
100
|
+
|
101
|
+
visit "/users/sign_in"
|
102
|
+
click_link "Sign in with facebook"
|
103
|
+
|
104
|
+
assert_current_url "/users/sign_in"
|
105
|
+
assert_contain 'Could not authorize you from Facebook because "Invalid credentials".'
|
106
|
+
end
|
107
|
+
end
|
@@ -9,9 +9,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
9
9
|
|
10
10
|
def request_forgot_password(&block)
|
11
11
|
visit_new_password_path
|
12
|
-
|
13
12
|
assert_response :success
|
14
|
-
assert_template 'passwords/new'
|
15
13
|
assert_not warden.authenticated?(:user)
|
16
14
|
|
17
15
|
fill_in 'email', :with => 'user@test.com'
|
@@ -19,19 +17,42 @@ class PasswordTest < ActionController::IntegrationTest
|
|
19
17
|
click_button 'Send me reset password instructions'
|
20
18
|
end
|
21
19
|
|
22
|
-
def reset_password(options={}, &block)
|
23
|
-
unless options[:visit] == false
|
24
|
-
visit edit_user_password_path(:reset_password_token => options[:reset_password_token])
|
25
|
-
end
|
20
|
+
def reset_password(options={}, &block)
|
21
|
+
visit edit_user_password_path(:reset_password_token => options[:reset_password_token]) unless options[:visit] == false
|
26
22
|
assert_response :success
|
27
|
-
assert_template 'passwords/edit'
|
28
23
|
|
29
|
-
fill_in '
|
30
|
-
fill_in '
|
24
|
+
fill_in 'New password', :with => '987654321'
|
25
|
+
fill_in 'Confirm new password', :with => '987654321'
|
31
26
|
yield if block_given?
|
32
27
|
click_button 'Change my password'
|
33
28
|
end
|
34
29
|
|
30
|
+
test 'reset password with email of different case should succeed when email is in the list of case insensitive keys' do
|
31
|
+
create_user(:email => 'Foo@Bar.com')
|
32
|
+
|
33
|
+
request_forgot_password do
|
34
|
+
fill_in 'email', :with => 'foo@bar.com'
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_current_url '/users/sign_in'
|
38
|
+
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do
|
42
|
+
swap Devise, :case_insensitive_keys => [] do
|
43
|
+
create_user(:email => 'Foo@Bar.com')
|
44
|
+
|
45
|
+
request_forgot_password do
|
46
|
+
fill_in 'email', :with => 'foo@bar.com'
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_response :success
|
50
|
+
assert_current_url '/users/password'
|
51
|
+
assert_have_selector "input[type=email][value='foo@bar.com']"
|
52
|
+
assert_contain 'not found'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
35
56
|
test 'authenticated user should not be able to visit forgot password page' do
|
36
57
|
sign_in_as_user
|
37
58
|
assert warden.authenticated?(:user)
|
@@ -46,7 +67,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
46
67
|
create_user
|
47
68
|
request_forgot_password
|
48
69
|
|
49
|
-
|
70
|
+
assert_current_url '/users/sign_in'
|
50
71
|
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
51
72
|
end
|
52
73
|
|
@@ -56,16 +77,14 @@ class PasswordTest < ActionController::IntegrationTest
|
|
56
77
|
end
|
57
78
|
|
58
79
|
assert_response :success
|
59
|
-
|
60
|
-
assert_have_selector
|
61
|
-
assert_contain '
|
80
|
+
assert_current_url '/users/password'
|
81
|
+
assert_have_selector "input[type=email][value='invalid.test@test.com']"
|
82
|
+
assert_contain 'not found'
|
62
83
|
end
|
63
84
|
|
64
85
|
test 'authenticated user should not be able to visit edit password page' do
|
65
86
|
sign_in_as_user
|
66
|
-
|
67
87
|
get edit_user_password_path
|
68
|
-
|
69
88
|
assert_response :redirect
|
70
89
|
assert_redirected_to root_path
|
71
90
|
assert warden.authenticated?(:user)
|
@@ -76,7 +95,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
76
95
|
reset_password :reset_password_token => 'invalid_reset_password'
|
77
96
|
|
78
97
|
assert_response :success
|
79
|
-
|
98
|
+
assert_current_url '/users/password'
|
80
99
|
assert_have_selector '#error_explanation'
|
81
100
|
assert_contain /Reset password token(.*)invalid/
|
82
101
|
assert_not user.reload.valid_password?('987654321')
|
@@ -86,11 +105,11 @@ class PasswordTest < ActionController::IntegrationTest
|
|
86
105
|
user = create_user
|
87
106
|
request_forgot_password
|
88
107
|
reset_password :reset_password_token => user.reload.reset_password_token do
|
89
|
-
fill_in '
|
108
|
+
fill_in 'Confirm new password', :with => 'other_password'
|
90
109
|
end
|
91
110
|
|
92
111
|
assert_response :success
|
93
|
-
|
112
|
+
assert_current_url '/users/password'
|
94
113
|
assert_have_selector '#error_explanation'
|
95
114
|
assert_contain 'Password doesn\'t match confirmation'
|
96
115
|
assert_not user.reload.valid_password?('987654321')
|
@@ -101,7 +120,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
101
120
|
request_forgot_password
|
102
121
|
reset_password :reset_password_token => user.reload.reset_password_token
|
103
122
|
|
104
|
-
|
123
|
+
assert_current_url '/'
|
105
124
|
assert_contain 'Your password was changed successfully.'
|
106
125
|
assert user.reload.valid_password?('987654321')
|
107
126
|
end
|
@@ -110,7 +129,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
110
129
|
user = create_user
|
111
130
|
request_forgot_password
|
112
131
|
reset_password :reset_password_token => user.reload.reset_password_token do
|
113
|
-
fill_in '
|
132
|
+
fill_in 'Confirm new password', :with => 'other_password'
|
114
133
|
end
|
115
134
|
assert_response :success
|
116
135
|
assert_have_selector '#error_explanation'
|
@@ -13,7 +13,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
13
13
|
fill_in 'password confirmation', :with => 'new_user123'
|
14
14
|
click_button 'Sign up'
|
15
15
|
|
16
|
-
assert_contain 'You have signed up successfully.'
|
16
|
+
assert_contain 'Welcome! You have signed up successfully.'
|
17
17
|
assert warden.authenticated?(:admin)
|
18
18
|
|
19
19
|
admin = Admin.last :order => "id"
|
@@ -28,8 +28,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
28
28
|
fill_in 'password confirmation', :with => 'new_user123'
|
29
29
|
click_button 'Sign up'
|
30
30
|
|
31
|
-
assert_contain 'You have signed up successfully'
|
32
|
-
assert_contain 'Sign in'
|
31
|
+
assert_contain 'You have signed up successfully. However, we could not sign you in because your account is unconfirmed.'
|
33
32
|
assert_not_contain 'You have to confirm your account before continuing'
|
34
33
|
|
35
34
|
assert_not warden.authenticated?(:user)
|
@@ -51,6 +50,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
51
50
|
assert_have_selector '#error_explanation'
|
52
51
|
assert_contain "Email is invalid"
|
53
52
|
assert_contain "Password doesn't match confirmation"
|
53
|
+
assert_contain "2 errors prohibited"
|
54
54
|
assert_nil User.first
|
55
55
|
|
56
56
|
assert_not warden.authenticated?(:user)
|
@@ -66,7 +66,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
66
66
|
click_button 'Sign up'
|
67
67
|
|
68
68
|
assert_current_url '/users'
|
69
|
-
assert_contain(/Email
|
69
|
+
assert_contain(/Email.*already.*taken/)
|
70
70
|
|
71
71
|
assert_not warden.authenticated?(:user)
|
72
72
|
end
|
@@ -98,6 +98,20 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
98
98
|
assert_equal "user.new@email.com", User.first.email
|
99
99
|
end
|
100
100
|
|
101
|
+
test 'a signed in user should still be able to use the website after changing his password' do
|
102
|
+
sign_in_as_user
|
103
|
+
get edit_user_registration_path
|
104
|
+
|
105
|
+
fill_in 'password', :with => '12345678'
|
106
|
+
fill_in 'password confirmation', :with => '12345678'
|
107
|
+
fill_in 'current password', :with => '123456'
|
108
|
+
click_button 'Update'
|
109
|
+
|
110
|
+
assert_contain 'You updated your account successfully.'
|
111
|
+
get users_path
|
112
|
+
assert warden.authenticated?(:user)
|
113
|
+
end
|
114
|
+
|
101
115
|
test 'a signed in user should not change his current user with invalid password' do
|
102
116
|
sign_in_as_user
|
103
117
|
get edit_user_registration_path
|
@@ -150,4 +164,16 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
150
164
|
|
151
165
|
assert User.all.empty?
|
152
166
|
end
|
167
|
+
|
168
|
+
test 'a user should be able to cancel sign up by deleting data in the session' do
|
169
|
+
get "/set"
|
170
|
+
assert_equal "something", @request.session["devise.foo_bar"]
|
171
|
+
|
172
|
+
get "/users/sign_up"
|
173
|
+
assert_equal "something", @request.session["devise.foo_bar"]
|
174
|
+
|
175
|
+
get "/users/cancel"
|
176
|
+
assert_nil @request.session["devise.foo_bar"]
|
177
|
+
assert_redirected_to new_user_registration_path
|
178
|
+
end
|
153
179
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class RememberMeTest < ActionController::IntegrationTest
|
4
|
-
|
5
4
|
def create_user_and_remember(add_to_token='')
|
6
5
|
user = create_user
|
7
6
|
user.remember_me!
|
@@ -10,6 +9,14 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
10
9
|
user
|
11
10
|
end
|
12
11
|
|
12
|
+
def create_admin_and_remember
|
13
|
+
admin = create_admin
|
14
|
+
admin.remember_me!
|
15
|
+
raw_cookie = Admin.serialize_into_cookie(admin)
|
16
|
+
cookies['remember_admin_token'] = generate_signed_cookie(raw_cookie)
|
17
|
+
admin
|
18
|
+
end
|
19
|
+
|
13
20
|
def generate_signed_cookie(raw_cookie)
|
14
21
|
request = ActionDispatch::TestRequest.new
|
15
22
|
request.cookie_jar.signed['raw_cookie'] = raw_cookie
|
@@ -29,32 +36,30 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
29
36
|
test 'do not remember the user if he has not checked remember me option' do
|
30
37
|
user = sign_in_as_user
|
31
38
|
assert_nil request.cookies["remember_user_cookie"]
|
32
|
-
assert_nil user.reload.remember_token
|
33
39
|
end
|
34
40
|
|
35
41
|
test 'generate remember token after sign in' do
|
36
42
|
user = sign_in_as_user :remember_me => true
|
37
43
|
assert request.cookies["remember_user_token"]
|
38
|
-
assert user.reload.remember_token
|
39
44
|
end
|
40
45
|
|
41
|
-
test 'generate remember token after sign in setting cookie
|
46
|
+
test 'generate remember token after sign in setting cookie options' do
|
42
47
|
# We test this by asserting the cookie is not sent after the redirect
|
43
48
|
# since we changed the domain. This is the only difference with the
|
44
49
|
# previous test.
|
45
|
-
swap
|
50
|
+
swap Devise, :cookie_options => { :domain => "omg.somewhere.com" } do
|
46
51
|
user = sign_in_as_user :remember_me => true
|
47
52
|
assert_nil request.cookies["remember_user_token"]
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
test '
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
test 'generate remember token after sign in setting session options' do
|
57
|
+
begin
|
58
|
+
Rails.configuration.session_options[:domain] = "omg.somewhere.com"
|
59
|
+
user = sign_in_as_user :remember_me => true
|
60
|
+
assert_nil request.cookies["remember_user_token"]
|
61
|
+
ensure
|
62
|
+
Rails.configuration.session_options.delete(:domain)
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
@@ -84,29 +89,29 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
84
89
|
|
85
90
|
test 'if both extend_remember_period and remember_across_browsers are true, sends the same token with a new expire date' do
|
86
91
|
swap Devise, :remember_across_browsers => true, :extend_remember_period => true, :remember_for => 1.year do
|
87
|
-
|
88
|
-
token =
|
92
|
+
admin = create_admin_and_remember
|
93
|
+
token = admin.remember_token
|
89
94
|
|
90
|
-
|
91
|
-
|
95
|
+
admin.remember_created_at = old = 10.minutes.ago
|
96
|
+
admin.save!
|
92
97
|
|
93
|
-
get
|
94
|
-
assert (cookie_expires("
|
95
|
-
assert_equal token, signed_cookie("
|
98
|
+
get root_path
|
99
|
+
assert (cookie_expires("remember_admin_token") - 1.year) > (old + 5.minutes)
|
100
|
+
assert_equal token, signed_cookie("remember_admin_token").last
|
96
101
|
end
|
97
102
|
end
|
98
103
|
|
99
104
|
test 'if both extend_remember_period and remember_across_browsers are false, sends a new token with old expire date' do
|
100
105
|
swap Devise, :remember_across_browsers => false, :extend_remember_period => false, :remember_for => 1.year do
|
101
|
-
|
102
|
-
token =
|
106
|
+
admin = create_admin_and_remember
|
107
|
+
token = admin.remember_token
|
103
108
|
|
104
|
-
|
105
|
-
|
109
|
+
admin.remember_created_at = old = 10.minutes.ago
|
110
|
+
admin.save!
|
106
111
|
|
107
|
-
get
|
108
|
-
assert (cookie_expires("
|
109
|
-
assert_not_equal token, signed_cookie("
|
112
|
+
get root_path
|
113
|
+
assert (cookie_expires("remember_admin_token") - 1.year) < (old + 5.minutes)
|
114
|
+
assert_not_equal token, signed_cookie("remember_admin_token").last
|
110
115
|
end
|
111
116
|
end
|
112
117
|
|
@@ -134,23 +139,41 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
134
139
|
end
|
135
140
|
end
|
136
141
|
|
137
|
-
test '
|
142
|
+
test 'do not remember the user anymore after forget' do
|
138
143
|
user = create_user_and_remember
|
139
144
|
get users_path
|
140
145
|
assert warden.authenticated?(:user)
|
146
|
+
|
141
147
|
get destroy_user_session_path
|
142
148
|
assert_not warden.authenticated?(:user)
|
143
|
-
assert_nil
|
149
|
+
assert_nil warden.cookies['remember_user_token']
|
150
|
+
|
151
|
+
get users_path
|
152
|
+
assert_not warden.authenticated?(:user)
|
144
153
|
assert_nil warden.cookies['remember_user_token']
|
145
154
|
end
|
146
155
|
|
147
|
-
test 'do not remember the
|
156
|
+
test 'do not remember the admin anymore after forget' do
|
157
|
+
admin = create_admin_and_remember
|
158
|
+
get root_path
|
159
|
+
assert warden.authenticated?(:admin)
|
160
|
+
|
161
|
+
get destroy_admin_session_path
|
162
|
+
assert_not warden.authenticated?(:admin)
|
163
|
+
assert_nil warden.cookies['remember_admin_token']
|
164
|
+
|
165
|
+
get root_path
|
166
|
+
assert_not warden.authenticated?(:admin)
|
167
|
+
assert_nil warden.cookies['remember_admin_token']
|
168
|
+
end
|
169
|
+
|
170
|
+
test 'changing user password expires remember me token' do
|
148
171
|
user = create_user_and_remember
|
149
|
-
|
150
|
-
|
151
|
-
|
172
|
+
user.password = "another_password"
|
173
|
+
user.password_confirmation = "another_password"
|
174
|
+
user.save!
|
175
|
+
|
152
176
|
get users_path
|
153
177
|
assert_not warden.authenticated?(:user)
|
154
|
-
assert_nil warden.cookies['remember_user_token']
|
155
178
|
end
|
156
|
-
end
|
179
|
+
end
|