devise-edge 1.2.rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +500 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +335 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/oauth_callbacks_controller.rb +4 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +75 -0
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +88 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +42 -0
- data/lib/devise.rb +371 -0
- data/lib/devise/controllers/helpers.rb +261 -0
- data/lib/devise/controllers/internal_helpers.rb +113 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/url_helpers.rb +39 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +126 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +45 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +105 -0
- data/lib/devise/models.rb +66 -0
- data/lib/devise/models/authenticatable.rb +143 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +94 -0
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +168 -0
- data/lib/devise/models/oauthable.rb +49 -0
- data/lib/devise/models/recoverable.rb +83 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +122 -0
- data/lib/devise/models/timeoutable.rb +33 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +60 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/oauth.rb +41 -0
- data/lib/devise/oauth/config.rb +33 -0
- data/lib/devise/oauth/helpers.rb +18 -0
- data/lib/devise/oauth/internal_helpers.rb +182 -0
- data/lib/devise/oauth/test_helpers.rb +29 -0
- data/lib/devise/oauth/url_helpers.rb +35 -0
- data/lib/devise/orm/active_record.rb +36 -0
- data/lib/devise/orm/mongo_mapper.rb +46 -0
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails.rb +67 -0
- data/lib/devise/rails/routes.rb +260 -0
- data/lib/devise/rails/warden_compat.rb +42 -0
- data/lib/devise/schema.rb +96 -0
- data/lib/devise/strategies/authenticatable.rb +150 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +51 -0
- data/lib/devise/strategies/token_authenticatable.rb +53 -0
- data/lib/devise/test_helpers.rb +100 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +30 -0
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +24 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +168 -0
- data/test/controllers/helpers_test.rb +220 -0
- data/test/controllers/internal_helpers_test.rb +56 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/devise_test.rb +65 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +148 -0
- data/test/integration/authenticatable_test.rb +424 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +64 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/oauthable_test.rb +258 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +179 -0
- data/test/integration/timeoutable_test.rb +80 -0
- data/test/integration/token_authenticatable_test.rb +99 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +84 -0
- data/test/mailers/reset_password_instructions_test.rb +72 -0
- data/test/mailers/unlock_instructions_test.rb +66 -0
- data/test/mapping_test.rb +95 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +82 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/oauthable_test.rb +21 -0
- data/test/models/recoverable_test.rb +155 -0
- data/test/models/rememberable_test.rb +271 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +37 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +77 -0
- data/test/oauth/config_test.rb +44 -0
- data/test/oauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +12 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/users_controller.rb +18 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +13 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +172 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +54 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +48 -0
- data/test/routes_test.rb +189 -0
- data/test/support/assertions.rb +24 -0
- data/test/support/helpers.rb +60 -0
- data/test/support/integration.rb +88 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +23 -0
- data/test/test_helpers_test.rb +101 -0
- metadata +335 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class PasswordTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
def visit_new_password_path
|
|
6
|
+
visit new_user_session_path
|
|
7
|
+
click_link 'Forgot your password?'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def request_forgot_password(&block)
|
|
11
|
+
visit_new_password_path
|
|
12
|
+
|
|
13
|
+
assert_response :success
|
|
14
|
+
assert_template 'passwords/new'
|
|
15
|
+
assert_not warden.authenticated?(:user)
|
|
16
|
+
|
|
17
|
+
fill_in 'email', :with => 'user@test.com'
|
|
18
|
+
yield if block_given?
|
|
19
|
+
click_button 'Send me reset password instructions'
|
|
20
|
+
end
|
|
21
|
+
|
|
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
|
|
26
|
+
assert_response :success
|
|
27
|
+
assert_template 'passwords/edit'
|
|
28
|
+
|
|
29
|
+
fill_in 'Password', :with => '987654321'
|
|
30
|
+
fill_in 'Password confirmation', :with => '987654321'
|
|
31
|
+
yield if block_given?
|
|
32
|
+
click_button 'Change my password'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
test 'authenticated user should not be able to visit forgot password page' do
|
|
36
|
+
sign_in_as_user
|
|
37
|
+
assert warden.authenticated?(:user)
|
|
38
|
+
|
|
39
|
+
get new_user_password_path
|
|
40
|
+
|
|
41
|
+
assert_response :redirect
|
|
42
|
+
assert_redirected_to root_path
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test 'not authenticated user should be able to request a forgot password' do
|
|
46
|
+
create_user
|
|
47
|
+
request_forgot_password
|
|
48
|
+
|
|
49
|
+
assert_template 'sessions/new'
|
|
50
|
+
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test 'not authenticated user with invalid email should receive an error message' do
|
|
54
|
+
request_forgot_password do
|
|
55
|
+
fill_in 'email', :with => 'invalid.test@test.com'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
assert_response :success
|
|
59
|
+
assert_template 'passwords/new'
|
|
60
|
+
assert_have_selector 'input[type=text][value=\'invalid.test@test.com\']'
|
|
61
|
+
assert_contain 'not found'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
test 'authenticated user should not be able to visit edit password page' do
|
|
65
|
+
sign_in_as_user
|
|
66
|
+
|
|
67
|
+
get edit_user_password_path
|
|
68
|
+
|
|
69
|
+
assert_response :redirect
|
|
70
|
+
assert_redirected_to root_path
|
|
71
|
+
assert warden.authenticated?(:user)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
test 'not authenticated user with invalid reset password token should not be able to change his password' do
|
|
75
|
+
user = create_user
|
|
76
|
+
reset_password :reset_password_token => 'invalid_reset_password'
|
|
77
|
+
|
|
78
|
+
assert_response :success
|
|
79
|
+
assert_template 'passwords/edit'
|
|
80
|
+
assert_have_selector '#error_explanation'
|
|
81
|
+
assert_contain /Reset password token(.*)invalid/
|
|
82
|
+
assert_not user.reload.valid_password?('987654321')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
test 'not authenticated user with valid reset password token but invalid password should not be able to change his password' do
|
|
86
|
+
user = create_user
|
|
87
|
+
request_forgot_password
|
|
88
|
+
reset_password :reset_password_token => user.reload.reset_password_token do
|
|
89
|
+
fill_in 'Password confirmation', :with => 'other_password'
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
assert_response :success
|
|
93
|
+
assert_template 'passwords/edit'
|
|
94
|
+
assert_have_selector '#error_explanation'
|
|
95
|
+
assert_contain 'Password doesn\'t match confirmation'
|
|
96
|
+
assert_not user.reload.valid_password?('987654321')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
test 'not authenticated user with valid data should be able to change his password' do
|
|
100
|
+
user = create_user
|
|
101
|
+
request_forgot_password
|
|
102
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
|
103
|
+
|
|
104
|
+
assert_template 'home/index'
|
|
105
|
+
assert_contain 'Your password was changed successfully.'
|
|
106
|
+
assert user.reload.valid_password?('987654321')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
test 'after entering invalid data user should still be able to change his password' do
|
|
110
|
+
user = create_user
|
|
111
|
+
request_forgot_password
|
|
112
|
+
reset_password :reset_password_token => user.reload.reset_password_token do
|
|
113
|
+
fill_in 'Password confirmation', :with => 'other_password'
|
|
114
|
+
end
|
|
115
|
+
assert_response :success
|
|
116
|
+
assert_have_selector '#error_explanation'
|
|
117
|
+
assert_not user.reload.valid_password?('987654321')
|
|
118
|
+
|
|
119
|
+
reset_password :reset_password_token => user.reload.reset_password_token, :visit => false
|
|
120
|
+
assert_contain 'Your password was changed successfully.'
|
|
121
|
+
assert user.reload.valid_password?('987654321')
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
test 'sign in user automatically after changing it\'s password' do
|
|
125
|
+
user = create_user
|
|
126
|
+
request_forgot_password
|
|
127
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
|
128
|
+
|
|
129
|
+
assert warden.authenticated?(:user)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
test 'does not sign in user automatically after changing it\'s password if it\'s not active' do
|
|
133
|
+
user = create_user(:confirm => false)
|
|
134
|
+
request_forgot_password
|
|
135
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
|
136
|
+
|
|
137
|
+
assert_equal new_user_session_path, @request.path
|
|
138
|
+
assert !warden.authenticated?(:user)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RegistrationTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
test 'a guest admin should be able to sign in successfully' do
|
|
6
|
+
get new_admin_session_path
|
|
7
|
+
click_link 'Sign up'
|
|
8
|
+
|
|
9
|
+
assert_template 'registrations/new'
|
|
10
|
+
|
|
11
|
+
fill_in 'email', :with => 'new_user@test.com'
|
|
12
|
+
fill_in 'password', :with => 'new_user123'
|
|
13
|
+
fill_in 'password confirmation', :with => 'new_user123'
|
|
14
|
+
click_button 'Sign up'
|
|
15
|
+
|
|
16
|
+
assert_contain 'You have signed up successfully.'
|
|
17
|
+
assert warden.authenticated?(:admin)
|
|
18
|
+
|
|
19
|
+
admin = Admin.last :order => "id"
|
|
20
|
+
assert_equal admin.email, 'new_user@test.com'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
|
|
24
|
+
get new_user_registration_path
|
|
25
|
+
|
|
26
|
+
fill_in 'email', :with => 'new_user@test.com'
|
|
27
|
+
fill_in 'password', :with => 'new_user123'
|
|
28
|
+
fill_in 'password confirmation', :with => 'new_user123'
|
|
29
|
+
click_button 'Sign up'
|
|
30
|
+
|
|
31
|
+
assert_contain 'You have signed up successfully'
|
|
32
|
+
assert_contain 'Sign in'
|
|
33
|
+
assert_not_contain 'You have to confirm your account before continuing'
|
|
34
|
+
|
|
35
|
+
assert_not warden.authenticated?(:user)
|
|
36
|
+
|
|
37
|
+
user = User.last :order => "id"
|
|
38
|
+
assert_equal user.email, 'new_user@test.com'
|
|
39
|
+
assert_not user.confirmed?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'a guest user cannot sign up with invalid information' do
|
|
43
|
+
get new_user_registration_path
|
|
44
|
+
|
|
45
|
+
fill_in 'email', :with => 'invalid_email'
|
|
46
|
+
fill_in 'password', :with => 'new_user123'
|
|
47
|
+
fill_in 'password confirmation', :with => 'new_user321'
|
|
48
|
+
click_button 'Sign up'
|
|
49
|
+
|
|
50
|
+
assert_template 'registrations/new'
|
|
51
|
+
assert_have_selector '#error_explanation'
|
|
52
|
+
assert_contain "Email is invalid"
|
|
53
|
+
assert_contain "Password doesn't match confirmation"
|
|
54
|
+
assert_nil User.first
|
|
55
|
+
|
|
56
|
+
assert_not warden.authenticated?(:user)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
test 'a guest should not sign up with email/password that already exists' do
|
|
60
|
+
user = create_user
|
|
61
|
+
get new_user_registration_path
|
|
62
|
+
|
|
63
|
+
fill_in 'email', :with => 'user@test.com'
|
|
64
|
+
fill_in 'password', :with => '123456'
|
|
65
|
+
fill_in 'password confirmation', :with => '123456'
|
|
66
|
+
click_button 'Sign up'
|
|
67
|
+
|
|
68
|
+
assert_current_url '/users'
|
|
69
|
+
assert_contain(/Email.*already.*taken/)
|
|
70
|
+
|
|
71
|
+
assert_not warden.authenticated?(:user)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
test 'a guest should not be able to change account' do
|
|
75
|
+
get edit_user_registration_path
|
|
76
|
+
assert_redirected_to new_user_session_path
|
|
77
|
+
follow_redirect!
|
|
78
|
+
assert_contain 'You need to sign in or sign up before continuing.'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test 'a signed in user should not be able to access sign up' do
|
|
82
|
+
sign_in_as_user
|
|
83
|
+
get new_user_registration_path
|
|
84
|
+
assert_redirected_to root_path
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
test 'a signed in user should be able to edit his account' do
|
|
88
|
+
sign_in_as_user
|
|
89
|
+
get edit_user_registration_path
|
|
90
|
+
|
|
91
|
+
fill_in 'email', :with => 'user.new@email.com'
|
|
92
|
+
fill_in 'current password', :with => '123456'
|
|
93
|
+
click_button 'Update'
|
|
94
|
+
|
|
95
|
+
assert_current_url '/'
|
|
96
|
+
assert_contain 'You updated your account successfully.'
|
|
97
|
+
|
|
98
|
+
assert_equal "user.new@email.com", User.first.email
|
|
99
|
+
end
|
|
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
|
+
|
|
115
|
+
test 'a signed in user should not change his current user with invalid password' do
|
|
116
|
+
sign_in_as_user
|
|
117
|
+
get edit_user_registration_path
|
|
118
|
+
|
|
119
|
+
fill_in 'email', :with => 'user.new@email.com'
|
|
120
|
+
fill_in 'current password', :with => 'invalid'
|
|
121
|
+
click_button 'Update'
|
|
122
|
+
|
|
123
|
+
assert_template 'registrations/edit'
|
|
124
|
+
assert_contain 'user@test.com'
|
|
125
|
+
assert_have_selector 'form input[value="user.new@email.com"]'
|
|
126
|
+
|
|
127
|
+
assert_equal "user@test.com", User.first.email
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
test 'a signed in user should be able to edit his password' do
|
|
131
|
+
sign_in_as_user
|
|
132
|
+
get edit_user_registration_path
|
|
133
|
+
|
|
134
|
+
fill_in 'password', :with => 'pas123'
|
|
135
|
+
fill_in 'password confirmation', :with => 'pas123'
|
|
136
|
+
fill_in 'current password', :with => '123456'
|
|
137
|
+
click_button 'Update'
|
|
138
|
+
|
|
139
|
+
assert_current_url '/'
|
|
140
|
+
assert_contain 'You updated your account successfully.'
|
|
141
|
+
|
|
142
|
+
assert User.first.valid_password?('pas123')
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
test 'a signed in user should not be able to edit his password with invalid confirmation' do
|
|
146
|
+
sign_in_as_user
|
|
147
|
+
get edit_user_registration_path
|
|
148
|
+
|
|
149
|
+
fill_in 'password', :with => 'pas123'
|
|
150
|
+
fill_in 'password confirmation', :with => ''
|
|
151
|
+
fill_in 'current password', :with => '123456'
|
|
152
|
+
click_button 'Update'
|
|
153
|
+
|
|
154
|
+
assert_contain "Password doesn't match confirmation"
|
|
155
|
+
assert_not User.first.valid_password?('pas123')
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
test 'a signed in user should be able to cancel his account' do
|
|
159
|
+
sign_in_as_user
|
|
160
|
+
get edit_user_registration_path
|
|
161
|
+
|
|
162
|
+
click_link "Cancel my account", :method => :delete
|
|
163
|
+
assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
|
|
164
|
+
|
|
165
|
+
assert User.all.empty?
|
|
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["user_provider_oauth_token"]
|
|
171
|
+
|
|
172
|
+
get "/users/sign_up"
|
|
173
|
+
assert_equal "something", @request.session["user_provider_oauth_token"]
|
|
174
|
+
|
|
175
|
+
get "/users/cancel"
|
|
176
|
+
assert_nil @request.session["user_provider_oauth_token"]
|
|
177
|
+
assert_redirected_to new_user_registration_path
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RememberMeTest < ActionController::IntegrationTest
|
|
4
|
+
def create_user_and_remember(add_to_token='')
|
|
5
|
+
user = create_user
|
|
6
|
+
user.remember_me!
|
|
7
|
+
raw_cookie = User.serialize_into_cookie(user).tap { |a| a.last << add_to_token }
|
|
8
|
+
cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)
|
|
9
|
+
user
|
|
10
|
+
end
|
|
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
|
+
|
|
20
|
+
def generate_signed_cookie(raw_cookie)
|
|
21
|
+
request = ActionDispatch::TestRequest.new
|
|
22
|
+
request.cookie_jar.signed['raw_cookie'] = raw_cookie
|
|
23
|
+
request.cookie_jar['raw_cookie']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def signed_cookie(key)
|
|
27
|
+
controller.send(:cookies).signed[key]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def cookie_expires(key)
|
|
31
|
+
cookie = response.headers["Set-Cookie"].split("\n").grep(/^#{key}/).first
|
|
32
|
+
cookie.split(";").map(&:strip).grep(/^expires=/)
|
|
33
|
+
Time.parse($')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test 'do not remember the user if he has not checked remember me option' do
|
|
37
|
+
user = sign_in_as_user
|
|
38
|
+
assert_nil request.cookies["remember_user_cookie"]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'generate remember token after sign in' do
|
|
42
|
+
user = sign_in_as_user :remember_me => true
|
|
43
|
+
assert request.cookies["remember_user_token"]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
test 'generate remember token after sign in setting cookie options' do
|
|
47
|
+
# We test this by asserting the cookie is not sent after the redirect
|
|
48
|
+
# since we changed the domain. This is the only difference with the
|
|
49
|
+
# previous test.
|
|
50
|
+
swap Devise, :cookie_options => { :domain => "omg.somewhere.com" } do
|
|
51
|
+
user = sign_in_as_user :remember_me => true
|
|
52
|
+
assert_nil request.cookies["remember_user_token"]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
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)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
test 'remember the user before sign in' do
|
|
67
|
+
user = create_user_and_remember
|
|
68
|
+
get users_path
|
|
69
|
+
assert_response :success
|
|
70
|
+
assert warden.authenticated?(:user)
|
|
71
|
+
assert warden.user(:user) == user
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
test 'does not extend remember period through sign in' do
|
|
75
|
+
swap Devise, :extend_remember_period => true, :remember_for => 1.year do
|
|
76
|
+
user = create_user
|
|
77
|
+
user.remember_me!
|
|
78
|
+
|
|
79
|
+
user.remember_created_at = old = 10.days.ago
|
|
80
|
+
user.save
|
|
81
|
+
|
|
82
|
+
sign_in_as_user :remember_me => true
|
|
83
|
+
user.reload
|
|
84
|
+
|
|
85
|
+
assert warden.user(:user) == user
|
|
86
|
+
assert_equal old.to_i, user.remember_created_at.to_i
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
test 'if both extend_remember_period and remember_across_browsers are true, sends the same token with a new expire date' do
|
|
91
|
+
swap Devise, :remember_across_browsers => true, :extend_remember_period => true, :remember_for => 1.year do
|
|
92
|
+
admin = create_admin_and_remember
|
|
93
|
+
token = admin.remember_token
|
|
94
|
+
|
|
95
|
+
admin.remember_created_at = old = 10.minutes.ago
|
|
96
|
+
admin.save!
|
|
97
|
+
|
|
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
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
test 'if both extend_remember_period and remember_across_browsers are false, sends a new token with old expire date' do
|
|
105
|
+
swap Devise, :remember_across_browsers => false, :extend_remember_period => false, :remember_for => 1.year do
|
|
106
|
+
admin = create_admin_and_remember
|
|
107
|
+
token = admin.remember_token
|
|
108
|
+
|
|
109
|
+
admin.remember_created_at = old = 10.minutes.ago
|
|
110
|
+
admin.save!
|
|
111
|
+
|
|
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
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
test 'do not remember other scopes' do
|
|
119
|
+
user = create_user_and_remember
|
|
120
|
+
get root_path
|
|
121
|
+
assert_response :success
|
|
122
|
+
assert warden.authenticated?(:user)
|
|
123
|
+
assert_not warden.authenticated?(:admin)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
test 'do not remember with invalid token' do
|
|
127
|
+
user = create_user_and_remember('add')
|
|
128
|
+
get users_path
|
|
129
|
+
assert_not warden.authenticated?(:user)
|
|
130
|
+
assert_redirected_to new_user_session_path
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
test 'do not remember with expired token' do
|
|
134
|
+
user = create_user_and_remember
|
|
135
|
+
swap Devise, :remember_for => 0 do
|
|
136
|
+
get users_path
|
|
137
|
+
assert_not warden.authenticated?(:user)
|
|
138
|
+
assert_redirected_to new_user_session_path
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
test 'do not remember the user anymore after forget' do
|
|
143
|
+
user = create_user_and_remember
|
|
144
|
+
get users_path
|
|
145
|
+
assert warden.authenticated?(:user)
|
|
146
|
+
|
|
147
|
+
get destroy_user_session_path
|
|
148
|
+
assert_not warden.authenticated?(:user)
|
|
149
|
+
assert_nil warden.cookies['remember_user_token']
|
|
150
|
+
|
|
151
|
+
get users_path
|
|
152
|
+
assert_not warden.authenticated?(:user)
|
|
153
|
+
assert_nil warden.cookies['remember_user_token']
|
|
154
|
+
end
|
|
155
|
+
|
|
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
|
|
171
|
+
user = create_user_and_remember
|
|
172
|
+
user.password = "another_password"
|
|
173
|
+
user.password_confirmation = "another_password"
|
|
174
|
+
user.save!
|
|
175
|
+
|
|
176
|
+
get users_path
|
|
177
|
+
assert_not warden.authenticated?(:user)
|
|
178
|
+
end
|
|
179
|
+
end
|