loyal_devise 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.rdoc +881 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +388 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +44 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
- data/app/controllers/devise/passwords_controller.rb +57 -0
- data/app/controllers/devise/registrations_controller.rb +120 -0
- data/app/controllers/devise/sessions_controller.rb +51 -0
- data/app/controllers/devise/unlocks_controller.rb +45 -0
- data/app/controllers/devise_controller.rb +193 -0
- data/app/helpers/devise_helper.rb +26 -0
- data/app/mailers/devise/mailer.rb +16 -0
- data/app/views/devise/_links.erb +3 -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 +59 -0
- data/devise.gemspec +26 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise/controllers/helpers.rb +273 -0
- data/lib/devise/controllers/rememberable.rb +53 -0
- data/lib/devise/controllers/scoped_views.rb +18 -0
- data/lib/devise/controllers/url_helpers.rb +68 -0
- data/lib/devise/delegator.rb +17 -0
- data/lib/devise/failure_app.rb +188 -0
- data/lib/devise/hooks/activatable.rb +12 -0
- data/lib/devise/hooks/forgetable.rb +10 -0
- data/lib/devise/hooks/lockable.rb +8 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +26 -0
- data/lib/devise/hooks/trackable.rb +10 -0
- data/lib/devise/mailers/helpers.rb +92 -0
- data/lib/devise/mapping.rb +173 -0
- data/lib/devise/models/authenticatable.rb +269 -0
- data/lib/devise/models/confirmable.rb +271 -0
- data/lib/devise/models/database_authenticatable.rb +127 -0
- data/lib/devise/models/lockable.rb +194 -0
- data/lib/devise/models/omniauthable.rb +28 -0
- data/lib/devise/models/recoverable.rb +141 -0
- data/lib/devise/models/registerable.rb +26 -0
- data/lib/devise/models/rememberable.rb +126 -0
- data/lib/devise/models/timeoutable.rb +50 -0
- data/lib/devise/models/token_authenticatable.rb +90 -0
- data/lib/devise/models/trackable.rb +36 -0
- data/lib/devise/models/validatable.rb +67 -0
- data/lib/devise/models.rb +129 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +46 -0
- data/lib/devise/omniauth/url_helpers.rb +19 -0
- data/lib/devise/omniauth.rb +29 -0
- data/lib/devise/orm/active_record.rb +4 -0
- data/lib/devise/orm/mongoid.rb +4 -0
- data/lib/devise/param_filter.rb +42 -0
- data/lib/devise/rails/routes.rb +447 -0
- data/lib/devise/rails/warden_compat.rb +44 -0
- data/lib/devise/rails.rb +55 -0
- data/lib/devise/strategies/authenticatable.rb +177 -0
- data/lib/devise/strategies/base.rb +21 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +56 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +15 -0
- data/lib/devise/version.rb +4 -0
- data/lib/devise.rb +445 -0
- data/lib/generators/active_record/devise_generator.rb +80 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/active_record/templates/migration_existing.rb +27 -0
- data/lib/generators/devise/devise_generator.rb +25 -0
- data/lib/generators/devise/install_generator.rb +25 -0
- data/lib/generators/devise/orm_helpers.rb +33 -0
- data/lib/generators/devise/views_generator.rb +117 -0
- data/lib/generators/mongoid/devise_generator.rb +58 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +241 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
- data/test/controllers/custom_strategy_test.rb +63 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +111 -0
- data/test/controllers/sessions_controller_test.rb +58 -0
- data/test/controllers/url_helpers_test.rb +60 -0
- data/test/delegator_test.rb +20 -0
- data/test/devise_test.rb +73 -0
- data/test/failure_app_test.rb +222 -0
- data/test/generators/active_record_generator_test.rb +76 -0
- data/test/generators/devise_generator_test.rb +40 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/mongoid_generator_test.rb +24 -0
- data/test/generators/views_generator_test.rb +53 -0
- data/test/helpers/devise_helper_test.rb +52 -0
- data/test/indifferent_hash.rb +34 -0
- data/test/integration/authenticatable_test.rb +634 -0
- data/test/integration/confirmable_test.rb +299 -0
- data/test/integration/database_authenticatable_test.rb +83 -0
- data/test/integration/http_authenticatable_test.rb +98 -0
- data/test/integration/lockable_test.rb +243 -0
- data/test/integration/omniauthable_test.rb +134 -0
- data/test/integration/recoverable_test.rb +307 -0
- data/test/integration/registerable_test.rb +346 -0
- data/test/integration/rememberable_test.rb +159 -0
- data/test/integration/timeoutable_test.rb +141 -0
- data/test/integration/token_authenticatable_test.rb +162 -0
- data/test/integration/trackable_test.rb +93 -0
- data/test/mailers/confirmation_instructions_test.rb +103 -0
- data/test/mailers/reset_password_instructions_test.rb +84 -0
- data/test/mailers/unlock_instructions_test.rb +78 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/authenticatable_test.rb +8 -0
- data/test/models/confirmable_test.rb +392 -0
- data/test/models/database_authenticatable_test.rb +190 -0
- data/test/models/lockable_test.rb +274 -0
- data/test/models/omniauthable_test.rb +8 -0
- data/test/models/recoverable_test.rb +206 -0
- data/test/models/registerable_test.rb +8 -0
- data/test/models/rememberable_test.rb +175 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +47 -0
- data/test/models/token_authenticatable_test.rb +56 -0
- data/test/models/trackable_test.rb +14 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +180 -0
- data/test/omniauth/config_test.rb +58 -0
- data/test/omniauth/url_helpers_test.rb +52 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +15 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/shim.rb +3 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +12 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +26 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
- data/test/rails_app/app/controllers/users_controller.rb +24 -0
- data/test/rails_app/app/helpers/application_helper.rb +4 -0
- data/test/rails_app/app/mailers/users/mailer.rb +9 -0
- data/test/rails_app/app/mongoid/admin.rb +28 -0
- data/test/rails_app/app/mongoid/shim.rb +25 -0
- data/test/rails_app/app/mongoid/user.rb +43 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +42 -0
- data/test/rails_app/config/boot.rb +9 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +34 -0
- data/test/rails_app/config/environments/test.rb +34 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/devise.rb +179 -0
- data/test/rails_app/config/initializers/inflections.rb +3 -0
- data/test/rails_app/config/initializers/secret_token.rb +3 -0
- data/test/rails_app/config/routes.rb +101 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
- data/test/rails_app/db/schema.rb +53 -0
- data/test/rails_app/lib/shared_admin.rb +15 -0
- data/test/rails_app/lib/shared_user.rb +27 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +249 -0
- data/test/support/assertions.rb +41 -0
- data/test/support/helpers.rb +92 -0
- data/test/support/integration.rb +93 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +25 -0
- data/test/test_helper.rb +28 -0
- data/test/test_helpers_test.rb +152 -0
- metadata +407 -0
@@ -0,0 +1,634 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class AuthenticationSanityTest < ActionController::IntegrationTest
|
5
|
+
test 'home should be accessible without sign in' do
|
6
|
+
visit '/'
|
7
|
+
assert_response :success
|
8
|
+
assert_template 'home/index'
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'sign in as user should not authenticate admin scope' do
|
12
|
+
sign_in_as_user
|
13
|
+
assert warden.authenticated?(:user)
|
14
|
+
assert_not warden.authenticated?(:admin)
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'sign in as admin should not authenticate user scope' do
|
18
|
+
sign_in_as_admin
|
19
|
+
assert warden.authenticated?(:admin)
|
20
|
+
assert_not warden.authenticated?(:user)
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'sign in as both user and admin at same time' do
|
24
|
+
sign_in_as_user
|
25
|
+
sign_in_as_admin
|
26
|
+
assert warden.authenticated?(:user)
|
27
|
+
assert warden.authenticated?(:admin)
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
|
31
|
+
swap Devise, :sign_out_all_scopes => false do
|
32
|
+
sign_in_as_user
|
33
|
+
sign_in_as_admin
|
34
|
+
get destroy_user_session_path
|
35
|
+
assert_not warden.authenticated?(:user)
|
36
|
+
assert warden.authenticated?(:admin)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
|
41
|
+
swap Devise, :sign_out_all_scopes => false do
|
42
|
+
sign_in_as_user
|
43
|
+
sign_in_as_admin
|
44
|
+
|
45
|
+
get destroy_admin_session_path
|
46
|
+
assert_not warden.authenticated?(:admin)
|
47
|
+
assert warden.authenticated?(:user)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
|
52
|
+
swap Devise, :sign_out_all_scopes => true do
|
53
|
+
sign_in_as_user
|
54
|
+
sign_in_as_admin
|
55
|
+
|
56
|
+
get destroy_user_session_path
|
57
|
+
assert_not warden.authenticated?(:user)
|
58
|
+
assert_not warden.authenticated?(:admin)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
|
63
|
+
swap Devise, :sign_out_all_scopes => true do
|
64
|
+
sign_in_as_user
|
65
|
+
sign_in_as_admin
|
66
|
+
|
67
|
+
get destroy_admin_session_path
|
68
|
+
assert_not warden.authenticated?(:admin)
|
69
|
+
assert_not warden.authenticated?(:user)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'not signed in as admin should not be able to access admins actions' do
|
74
|
+
get admins_path
|
75
|
+
assert_redirected_to new_admin_session_path
|
76
|
+
assert_not warden.authenticated?(:admin)
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'signed in as user should not be able to access admins actions' do
|
80
|
+
sign_in_as_user
|
81
|
+
assert warden.authenticated?(:user)
|
82
|
+
assert_not warden.authenticated?(:admin)
|
83
|
+
|
84
|
+
get admins_path
|
85
|
+
assert_redirected_to new_admin_session_path
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'signed in as admin should be able to access admin actions' do
|
89
|
+
sign_in_as_admin
|
90
|
+
assert warden.authenticated?(:admin)
|
91
|
+
assert_not warden.authenticated?(:user)
|
92
|
+
|
93
|
+
get admins_path
|
94
|
+
|
95
|
+
assert_response :success
|
96
|
+
assert_template 'admins/index'
|
97
|
+
assert_contain 'Welcome Admin'
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'authenticated admin should not be able to sign as admin again' do
|
101
|
+
sign_in_as_admin
|
102
|
+
get new_admin_session_path
|
103
|
+
|
104
|
+
assert_response :redirect
|
105
|
+
assert_redirected_to admin_root_path
|
106
|
+
assert warden.authenticated?(:admin)
|
107
|
+
end
|
108
|
+
|
109
|
+
test 'authenticated admin should be able to sign out' do
|
110
|
+
sign_in_as_admin
|
111
|
+
assert warden.authenticated?(:admin)
|
112
|
+
|
113
|
+
get destroy_admin_session_path
|
114
|
+
assert_response :redirect
|
115
|
+
assert_redirected_to root_path
|
116
|
+
|
117
|
+
get root_path
|
118
|
+
assert_contain 'Signed out successfully'
|
119
|
+
assert_not warden.authenticated?(:admin)
|
120
|
+
end
|
121
|
+
|
122
|
+
test 'unauthenticated admin does not set message on sign out' do
|
123
|
+
get destroy_admin_session_path
|
124
|
+
assert_response :redirect
|
125
|
+
assert_redirected_to root_path
|
126
|
+
|
127
|
+
get root_path
|
128
|
+
assert_not_contain 'Signed out successfully'
|
129
|
+
end
|
130
|
+
|
131
|
+
test 'scope uses custom failure app' do
|
132
|
+
put "/en/accounts/management"
|
133
|
+
assert_equal "Oops, not found", response.body
|
134
|
+
assert_equal 404, response.status
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
139
|
+
test 'not signed in should not be able to access private route (authenticate denied)' do
|
140
|
+
get private_path
|
141
|
+
assert_redirected_to new_admin_session_path
|
142
|
+
assert_not warden.authenticated?(:admin)
|
143
|
+
end
|
144
|
+
|
145
|
+
test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do
|
146
|
+
sign_in_as_user
|
147
|
+
assert warden.authenticated?(:user)
|
148
|
+
assert_not warden.authenticated?(:admin)
|
149
|
+
get private_path
|
150
|
+
assert_redirected_to new_admin_session_path
|
151
|
+
end
|
152
|
+
|
153
|
+
test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do
|
154
|
+
sign_in_as_admin
|
155
|
+
assert warden.authenticated?(:admin)
|
156
|
+
assert_not warden.authenticated?(:user)
|
157
|
+
|
158
|
+
get private_path
|
159
|
+
|
160
|
+
assert_response :success
|
161
|
+
assert_template 'home/private'
|
162
|
+
assert_contain 'Private!'
|
163
|
+
end
|
164
|
+
|
165
|
+
test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
|
166
|
+
sign_in_as_admin(:active => false)
|
167
|
+
assert warden.authenticated?(:admin)
|
168
|
+
assert_not warden.authenticated?(:user)
|
169
|
+
|
170
|
+
assert_raises ActionController::RoutingError do
|
171
|
+
get "/private/active"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
|
176
|
+
sign_in_as_admin(:active => true)
|
177
|
+
assert warden.authenticated?(:admin)
|
178
|
+
assert_not warden.authenticated?(:user)
|
179
|
+
|
180
|
+
get private_active_path
|
181
|
+
|
182
|
+
assert_response :success
|
183
|
+
assert_template 'home/private'
|
184
|
+
assert_contain 'Private!'
|
185
|
+
end
|
186
|
+
|
187
|
+
test 'signed in as admin should get admin dashboard (authenticated accepted)' do
|
188
|
+
sign_in_as_admin
|
189
|
+
assert warden.authenticated?(:admin)
|
190
|
+
assert_not warden.authenticated?(:user)
|
191
|
+
|
192
|
+
get dashboard_path
|
193
|
+
|
194
|
+
assert_response :success
|
195
|
+
assert_template 'home/admin'
|
196
|
+
assert_contain 'Admin dashboard'
|
197
|
+
end
|
198
|
+
|
199
|
+
test 'signed in as user should get user dashboard (authenticated accepted)' do
|
200
|
+
sign_in_as_user
|
201
|
+
assert warden.authenticated?(:user)
|
202
|
+
assert_not warden.authenticated?(:admin)
|
203
|
+
|
204
|
+
get dashboard_path
|
205
|
+
|
206
|
+
assert_response :success
|
207
|
+
assert_template 'home/user'
|
208
|
+
assert_contain 'User dashboard'
|
209
|
+
end
|
210
|
+
|
211
|
+
test 'not signed in should get no dashboard (authenticated denied)' do
|
212
|
+
assert_raises ActionController::RoutingError do
|
213
|
+
get dashboard_path
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
|
218
|
+
sign_in_as_admin(:active => false)
|
219
|
+
assert warden.authenticated?(:admin)
|
220
|
+
assert_not warden.authenticated?(:user)
|
221
|
+
|
222
|
+
assert_raises ActionController::RoutingError do
|
223
|
+
get "/dashboard/active"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
|
228
|
+
sign_in_as_admin(:active => true)
|
229
|
+
assert warden.authenticated?(:admin)
|
230
|
+
assert_not warden.authenticated?(:user)
|
231
|
+
|
232
|
+
get dashboard_active_path
|
233
|
+
|
234
|
+
assert_response :success
|
235
|
+
assert_template 'home/admin_dashboard'
|
236
|
+
assert_contain 'Admin dashboard'
|
237
|
+
end
|
238
|
+
|
239
|
+
test 'signed in user should not see unauthenticated page (unauthenticated denied)' do
|
240
|
+
sign_in_as_user
|
241
|
+
assert warden.authenticated?(:user)
|
242
|
+
assert_not warden.authenticated?(:admin)
|
243
|
+
|
244
|
+
assert_raises ActionController::RoutingError do
|
245
|
+
get join_path
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
test 'not signed in users should see unautheticated page (unauthenticated accepted)' do
|
250
|
+
get join_path
|
251
|
+
|
252
|
+
assert_response :success
|
253
|
+
assert_template 'home/join'
|
254
|
+
assert_contain 'Join'
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
class AuthenticationRedirectTest < ActionController::IntegrationTest
|
259
|
+
test 'redirect from warden shows sign in or sign up message' do
|
260
|
+
get admins_path
|
261
|
+
|
262
|
+
warden_path = new_admin_session_path
|
263
|
+
assert_redirected_to warden_path
|
264
|
+
|
265
|
+
get warden_path
|
266
|
+
assert_contain 'You need to sign in or sign up before continuing.'
|
267
|
+
end
|
268
|
+
|
269
|
+
test 'redirect to default url if no other was configured' do
|
270
|
+
sign_in_as_user
|
271
|
+
assert_template 'home/index'
|
272
|
+
assert_nil session[:"user_return_to"]
|
273
|
+
end
|
274
|
+
|
275
|
+
test 'redirect to requested url after sign in' do
|
276
|
+
get users_path
|
277
|
+
assert_redirected_to new_user_session_path
|
278
|
+
assert_equal users_path, session[:"user_return_to"]
|
279
|
+
|
280
|
+
follow_redirect!
|
281
|
+
sign_in_as_user :visit => false
|
282
|
+
|
283
|
+
assert_current_url '/users'
|
284
|
+
assert_nil session[:"user_return_to"]
|
285
|
+
end
|
286
|
+
|
287
|
+
test 'redirect to last requested url overwriting the stored return_to option' do
|
288
|
+
get expire_user_path(create_user)
|
289
|
+
assert_redirected_to new_user_session_path
|
290
|
+
assert_equal expire_user_path(create_user), session[:"user_return_to"]
|
291
|
+
|
292
|
+
get users_path
|
293
|
+
assert_redirected_to new_user_session_path
|
294
|
+
assert_equal users_path, session[:"user_return_to"]
|
295
|
+
|
296
|
+
follow_redirect!
|
297
|
+
sign_in_as_user :visit => false
|
298
|
+
|
299
|
+
assert_current_url '/users'
|
300
|
+
assert_nil session[:"user_return_to"]
|
301
|
+
end
|
302
|
+
|
303
|
+
test 'xml http requests does not store urls for redirect' do
|
304
|
+
get users_path, {}, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
|
305
|
+
assert_equal 401, response.status
|
306
|
+
assert_nil session[:"user_return_to"]
|
307
|
+
end
|
308
|
+
|
309
|
+
test 'redirect to configured home path for a given scope after sign in' do
|
310
|
+
sign_in_as_admin
|
311
|
+
assert_equal "/admin_area/home", @request.path
|
312
|
+
end
|
313
|
+
|
314
|
+
test 'require_no_authentication should set the already_authenticated flash message' do
|
315
|
+
sign_in_as_user
|
316
|
+
visit new_user_session_path
|
317
|
+
assert_equal flash[:alert], I18n.t("devise.failure.already_authenticated")
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
class AuthenticationSessionTest < ActionController::IntegrationTest
|
322
|
+
test 'destroyed account is signed out' do
|
323
|
+
sign_in_as_user
|
324
|
+
get '/users'
|
325
|
+
|
326
|
+
User.destroy_all
|
327
|
+
get '/users'
|
328
|
+
assert_redirected_to new_user_session_path
|
329
|
+
end
|
330
|
+
|
331
|
+
test 'allows session to be set for a given scope' do
|
332
|
+
sign_in_as_user
|
333
|
+
get '/users'
|
334
|
+
assert_equal "Cart", @controller.user_session[:cart]
|
335
|
+
end
|
336
|
+
|
337
|
+
test 'does not explode when invalid user class is stored in session' do
|
338
|
+
klass = User
|
339
|
+
paths = ActiveSupport::Dependencies.autoload_paths.dup
|
340
|
+
|
341
|
+
begin
|
342
|
+
sign_in_as_user
|
343
|
+
assert warden.authenticated?(:user)
|
344
|
+
|
345
|
+
Object.send :remove_const, :User
|
346
|
+
ActiveSupport::Dependencies.autoload_paths.clear
|
347
|
+
|
348
|
+
visit "/users"
|
349
|
+
assert_not warden.authenticated?(:user)
|
350
|
+
ensure
|
351
|
+
Object.const_set(:User, klass)
|
352
|
+
ActiveSupport::Dependencies.autoload_paths.replace(paths)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
test 'session id is changed on sign in' do
|
357
|
+
get '/users'
|
358
|
+
session_id = request.session["session_id"]
|
359
|
+
|
360
|
+
get '/users'
|
361
|
+
assert_equal session_id, request.session["session_id"]
|
362
|
+
|
363
|
+
sign_in_as_user
|
364
|
+
assert_not_equal session_id, request.session["session_id"]
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
class AuthenticationWithScopedViewsTest < ActionController::IntegrationTest
|
369
|
+
test 'renders the scoped view if turned on and view is available' do
|
370
|
+
swap Devise, :scoped_views => true do
|
371
|
+
assert_raise Webrat::NotFoundError do
|
372
|
+
sign_in_as_user
|
373
|
+
end
|
374
|
+
assert_match /Special user view/, response.body
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
test 'renders the scoped view if turned on in an specific controller' do
|
379
|
+
begin
|
380
|
+
Devise::SessionsController.scoped_views = true
|
381
|
+
assert_raise Webrat::NotFoundError do
|
382
|
+
sign_in_as_user
|
383
|
+
end
|
384
|
+
|
385
|
+
assert_match /Special user view/, response.body
|
386
|
+
assert !Devise::PasswordsController.scoped_views?
|
387
|
+
ensure
|
388
|
+
Devise::SessionsController.send :remove_instance_variable, :@scoped_views
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
test 'does not render the scoped view if turned off' do
|
393
|
+
swap Devise, :scoped_views => false do
|
394
|
+
assert_nothing_raised do
|
395
|
+
sign_in_as_user
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
test 'does not render the scoped view if not available' do
|
401
|
+
swap Devise, :scoped_views => true do
|
402
|
+
assert_nothing_raised do
|
403
|
+
sign_in_as_admin
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
class AuthenticationOthersTest < ActionController::IntegrationTest
|
410
|
+
test 'handles unverified requests gets rid of caches' do
|
411
|
+
swap UsersController, :allow_forgery_protection => true do
|
412
|
+
post exhibit_user_url(1)
|
413
|
+
assert_not warden.authenticated?(:user)
|
414
|
+
|
415
|
+
sign_in_as_user
|
416
|
+
assert warden.authenticated?(:user)
|
417
|
+
|
418
|
+
post exhibit_user_url(1)
|
419
|
+
assert_not warden.authenticated?(:user)
|
420
|
+
assert_equal "User is not authenticated", response.body
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
test 'uses the custom controller with the custom controller view' do
|
425
|
+
get '/admin_area/sign_in'
|
426
|
+
assert_contain 'Sign in'
|
427
|
+
assert_contain 'Welcome to "admins/sessions" controller!'
|
428
|
+
assert_contain 'Welcome to "sessions/new" view!'
|
429
|
+
end
|
430
|
+
|
431
|
+
test 'render 404 on roles without routes' do
|
432
|
+
assert_raise ActionController::RoutingError do
|
433
|
+
get '/admin_area/password/new'
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
test 'does not intercept Rails 401 responses' do
|
438
|
+
get '/unauthenticated'
|
439
|
+
assert_equal 401, response.status
|
440
|
+
end
|
441
|
+
|
442
|
+
test 'render 404 on roles without mapping' do
|
443
|
+
assert_raise AbstractController::ActionNotFound do
|
444
|
+
get '/sign_in'
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
test 'sign in with script name' do
|
449
|
+
assert_nothing_raised do
|
450
|
+
get new_user_session_path, {}, "SCRIPT_NAME" => "/omg"
|
451
|
+
fill_in "email", :with => "user@test.com"
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
test 'sign in stub in xml format' do
|
456
|
+
get new_user_session_path(:format => 'xml')
|
457
|
+
assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
|
458
|
+
assert_match /<user>.*<\/user>/m, response.body
|
459
|
+
assert_match '<email></email>', response.body
|
460
|
+
assert_match '<password nil="true"></password>', response.body
|
461
|
+
end
|
462
|
+
|
463
|
+
test 'sign in stub in json format' do
|
464
|
+
get new_user_session_path(:format => 'json')
|
465
|
+
assert_match '{"user":{', response.body
|
466
|
+
assert_match '"email":""', response.body
|
467
|
+
assert_match '"password":null', response.body
|
468
|
+
end
|
469
|
+
|
470
|
+
test 'sign in stub in json with non attribute key' do
|
471
|
+
swap Devise, :authentication_keys => [:other_key] do
|
472
|
+
get new_user_session_path(:format => 'json')
|
473
|
+
assert_match '{"user":{', response.body
|
474
|
+
assert_match '"other_key":null', response.body
|
475
|
+
assert_match '"password":null', response.body
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
test 'uses the mapping from router' do
|
480
|
+
sign_in_as_user :visit => "/as/sign_in"
|
481
|
+
assert warden.authenticated?(:user)
|
482
|
+
assert_not warden.authenticated?(:admin)
|
483
|
+
end
|
484
|
+
|
485
|
+
test 'sign in with xml format returns xml response' do
|
486
|
+
create_user
|
487
|
+
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
|
488
|
+
assert_response :success
|
489
|
+
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
490
|
+
end
|
491
|
+
|
492
|
+
test 'sign in with xml format is idempotent' do
|
493
|
+
get new_user_session_path(:format => 'xml')
|
494
|
+
assert_response :success
|
495
|
+
|
496
|
+
create_user
|
497
|
+
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
|
498
|
+
assert_response :success
|
499
|
+
|
500
|
+
get new_user_session_path(:format => 'xml')
|
501
|
+
assert_response :success
|
502
|
+
|
503
|
+
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
|
504
|
+
assert_response :success
|
505
|
+
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
506
|
+
end
|
507
|
+
|
508
|
+
test 'sign out with xml format returns ok response' do
|
509
|
+
sign_in_as_user
|
510
|
+
get destroy_user_session_path(:format => 'xml')
|
511
|
+
assert_response :no_content
|
512
|
+
assert_not warden.authenticated?(:user)
|
513
|
+
end
|
514
|
+
|
515
|
+
test 'sign out with json format returns empty json response' do
|
516
|
+
sign_in_as_user
|
517
|
+
get destroy_user_session_path(:format => 'json')
|
518
|
+
assert_response :no_content
|
519
|
+
assert_not warden.authenticated?(:user)
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
class AuthenticationKeysTest < ActionController::IntegrationTest
|
524
|
+
test 'missing authentication keys cause authentication to abort' do
|
525
|
+
swap Devise, :authentication_keys => [:subdomain] do
|
526
|
+
sign_in_as_user
|
527
|
+
assert_contain "Invalid email or password."
|
528
|
+
assert_not warden.authenticated?(:user)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
test 'missing authentication keys cause authentication to abort unless marked as not required' do
|
533
|
+
swap Devise, :authentication_keys => { :email => true, :subdomain => false } do
|
534
|
+
sign_in_as_user
|
535
|
+
assert warden.authenticated?(:user)
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
class AuthenticationRequestKeysTest < ActionController::IntegrationTest
|
541
|
+
test 'request keys are used on authentication' do
|
542
|
+
host! 'foo.bar.baz'
|
543
|
+
|
544
|
+
swap Devise, :request_keys => [:subdomain] do
|
545
|
+
User.expects(:find_for_authentication).with(:subdomain => 'foo', :email => 'user@test.com').returns(create_user)
|
546
|
+
sign_in_as_user
|
547
|
+
assert warden.authenticated?(:user)
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
test 'invalid request keys raises NoMethodError' do
|
552
|
+
swap Devise, :request_keys => [:unknown_method] do
|
553
|
+
assert_raise NoMethodError do
|
554
|
+
sign_in_as_user
|
555
|
+
end
|
556
|
+
|
557
|
+
assert_not warden.authenticated?(:user)
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
test 'blank request keys cause authentication to abort' do
|
562
|
+
host! 'test.com'
|
563
|
+
|
564
|
+
swap Devise, :request_keys => [:subdomain] do
|
565
|
+
sign_in_as_user
|
566
|
+
assert_contain "Invalid email or password."
|
567
|
+
assert_not warden.authenticated?(:user)
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
test 'blank request keys cause authentication to abort unless if marked as not required' do
|
572
|
+
host! 'test.com'
|
573
|
+
|
574
|
+
swap Devise, :request_keys => { :subdomain => false } do
|
575
|
+
sign_in_as_user
|
576
|
+
assert warden.authenticated?(:user)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
class AuthenticationSignOutViaTest < ActionController::IntegrationTest
|
582
|
+
def sign_in!(scope)
|
583
|
+
sign_in_as_admin(:visit => send("new_#{scope}_session_path"))
|
584
|
+
assert warden.authenticated?(scope)
|
585
|
+
end
|
586
|
+
|
587
|
+
test 'allow sign out via delete when sign_out_via provides only delete' do
|
588
|
+
sign_in!(:sign_out_via_delete)
|
589
|
+
delete destroy_sign_out_via_delete_session_path
|
590
|
+
assert_not warden.authenticated?(:sign_out_via_delete)
|
591
|
+
end
|
592
|
+
|
593
|
+
test 'do not allow sign out via get when sign_out_via provides only delete' do
|
594
|
+
sign_in!(:sign_out_via_delete)
|
595
|
+
assert_raise ActionController::RoutingError do
|
596
|
+
get destroy_sign_out_via_delete_session_path
|
597
|
+
end
|
598
|
+
assert warden.authenticated?(:sign_out_via_delete)
|
599
|
+
end
|
600
|
+
|
601
|
+
test 'allow sign out via post when sign_out_via provides only post' do
|
602
|
+
sign_in!(:sign_out_via_post)
|
603
|
+
post destroy_sign_out_via_post_session_path
|
604
|
+
assert_not warden.authenticated?(:sign_out_via_post)
|
605
|
+
end
|
606
|
+
|
607
|
+
test 'do not allow sign out via get when sign_out_via provides only post' do
|
608
|
+
sign_in!(:sign_out_via_post)
|
609
|
+
assert_raise ActionController::RoutingError do
|
610
|
+
get destroy_sign_out_via_delete_session_path
|
611
|
+
end
|
612
|
+
assert warden.authenticated?(:sign_out_via_post)
|
613
|
+
end
|
614
|
+
|
615
|
+
test 'allow sign out via delete when sign_out_via provides delete and post' do
|
616
|
+
sign_in!(:sign_out_via_delete_or_post)
|
617
|
+
delete destroy_sign_out_via_delete_or_post_session_path
|
618
|
+
assert_not warden.authenticated?(:sign_out_via_delete_or_post)
|
619
|
+
end
|
620
|
+
|
621
|
+
test 'allow sign out via post when sign_out_via provides delete and post' do
|
622
|
+
sign_in!(:sign_out_via_delete_or_post)
|
623
|
+
post destroy_sign_out_via_delete_or_post_session_path
|
624
|
+
assert_not warden.authenticated?(:sign_out_via_delete_or_post)
|
625
|
+
end
|
626
|
+
|
627
|
+
test 'do not allow sign out via get when sign_out_via provides delete and post' do
|
628
|
+
sign_in!(:sign_out_via_delete_or_post)
|
629
|
+
assert_raise ActionController::RoutingError do
|
630
|
+
get destroy_sign_out_via_delete_or_post_session_path
|
631
|
+
end
|
632
|
+
assert warden.authenticated?(:sign_out_via_delete_or_post)
|
633
|
+
end
|
634
|
+
end
|