devise_token_auth 0.1.42 → 0.1.43.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise_token_auth might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +39 -38
- data/app/controllers/devise_token_auth/application_controller.rb +15 -0
- data/app/controllers/devise_token_auth/concerns/resource_finder.rb +38 -0
- data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +21 -19
- data/app/controllers/devise_token_auth/confirmations_controller.rb +12 -7
- data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +3 -7
- data/app/controllers/devise_token_auth/passwords_controller.rb +16 -26
- data/app/controllers/devise_token_auth/registrations_controller.rb +6 -2
- data/app/controllers/devise_token_auth/sessions_controller.rb +3 -14
- data/app/controllers/devise_token_auth/unlocks_controller.rb +105 -0
- data/app/models/devise_token_auth/concerns/user.rb +29 -12
- data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +5 -8
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- data/app/views/devise_token_auth/omniauth_external_window.html.erb +1 -1
- data/config/initializers/devise.rb +1 -1
- data/config/locales/da-DK.yml +50 -0
- data/config/locales/en.yml +4 -0
- data/lib/devise_token_auth/controllers/helpers.rb +30 -20
- data/lib/devise_token_auth/rails/routes.rb +1 -1
- data/lib/devise_token_auth/url.rb +1 -1
- data/lib/devise_token_auth/version.rb +1 -1
- data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +2 -1
- data/lib/generators/devise_token_auth/templates/user.rb +1 -1
- data/test/controllers/custom/custom_confirmations_controller_test.rb +5 -10
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +15 -16
- data/test/controllers/custom/custom_passwords_controller_test.rb +28 -34
- data/test/controllers/custom/custom_registrations_controller_test.rb +23 -21
- data/test/controllers/custom/custom_sessions_controller_test.rb +16 -18
- data/test/controllers/custom/custom_token_validations_controller_test.rb +13 -11
- data/test/controllers/demo_group_controller_test.rb +19 -5
- data/test/controllers/demo_mang_controller_test.rb +37 -16
- data/test/controllers/demo_user_controller_test.rb +70 -38
- data/test/controllers/devise_token_auth/confirmations_controller_test.rb +40 -22
- data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +108 -82
- data/test/controllers/devise_token_auth/passwords_controller_test.rb +127 -145
- data/test/controllers/devise_token_auth/registrations_controller_test.rb +258 -274
- data/test/controllers/devise_token_auth/sessions_controller_test.rb +112 -117
- data/test/controllers/devise_token_auth/token_validations_controller_test.rb +14 -15
- data/test/controllers/devise_token_auth/unlocks_controller_test.rb +194 -0
- data/test/controllers/overrides/confirmations_controller_test.rb +8 -9
- data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +16 -12
- data/test/controllers/overrides/passwords_controller_test.rb +19 -15
- data/test/controllers/overrides/registrations_controller_test.rb +7 -7
- data/test/controllers/overrides/sessions_controller_test.rb +6 -6
- data/test/controllers/overrides/token_validations_controller_test.rb +7 -4
- data/test/dummy/app/controllers/auth_origin_controller.rb +2 -2
- data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +0 -2
- data/test/dummy/app/controllers/overrides/confirmations_controller.rb +11 -7
- data/test/dummy/app/controllers/overrides/passwords_controller.rb +10 -8
- data/test/dummy/app/controllers/overrides/sessions_controller.rb +1 -1
- data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +2 -2
- data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +2 -2
- data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +1 -1
- data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +1 -1
- data/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +2 -1
- data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +1 -1
- data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +2 -1
- data/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb +2 -1
- data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +2 -1
- data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +2 -1
- data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +2 -1
- data/test/dummy/db/schema.rb +157 -162
- data/test/dummy/tmp/generators/app/models/user.rb +1 -1
- data/test/dummy/tmp/generators/db/migrate/{20170517171822_devise_token_auth_create_users.rb → 20171014052631_devise_token_auth_create_users.rb} +2 -1
- data/test/lib/generators/devise_token_auth/install_generator_test.rb +5 -1
- data/test/models/user_test.rb +35 -1
- data/test/test_helper.rb +17 -11
- metadata +85 -80
@@ -6,13 +6,12 @@ require 'test_helper'
|
|
6
6
|
# was the correct object stored in the response?
|
7
7
|
# was the appropriate message delivered in the json payload?
|
8
8
|
|
9
|
-
|
10
9
|
class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
11
10
|
describe DeviseTokenAuth::RegistrationsController do
|
12
11
|
describe 'Validate non-empty body' do
|
13
12
|
before do
|
14
13
|
# need to post empty data
|
15
|
-
post '/auth', {}
|
14
|
+
post '/auth', params: {}
|
16
15
|
|
17
16
|
@resource = assigns(:resource)
|
18
17
|
@data = JSON.parse(response.body)
|
@@ -35,48 +34,49 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
describe
|
37
|
+
describe 'Successful registration' do
|
39
38
|
before do
|
40
39
|
@mails_sent = ActionMailer::Base.deliveries.count
|
41
40
|
|
42
|
-
post '/auth',
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
post '/auth',
|
42
|
+
params: {
|
43
|
+
email: Faker::Internet.email,
|
44
|
+
password: 'secret123',
|
45
|
+
password_confirmation: 'secret123',
|
46
|
+
confirm_success_url: Faker::Internet.url,
|
47
|
+
unpermitted_param: '(x_x)'
|
48
|
+
}
|
49
49
|
|
50
50
|
@resource = assigns(:resource)
|
51
51
|
@data = JSON.parse(response.body)
|
52
52
|
@mail = ActionMailer::Base.deliveries.last
|
53
53
|
end
|
54
54
|
|
55
|
-
test
|
55
|
+
test 'request should be successful' do
|
56
56
|
assert_equal 200, response.status
|
57
57
|
end
|
58
58
|
|
59
|
-
test
|
59
|
+
test 'user should have been created' do
|
60
60
|
assert @resource.id
|
61
61
|
end
|
62
62
|
|
63
|
-
test
|
63
|
+
test 'user should not be confirmed' do
|
64
64
|
assert_nil @resource.confirmed_at
|
65
65
|
end
|
66
66
|
|
67
|
-
test
|
67
|
+
test 'new user data should be returned as json' do
|
68
68
|
assert @data['data']['email']
|
69
69
|
end
|
70
70
|
|
71
|
-
test
|
71
|
+
test 'new user should receive confirmation email' do
|
72
72
|
assert_equal @resource.email, @mail['to'].to_s
|
73
73
|
end
|
74
74
|
|
75
|
-
test
|
75
|
+
test 'new user password should not be returned' do
|
76
76
|
assert_nil @data['data']['password']
|
77
77
|
end
|
78
78
|
|
79
|
-
test
|
79
|
+
test 'only one email was sent' do
|
80
80
|
assert_equal @mails_sent + 1, ActionMailer::Base.deliveries.count
|
81
81
|
end
|
82
82
|
end
|
@@ -85,12 +85,11 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
85
85
|
test 'can use + sign in email addresses' do
|
86
86
|
@plus_email = 'ak+testing@gmail.com'
|
87
87
|
|
88
|
-
post '/auth',
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
88
|
+
post '/auth',
|
89
|
+
params: { email: @plus_email,
|
90
|
+
password: 'secret123',
|
91
|
+
password_confirmation: 'secret123',
|
92
|
+
confirm_success_url: Faker::Internet.url }
|
94
93
|
|
95
94
|
@resource = assigns(:resource)
|
96
95
|
|
@@ -109,58 +108,55 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
109
108
|
DeviseTokenAuth.redirect_whitelist = nil
|
110
109
|
end
|
111
110
|
|
112
|
-
test
|
113
|
-
post '/auth',
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
}
|
111
|
+
test 'request to whitelisted redirect should be successful' do
|
112
|
+
post '/auth',
|
113
|
+
params: { email: Faker::Internet.email,
|
114
|
+
password: 'secret123',
|
115
|
+
password_confirmation: 'secret123',
|
116
|
+
confirm_success_url: @good_redirect_url,
|
117
|
+
unpermitted_param: '(x_x)' }
|
120
118
|
|
121
119
|
assert_equal 200, response.status
|
122
120
|
end
|
123
121
|
|
124
|
-
test
|
125
|
-
post '/auth',
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
}
|
122
|
+
test 'request to non-whitelisted redirect should fail' do
|
123
|
+
post '/auth',
|
124
|
+
params: { email: Faker::Internet.email,
|
125
|
+
password: 'secret123',
|
126
|
+
password_confirmation: 'secret123',
|
127
|
+
confirm_success_url: @bad_redirect_url,
|
128
|
+
unpermitted_param: '(x_x)' }
|
132
129
|
@data = JSON.parse(response.body)
|
133
130
|
|
134
131
|
assert_equal 422, response.status
|
135
|
-
assert @data[
|
136
|
-
assert_equal @data[
|
132
|
+
assert @data['errors']
|
133
|
+
assert_equal @data['errors'],
|
134
|
+
[I18n.t('devise_token_auth.registrations.redirect_url_not_allowed',
|
135
|
+
redirect_url: @bad_redirect_url)]
|
137
136
|
end
|
138
137
|
end
|
139
138
|
|
140
139
|
describe 'failure if not redirecturl' do
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
unpermitted_param: '(x_x)'
|
148
|
-
}
|
140
|
+
test 'request should fail if not redirect_url' do
|
141
|
+
post '/auth',
|
142
|
+
params: { email: Faker::Internet.email,
|
143
|
+
password: 'secret123',
|
144
|
+
password_confirmation: 'secret123',
|
145
|
+
unpermitted_param: '(x_x)' }
|
149
146
|
|
150
147
|
assert_equal 422, response.status
|
151
148
|
end
|
152
149
|
|
153
|
-
test
|
154
|
-
post '/auth',
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
}
|
150
|
+
test 'request to non-whitelisted redirect should fail' do
|
151
|
+
post '/auth',
|
152
|
+
params: { email: Faker::Internet.email,
|
153
|
+
password: 'secret123',
|
154
|
+
password_confirmation: 'secret123',
|
155
|
+
unpermitted_param: '(x_x)' }
|
160
156
|
@data = JSON.parse(response.body)
|
161
157
|
|
162
|
-
assert @data[
|
163
|
-
assert_equal @data[
|
158
|
+
assert @data['errors']
|
159
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.missing_confirm_success_url')]
|
164
160
|
end
|
165
161
|
end
|
166
162
|
|
@@ -171,12 +167,12 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
171
167
|
|
172
168
|
DeviseTokenAuth.default_confirm_success_url = @redirect_url
|
173
169
|
|
174
|
-
|
175
|
-
email: Faker::Internet.email,
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
170
|
+
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
|
171
|
+
post '/auth', params: { email: Faker::Internet.email,
|
172
|
+
password: 'secret123',
|
173
|
+
password_confirmation: 'secret123',
|
174
|
+
unpermitted_param: '(x_x)' }
|
175
|
+
end
|
180
176
|
|
181
177
|
@resource = assigns(:resource)
|
182
178
|
@data = JSON.parse(response.body)
|
@@ -188,14 +184,10 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
188
184
|
DeviseTokenAuth.default_confirm_success_url = nil
|
189
185
|
end
|
190
186
|
|
191
|
-
test
|
187
|
+
test 'request should be successful' do
|
192
188
|
assert_equal 200, response.status
|
193
189
|
end
|
194
190
|
|
195
|
-
test "the email was sent" do
|
196
|
-
assert_equal @mails_sent + 1, ActionMailer::Base.deliveries.count
|
197
|
-
end
|
198
|
-
|
199
191
|
test 'email contains the default redirect url' do
|
200
192
|
assert_equal @redirect_url, @sent_redirect_url
|
201
193
|
end
|
@@ -205,10 +197,10 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
205
197
|
before do
|
206
198
|
@mails_sent = ActionMailer::Base.deliveries.count
|
207
199
|
|
208
|
-
post '/api/v1/auth', {
|
200
|
+
post '/api/v1/auth', params: {
|
209
201
|
email: Faker::Internet.email,
|
210
|
-
password:
|
211
|
-
password_confirmation:
|
202
|
+
password: 'secret123',
|
203
|
+
password_confirmation: 'secret123',
|
212
204
|
confirm_success_url: Faker::Internet.url,
|
213
205
|
unpermitted_param: '(x_x)'
|
214
206
|
}
|
@@ -218,58 +210,55 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
218
210
|
@mail = ActionMailer::Base.deliveries.last
|
219
211
|
end
|
220
212
|
|
221
|
-
test
|
213
|
+
test 'request should be successful' do
|
222
214
|
assert_equal 200, response.status
|
223
215
|
end
|
224
216
|
|
225
|
-
test
|
217
|
+
test 'user should have been created' do
|
226
218
|
assert @resource.id
|
227
219
|
end
|
228
220
|
end
|
229
221
|
|
230
|
-
describe
|
231
|
-
|
222
|
+
describe 'case-insensitive email' do
|
232
223
|
before do
|
233
224
|
@resource_class = User
|
234
225
|
@request_params = {
|
235
|
-
email:
|
236
|
-
password:
|
237
|
-
password_confirmation:
|
226
|
+
email: 'AlternatingCase@example.com',
|
227
|
+
password: 'secret123',
|
228
|
+
password_confirmation: 'secret123',
|
238
229
|
confirm_success_url: Faker::Internet.url
|
239
230
|
}
|
240
231
|
end
|
241
232
|
|
242
|
-
test
|
233
|
+
test 'success should downcase uid if configured' do
|
243
234
|
@resource_class.case_insensitive_keys = [:email]
|
244
|
-
post '/auth', @request_params
|
235
|
+
post '/auth', params: @request_params
|
245
236
|
assert_equal 200, response.status
|
246
237
|
@data = JSON.parse(response.body)
|
247
|
-
assert_equal
|
238
|
+
assert_equal 'alternatingcase@example.com', @data['data']['uid']
|
248
239
|
end
|
249
240
|
|
250
|
-
test
|
241
|
+
test 'request should not downcase uid if not configured' do
|
251
242
|
@resource_class.case_insensitive_keys = []
|
252
|
-
post '/auth', @request_params
|
243
|
+
post '/auth', params: @request_params
|
253
244
|
assert_equal 200, response.status
|
254
245
|
@data = JSON.parse(response.body)
|
255
|
-
assert_equal
|
246
|
+
assert_equal 'AlternatingCase@example.com', @data['data']['uid']
|
256
247
|
end
|
257
|
-
|
258
248
|
end
|
259
249
|
|
260
|
-
describe
|
250
|
+
describe 'Adding extra params' do
|
261
251
|
before do
|
262
252
|
@redirect_url = Faker::Internet.url
|
263
253
|
@operating_thetan = 2
|
264
254
|
|
265
|
-
post '/auth',
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
}
|
255
|
+
post '/auth',
|
256
|
+
params: { email: Faker::Internet.email,
|
257
|
+
password: 'secret123',
|
258
|
+
password_confirmation: 'secret123',
|
259
|
+
confirm_success_url: @redirect_url,
|
260
|
+
favorite_color: @fav_color,
|
261
|
+
operating_thetan: @operating_thetan }
|
273
262
|
|
274
263
|
@resource = assigns(:resource)
|
275
264
|
@data = JSON.parse(response.body)
|
@@ -284,7 +273,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
284
273
|
assert_equal @redirect_url, @mail_redirect_url
|
285
274
|
end
|
286
275
|
|
287
|
-
test
|
276
|
+
test 'additional sign_up params should be considered' do
|
288
277
|
assert_equal @operating_thetan, @resource.operating_thetan
|
289
278
|
end
|
290
279
|
|
@@ -293,130 +282,125 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
293
282
|
end
|
294
283
|
|
295
284
|
test "client config name falls back to 'default'" do
|
296
|
-
assert_equal
|
285
|
+
assert_equal 'default', @mail_config_name
|
297
286
|
end
|
298
287
|
end
|
299
288
|
|
300
289
|
describe 'bad email' do
|
301
290
|
before do
|
302
|
-
post '/auth',
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
}
|
291
|
+
post '/auth',
|
292
|
+
params: { email: 'false_email@',
|
293
|
+
password: 'secret123',
|
294
|
+
password_confirmation: 'secret123',
|
295
|
+
confirm_success_url: Faker::Internet.url }
|
308
296
|
|
309
297
|
@resource = assigns(:resource)
|
310
298
|
@data = JSON.parse(response.body)
|
311
299
|
end
|
312
300
|
|
313
|
-
test
|
301
|
+
test 'request should not be successful' do
|
314
302
|
assert_equal 422, response.status
|
315
303
|
end
|
316
304
|
|
317
|
-
test
|
305
|
+
test 'user should not have been created' do
|
318
306
|
assert_nil @resource.id
|
319
307
|
end
|
320
308
|
|
321
|
-
test
|
309
|
+
test 'error should be returned in the response' do
|
322
310
|
assert @data['errors'].length
|
323
311
|
end
|
324
312
|
|
325
|
-
test
|
313
|
+
test 'full_messages should be included in error hash' do
|
326
314
|
assert @data['errors']['full_messages'].length
|
327
315
|
end
|
328
316
|
end
|
329
317
|
|
330
318
|
describe 'missing email' do
|
331
319
|
before do
|
332
|
-
post '/auth',
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
}
|
320
|
+
post '/auth',
|
321
|
+
params: { password: 'secret123',
|
322
|
+
password_confirmation: 'secret123',
|
323
|
+
confirm_success_url: Faker::Internet.url }
|
337
324
|
|
338
325
|
@resource = assigns(:resource)
|
339
326
|
@data = JSON.parse(response.body)
|
340
327
|
end
|
341
328
|
|
342
|
-
test
|
329
|
+
test 'request should not be successful' do
|
343
330
|
assert_equal 422, response.status
|
344
331
|
end
|
345
332
|
|
346
|
-
test
|
333
|
+
test 'user should not have been created' do
|
347
334
|
assert_nil @resource.id
|
348
335
|
end
|
349
336
|
|
350
|
-
test
|
337
|
+
test 'error should be returned in the response' do
|
351
338
|
assert @data['errors'].length
|
352
339
|
end
|
353
340
|
|
354
|
-
test
|
341
|
+
test 'full_messages should be included in error hash' do
|
355
342
|
assert @data['errors']['full_messages'].length
|
356
343
|
end
|
357
344
|
end
|
358
345
|
|
359
|
-
describe
|
346
|
+
describe 'Mismatched passwords' do
|
360
347
|
before do
|
361
|
-
post '/auth',
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
}
|
348
|
+
post '/auth',
|
349
|
+
params: { email: Faker::Internet.email,
|
350
|
+
password: 'secret123',
|
351
|
+
password_confirmation: 'bogus',
|
352
|
+
confirm_success_url: Faker::Internet.url }
|
367
353
|
|
368
354
|
@resource = assigns(:resource)
|
369
355
|
@data = JSON.parse(response.body)
|
370
356
|
end
|
371
357
|
|
372
|
-
test
|
358
|
+
test 'request should not be successful' do
|
373
359
|
assert_equal 422, response.status
|
374
360
|
end
|
375
361
|
|
376
|
-
test
|
362
|
+
test 'user should have been created' do
|
377
363
|
assert_nil @resource.id
|
378
364
|
end
|
379
365
|
|
380
|
-
test
|
366
|
+
test 'error should be returned in the response' do
|
381
367
|
assert @data['errors'].length
|
382
368
|
end
|
383
369
|
|
384
|
-
test
|
370
|
+
test 'full_messages should be included in error hash' do
|
385
371
|
assert @data['errors']['full_messages'].length
|
386
372
|
end
|
387
373
|
end
|
388
374
|
|
389
|
-
describe
|
375
|
+
describe 'Existing users' do
|
390
376
|
before do
|
391
377
|
@existing_user = users(:confirmed_email_user)
|
392
378
|
|
393
|
-
post
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
}
|
379
|
+
post '/auth',
|
380
|
+
params: { email: @existing_user.email,
|
381
|
+
password: 'secret123',
|
382
|
+
password_confirmation: 'secret123',
|
383
|
+
confirm_success_url: Faker::Internet.url }
|
399
384
|
|
400
385
|
@resource = assigns(:resource)
|
401
386
|
@data = JSON.parse(response.body)
|
402
387
|
end
|
403
388
|
|
404
|
-
test
|
389
|
+
test 'request should not be successful' do
|
405
390
|
assert_equal 422, response.status
|
406
391
|
end
|
407
392
|
|
408
|
-
test
|
393
|
+
test 'user should have been created' do
|
409
394
|
assert_nil @resource.id
|
410
395
|
end
|
411
396
|
|
412
|
-
test
|
397
|
+
test 'error should be returned in the response' do
|
413
398
|
assert @data['errors'].length
|
414
399
|
end
|
415
400
|
end
|
416
401
|
|
417
|
-
|
418
|
-
|
419
|
-
describe "success" do
|
402
|
+
describe 'Destroy user account' do
|
403
|
+
describe 'success' do
|
420
404
|
before do
|
421
405
|
@existing_user = users(:confirmed_email_user)
|
422
406
|
@auth_headers = @existing_user.create_new_auth_token
|
@@ -425,7 +409,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
425
409
|
# ensure request is not treated as batch request
|
426
410
|
age_token(@existing_user, @client_id)
|
427
411
|
|
428
|
-
delete
|
412
|
+
delete '/auth', params: {}, headers: @auth_headers
|
429
413
|
|
430
414
|
@data = JSON.parse(response.body)
|
431
415
|
end
|
@@ -434,18 +418,20 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
434
418
|
assert_equal 200, response.status
|
435
419
|
end
|
436
420
|
|
437
|
-
test
|
438
|
-
assert @data[
|
439
|
-
assert_equal @data[
|
421
|
+
test 'message should be returned' do
|
422
|
+
assert @data['message']
|
423
|
+
assert_equal @data['message'],
|
424
|
+
I18n.t('devise_token_auth.registrations.account_with_uid_destroyed',
|
425
|
+
uid: @existing_user.uid)
|
440
426
|
end
|
441
|
-
test
|
427
|
+
test 'existing user should be deleted' do
|
442
428
|
refute User.where(id: @existing_user.id).first
|
443
429
|
end
|
444
430
|
end
|
445
431
|
|
446
432
|
describe 'failure: no auth headers' do
|
447
433
|
before do
|
448
|
-
delete
|
434
|
+
delete '/auth'
|
449
435
|
@data = JSON.parse(response.body)
|
450
436
|
end
|
451
437
|
|
@@ -455,14 +441,13 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
455
441
|
|
456
442
|
test 'error should be returned' do
|
457
443
|
assert @data['errors'].length
|
458
|
-
assert_equal @data['errors'], [I18n.t(
|
444
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.account_to_destroy_not_found')]
|
459
445
|
end
|
460
446
|
end
|
461
447
|
end
|
462
448
|
|
463
|
-
|
464
|
-
|
465
|
-
describe "existing user" do
|
449
|
+
describe 'Update user account' do
|
450
|
+
describe 'existing user' do
|
466
451
|
before do
|
467
452
|
@existing_user = users(:confirmed_email_user)
|
468
453
|
@auth_headers = @existing_user.create_new_auth_token
|
@@ -472,37 +457,38 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
472
457
|
age_token(@existing_user, @client_id)
|
473
458
|
end
|
474
459
|
|
475
|
-
describe
|
476
|
-
describe
|
460
|
+
describe 'without password check' do
|
461
|
+
describe 'success' do
|
477
462
|
before do
|
478
463
|
# test valid update param
|
479
464
|
@resource_class = User
|
480
|
-
@new_operating_thetan =
|
481
|
-
@email =
|
465
|
+
@new_operating_thetan = 1_000_000
|
466
|
+
@email = 'AlternatingCase2@example.com'
|
482
467
|
@request_params = {
|
483
468
|
operating_thetan: @new_operating_thetan,
|
484
469
|
email: @email
|
485
470
|
}
|
486
471
|
end
|
487
472
|
|
488
|
-
test
|
489
|
-
put
|
473
|
+
test 'Request was successful' do
|
474
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
490
475
|
assert_equal 200, response.status
|
491
476
|
end
|
492
477
|
|
493
|
-
test
|
478
|
+
test 'Case sensitive attributes update' do
|
494
479
|
@resource_class.case_insensitive_keys = []
|
495
|
-
put
|
480
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
496
481
|
@data = JSON.parse(response.body)
|
497
482
|
@existing_user.reload
|
498
|
-
assert_equal @new_operating_thetan,
|
483
|
+
assert_equal @new_operating_thetan,
|
484
|
+
@existing_user.operating_thetan
|
499
485
|
assert_equal @email, @existing_user.email
|
500
486
|
assert_equal @email, @existing_user.uid
|
501
487
|
end
|
502
488
|
|
503
|
-
test
|
489
|
+
test 'Case insensitive attributes update' do
|
504
490
|
@resource_class.case_insensitive_keys = [:email]
|
505
|
-
put
|
491
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
506
492
|
@data = JSON.parse(response.body)
|
507
493
|
@existing_user.reload
|
508
494
|
assert_equal @new_operating_thetan, @existing_user.operating_thetan
|
@@ -510,16 +496,14 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
510
496
|
assert_equal @email.downcase, @existing_user.uid
|
511
497
|
end
|
512
498
|
|
513
|
-
test
|
514
|
-
@request_params
|
515
|
-
|
516
|
-
email: "new.email@example.com",
|
517
|
-
)
|
499
|
+
test 'Supply current password' do
|
500
|
+
@request_params[:current_password] = 'secret123'
|
501
|
+
@request_params[:email] = 'new.email@example.com'
|
518
502
|
|
519
|
-
put
|
503
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
520
504
|
@data = JSON.parse(response.body)
|
521
505
|
@existing_user.reload
|
522
|
-
assert_equal @existing_user.email,
|
506
|
+
assert_equal @existing_user.email, 'new.email@example.com'
|
523
507
|
end
|
524
508
|
end
|
525
509
|
|
@@ -527,7 +511,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
527
511
|
before do
|
528
512
|
# get the email so we can check it wasn't updated
|
529
513
|
@email = @existing_user.email
|
530
|
-
put '/auth', {}, @auth_headers
|
514
|
+
put '/auth', params: {}, headers: @auth_headers
|
531
515
|
|
532
516
|
@data = JSON.parse(response.body)
|
533
517
|
@existing_user.reload
|
@@ -550,29 +534,29 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
550
534
|
end
|
551
535
|
end
|
552
536
|
|
553
|
-
describe
|
537
|
+
describe 'error' do
|
554
538
|
before do
|
555
539
|
# test invalid update param
|
556
|
-
@new_operating_thetan =
|
557
|
-
put
|
558
|
-
|
559
|
-
|
540
|
+
@new_operating_thetan = 'blegh'
|
541
|
+
put '/auth',
|
542
|
+
params: { operating_thetan: @new_operating_thetan },
|
543
|
+
headers: @auth_headers
|
560
544
|
|
561
545
|
@data = JSON.parse(response.body)
|
562
546
|
@existing_user.reload
|
563
547
|
end
|
564
548
|
|
565
|
-
test
|
549
|
+
test 'Request was NOT successful' do
|
566
550
|
assert_equal 422, response.status
|
567
551
|
end
|
568
552
|
|
569
|
-
test
|
570
|
-
assert @data[
|
553
|
+
test 'Errors were provided with response' do
|
554
|
+
assert @data['errors'].length
|
571
555
|
end
|
572
556
|
end
|
573
557
|
end
|
574
558
|
|
575
|
-
describe
|
559
|
+
describe 'with password check for password update only' do
|
576
560
|
before do
|
577
561
|
DeviseTokenAuth.check_current_password_before_update = :password
|
578
562
|
end
|
@@ -581,25 +565,25 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
581
565
|
DeviseTokenAuth.check_current_password_before_update = false
|
582
566
|
end
|
583
567
|
|
584
|
-
describe
|
568
|
+
describe 'success without password update' do
|
585
569
|
before do
|
586
570
|
# test valid update param
|
587
571
|
@resource_class = User
|
588
|
-
@new_operating_thetan =
|
589
|
-
@email =
|
572
|
+
@new_operating_thetan = 1_000_000
|
573
|
+
@email = 'AlternatingCase2@example.com'
|
590
574
|
@request_params = {
|
591
575
|
operating_thetan: @new_operating_thetan,
|
592
576
|
email: @email
|
593
577
|
}
|
594
578
|
end
|
595
579
|
|
596
|
-
test
|
597
|
-
put
|
580
|
+
test 'Request was successful' do
|
581
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
598
582
|
assert_equal 200, response.status
|
599
583
|
end
|
600
584
|
end
|
601
585
|
|
602
|
-
describe
|
586
|
+
describe 'success with password update' do
|
603
587
|
before do
|
604
588
|
@existing_user.update password: 'secret123', password_confirmation: 'secret123'
|
605
589
|
@request_params = {
|
@@ -609,15 +593,16 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
609
593
|
}
|
610
594
|
end
|
611
595
|
|
612
|
-
test
|
613
|
-
put
|
596
|
+
test 'Request was successful' do
|
597
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
614
598
|
assert_equal 200, response.status
|
615
599
|
end
|
616
600
|
end
|
617
601
|
|
618
|
-
describe
|
602
|
+
describe 'error with password mismatch' do
|
619
603
|
before do
|
620
|
-
@existing_user.update password: 'secret123',
|
604
|
+
@existing_user.update password: 'secret123',
|
605
|
+
password_confirmation: 'secret123'
|
621
606
|
@request_params = {
|
622
607
|
password: 'the_new_secret456',
|
623
608
|
password_confirmation: 'the_new_secret456',
|
@@ -625,27 +610,28 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
625
610
|
}
|
626
611
|
end
|
627
612
|
|
628
|
-
test
|
629
|
-
put
|
613
|
+
test 'Request was NOT successful' do
|
614
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
630
615
|
assert_equal 422, response.status
|
631
616
|
end
|
632
617
|
end
|
633
618
|
end
|
634
619
|
|
635
|
-
describe
|
620
|
+
describe 'with password check for all attributes' do
|
636
621
|
before do
|
637
622
|
DeviseTokenAuth.check_current_password_before_update = :password
|
638
|
-
@new_operating_thetan =
|
639
|
-
@email =
|
623
|
+
@new_operating_thetan = 1_000_000
|
624
|
+
@email = 'AlternatingCase2@example.com'
|
640
625
|
end
|
641
626
|
|
642
627
|
after do
|
643
628
|
DeviseTokenAuth.check_current_password_before_update = false
|
644
629
|
end
|
645
630
|
|
646
|
-
describe
|
631
|
+
describe 'success with password update' do
|
647
632
|
before do
|
648
|
-
@existing_user.update password: 'secret123',
|
633
|
+
@existing_user.update password: 'secret123',
|
634
|
+
password_confirmation: 'secret123'
|
649
635
|
@request_params = {
|
650
636
|
operating_thetan: @new_operating_thetan,
|
651
637
|
email: @email,
|
@@ -653,15 +639,16 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
653
639
|
}
|
654
640
|
end
|
655
641
|
|
656
|
-
test
|
657
|
-
put
|
642
|
+
test 'Request was successful' do
|
643
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
658
644
|
assert_equal 200, response.status
|
659
645
|
end
|
660
646
|
end
|
661
647
|
|
662
|
-
describe
|
648
|
+
describe 'error with password mismatch' do
|
663
649
|
before do
|
664
|
-
@existing_user.update password: 'secret123',
|
650
|
+
@existing_user.update password: 'secret123',
|
651
|
+
password_confirmation: 'secret123'
|
665
652
|
@request_params = {
|
666
653
|
operating_thetan: @new_operating_thetan,
|
667
654
|
email: @email,
|
@@ -669,15 +656,15 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
669
656
|
}
|
670
657
|
end
|
671
658
|
|
672
|
-
test
|
673
|
-
put
|
659
|
+
test 'Request was NOT successful' do
|
660
|
+
put '/auth', params: @request_params, headers: @auth_headers
|
674
661
|
assert_equal 422, response.status
|
675
662
|
end
|
676
663
|
end
|
677
664
|
end
|
678
665
|
end
|
679
666
|
|
680
|
-
describe
|
667
|
+
describe 'invalid user' do
|
681
668
|
before do
|
682
669
|
@existing_user = users(:confirmed_email_user)
|
683
670
|
@auth_headers = @existing_user.create_new_auth_token
|
@@ -689,80 +676,80 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
689
676
|
# test valid update param
|
690
677
|
@new_operating_thetan = 3
|
691
678
|
|
692
|
-
put
|
693
|
-
|
694
|
-
|
679
|
+
put '/auth',
|
680
|
+
params: {
|
681
|
+
operating_thetan: @new_operating_thetan
|
682
|
+
},
|
683
|
+
headers: @auth_headers
|
695
684
|
|
696
685
|
@data = JSON.parse(response.body)
|
697
686
|
@existing_user.reload
|
698
687
|
end
|
699
688
|
|
700
|
-
test
|
689
|
+
test 'Response should return 404 status' do
|
701
690
|
assert_equal 404, response.status
|
702
691
|
end
|
703
692
|
|
704
|
-
test
|
705
|
-
assert @data[
|
706
|
-
assert_equal @data[
|
693
|
+
test 'error should be returned' do
|
694
|
+
assert @data['errors'].length
|
695
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.user_not_found')]
|
707
696
|
end
|
708
697
|
|
709
|
-
test
|
698
|
+
test 'User should not be updated' do
|
710
699
|
refute_equal @new_operating_thetan, @existing_user.operating_thetan
|
711
700
|
end
|
712
701
|
end
|
713
702
|
end
|
714
703
|
|
715
|
-
describe
|
704
|
+
describe 'Ouath user has existing email' do
|
716
705
|
before do
|
717
706
|
@existing_user = users(:duplicate_email_facebook_user)
|
718
707
|
|
719
|
-
post
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
}
|
708
|
+
post '/auth',
|
709
|
+
params: { email: @existing_user.email,
|
710
|
+
password: 'secret123',
|
711
|
+
password_confirmation: 'secret123',
|
712
|
+
confirm_success_url: Faker::Internet.url }
|
725
713
|
|
726
714
|
@resource = assigns(:resource)
|
727
715
|
@data = JSON.parse(response.body)
|
728
716
|
end
|
729
717
|
|
730
|
-
test
|
718
|
+
test 'request should be successful' do
|
731
719
|
assert_equal 200, response.status
|
732
720
|
end
|
733
721
|
|
734
|
-
test
|
722
|
+
test 'user should have been created' do
|
735
723
|
assert @resource.id
|
736
724
|
end
|
737
725
|
|
738
|
-
test
|
726
|
+
test 'new user data should be returned as json' do
|
739
727
|
assert @data['data']['email']
|
740
728
|
end
|
741
729
|
end
|
742
730
|
|
743
|
-
describe
|
731
|
+
describe 'Alternate user class' do
|
744
732
|
before do
|
745
|
-
post
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
}
|
733
|
+
post '/mangs',
|
734
|
+
params: { email: Faker::Internet.email,
|
735
|
+
password: 'secret123',
|
736
|
+
password_confirmation: 'secret123',
|
737
|
+
confirm_success_url: Faker::Internet.url }
|
751
738
|
|
752
739
|
@resource = assigns(:resource)
|
753
740
|
@data = JSON.parse(response.body)
|
754
741
|
@mail = ActionMailer::Base.deliveries.last
|
755
742
|
end
|
756
743
|
|
757
|
-
test
|
744
|
+
test 'request should be successful' do
|
758
745
|
assert_equal 200, response.status
|
759
746
|
end
|
760
747
|
|
761
|
-
test
|
762
|
-
assert_equal
|
748
|
+
test 'use should be a Mang' do
|
749
|
+
assert_equal 'Mang', @resource.class.name
|
763
750
|
end
|
764
751
|
|
765
|
-
test
|
752
|
+
test 'Mang should be destroyed' do
|
766
753
|
@resource.skip_confirmation!
|
767
754
|
@resource.save!
|
768
755
|
@auth_headers = @resource.create_new_auth_token
|
@@ -771,24 +758,25 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
771
758
|
# ensure request is not treated as batch request
|
772
759
|
age_token(@resource, @client_id)
|
773
760
|
|
774
|
-
|
761
|
+
delete '/mangs',
|
762
|
+
params: {},
|
763
|
+
headers: @auth_headers
|
775
764
|
|
776
765
|
assert_equal 200, response.status
|
777
766
|
refute Mang.where(id: @resource.id).first
|
778
767
|
end
|
779
768
|
end
|
780
769
|
|
781
|
-
describe
|
770
|
+
describe 'Passing client config name' do
|
782
771
|
before do
|
783
772
|
@config_name = 'altUser'
|
784
773
|
|
785
|
-
post
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
}
|
774
|
+
post '/mangs',
|
775
|
+
params: { email: Faker::Internet.email,
|
776
|
+
password: 'secret123',
|
777
|
+
password_confirmation: 'secret123',
|
778
|
+
confirm_success_url: Faker::Internet.url,
|
779
|
+
config_name: @config_name }
|
792
780
|
|
793
781
|
@resource = assigns(:resource)
|
794
782
|
@data = JSON.parse(response.body)
|
@@ -808,70 +796,66 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
|
|
808
796
|
|
809
797
|
describe 'Excluded :registrations module' do
|
810
798
|
test 'UnregisterableUser should not be able to access registration routes' do
|
811
|
-
assert_raises(ActionController::RoutingError)
|
812
|
-
post '/unregisterable_user_auth',
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
}
|
799
|
+
assert_raises(ActionController::RoutingError) do
|
800
|
+
post '/unregisterable_user_auth',
|
801
|
+
params: { email: Faker::Internet.email,
|
802
|
+
password: 'secret123',
|
803
|
+
password_confirmation: 'secret123',
|
804
|
+
confirm_success_url: Faker::Internet.url }
|
805
|
+
end
|
819
806
|
end
|
820
807
|
end
|
821
808
|
|
822
|
-
describe
|
809
|
+
describe 'Skipped confirmation' do
|
823
810
|
setup do
|
824
811
|
User.set_callback(:create, :before, :skip_confirmation!)
|
825
812
|
|
826
|
-
post
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
}
|
813
|
+
post '/auth',
|
814
|
+
params: { email: Faker::Internet.email,
|
815
|
+
password: 'secret123',
|
816
|
+
password_confirmation: 'secret123',
|
817
|
+
confirm_success_url: Faker::Internet.url }
|
832
818
|
|
833
819
|
@resource = assigns(:resource)
|
834
|
-
@token = response.headers[
|
835
|
-
@client_id = response.headers[
|
820
|
+
@token = response.headers['access-token']
|
821
|
+
@client_id = response.headers['client']
|
836
822
|
end
|
837
823
|
|
838
824
|
teardown do
|
839
825
|
User.skip_callback(:create, :before, :skip_confirmation!)
|
840
826
|
end
|
841
827
|
|
842
|
-
test
|
828
|
+
test 'user was created' do
|
843
829
|
assert @resource
|
844
830
|
end
|
845
831
|
|
846
|
-
test
|
832
|
+
test 'user was confirmed' do
|
847
833
|
assert @resource.confirmed?
|
848
834
|
end
|
849
835
|
|
850
|
-
test
|
851
|
-
assert response.headers[
|
852
|
-
assert response.headers[
|
853
|
-
assert response.headers[
|
854
|
-
assert response.headers[
|
855
|
-
assert response.headers[
|
836
|
+
test 'auth headers were returned in response' do
|
837
|
+
assert response.headers['access-token']
|
838
|
+
assert response.headers['token-type']
|
839
|
+
assert response.headers['client']
|
840
|
+
assert response.headers['expiry']
|
841
|
+
assert response.headers['uid']
|
856
842
|
end
|
857
843
|
|
858
|
-
test
|
844
|
+
test 'response token is valid' do
|
859
845
|
assert @resource.valid_token?(@token, @client_id)
|
860
846
|
end
|
861
847
|
end
|
862
848
|
|
863
|
-
|
864
849
|
describe 'User with only :database_authenticatable and :registerable included' do
|
865
850
|
setup do
|
866
851
|
@mails_sent = ActionMailer::Base.deliveries.count
|
867
852
|
|
868
|
-
post '/only_email_auth',
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
}
|
853
|
+
post '/only_email_auth',
|
854
|
+
params: { email: Faker::Internet.email,
|
855
|
+
password: 'secret123',
|
856
|
+
password_confirmation: 'secret123',
|
857
|
+
confirm_success_url: Faker::Internet.url,
|
858
|
+
unpermitted_param: '(x_x)' }
|
875
859
|
|
876
860
|
@resource = assigns(:resource)
|
877
861
|
@data = JSON.parse(response.body)
|