devise_token_auth 0.1.42 → 0.1.43.beta1
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.
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
@@ -8,7 +8,7 @@ require 'test_helper'
|
|
8
8
|
|
9
9
|
class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
10
10
|
describe DeviseTokenAuth::SessionsController do
|
11
|
-
describe
|
11
|
+
describe 'Confirmed user' do
|
12
12
|
before do
|
13
13
|
@existing_user = users(:confirmed_email_user)
|
14
14
|
@existing_user.skip_confirmation!
|
@@ -23,10 +23,11 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
23
23
|
@old_sign_in_ip = @existing_user.current_sign_in_ip
|
24
24
|
@old_last_sign_in_ip = @existing_user.last_sign_in_ip
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
post :create,
|
27
|
+
params: {
|
28
|
+
email: @existing_user.email,
|
29
|
+
password: 'secret123'
|
30
|
+
}
|
30
31
|
|
31
32
|
@resource = assigns(:resource)
|
32
33
|
@data = JSON.parse(response.body)
|
@@ -38,11 +39,11 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
38
39
|
@new_last_sign_in_ip = @resource.last_sign_in_ip
|
39
40
|
end
|
40
41
|
|
41
|
-
test
|
42
|
+
test 'request should succeed' do
|
42
43
|
assert_equal 200, response.status
|
43
44
|
end
|
44
45
|
|
45
|
-
test
|
46
|
+
test 'request should return user data' do
|
46
47
|
assert_equal @existing_user.email, @data['data']['email']
|
47
48
|
end
|
48
49
|
|
@@ -63,31 +64,30 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
63
64
|
|
64
65
|
test 'sign_in_ip is updated' do
|
65
66
|
refute @old_sign_in_ip
|
66
|
-
assert_equal
|
67
|
+
assert_equal '0.0.0.0', @new_sign_in_ip
|
67
68
|
end
|
68
69
|
|
69
70
|
test 'last_sign_in_ip is updated' do
|
70
71
|
refute @old_last_sign_in_ip
|
71
|
-
assert_equal
|
72
|
+
assert_equal '0.0.0.0', @new_last_sign_in_ip
|
72
73
|
end
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
77
|
describe 'get sign_in is not supported' do
|
77
78
|
before do
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
}
|
79
|
+
get :new,
|
80
|
+
params: { nickname: @existing_user.nickname,
|
81
|
+
password: 'secret123' }
|
82
82
|
@data = JSON.parse(response.body)
|
83
83
|
end
|
84
84
|
|
85
85
|
test 'user is notified that they should use post sign_in to authenticate' do
|
86
86
|
assert_equal 405, response.status
|
87
87
|
end
|
88
|
-
test
|
88
|
+
test 'response should contain errors' do
|
89
89
|
assert @data['errors']
|
90
|
-
assert_equal @data['errors'], [I18n.t(
|
90
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.not_supported')]
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -95,9 +95,10 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
95
95
|
before do
|
96
96
|
request.headers.merge!(
|
97
97
|
'email' => @existing_user.email,
|
98
|
-
'password' => 'secret123'
|
98
|
+
'password' => 'secret123'
|
99
|
+
)
|
99
100
|
|
100
|
-
|
101
|
+
head :create
|
101
102
|
@data = JSON.parse(response.body)
|
102
103
|
end
|
103
104
|
|
@@ -108,10 +109,9 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
108
109
|
|
109
110
|
describe 'alt auth keys' do
|
110
111
|
before do
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
}
|
112
|
+
post :create,
|
113
|
+
params: { nickname: @existing_user.nickname,
|
114
|
+
password: 'secret123' }
|
115
115
|
@data = JSON.parse(response.body)
|
116
116
|
end
|
117
117
|
|
@@ -123,23 +123,28 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
123
123
|
|
124
124
|
describe 'authed user sign out' do
|
125
125
|
before do
|
126
|
-
def @controller.reset_session_called
|
127
|
-
|
126
|
+
def @controller.reset_session_called
|
127
|
+
@reset_session_called == true
|
128
|
+
end
|
129
|
+
|
130
|
+
def @controller.reset_session
|
131
|
+
@reset_session_called = true
|
132
|
+
end
|
128
133
|
@auth_headers = @existing_user.create_new_auth_token
|
129
134
|
request.headers.merge!(@auth_headers)
|
130
|
-
|
135
|
+
delete :destroy, format: :json
|
131
136
|
end
|
132
137
|
|
133
|
-
test
|
138
|
+
test 'user is successfully logged out' do
|
134
139
|
assert_equal 200, response.status
|
135
140
|
end
|
136
141
|
|
137
|
-
test
|
142
|
+
test 'token was destroyed' do
|
138
143
|
@existing_user.reload
|
139
|
-
refute @existing_user.tokens[@auth_headers[
|
144
|
+
refute @existing_user.tokens[@auth_headers['client']]
|
140
145
|
end
|
141
146
|
|
142
|
-
test
|
147
|
+
test 'session was destroyed' do
|
143
148
|
assert_equal true, @controller.reset_session_called
|
144
149
|
end
|
145
150
|
end
|
@@ -147,38 +152,39 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
147
152
|
describe 'unauthed user sign out' do
|
148
153
|
before do
|
149
154
|
@auth_headers = @existing_user.create_new_auth_token
|
150
|
-
|
155
|
+
delete :destroy, format: :json
|
151
156
|
@data = JSON.parse(response.body)
|
152
157
|
end
|
153
158
|
|
154
|
-
test
|
159
|
+
test 'unauthed request returns 404' do
|
155
160
|
assert_equal 404, response.status
|
156
161
|
end
|
157
162
|
|
158
|
-
test
|
163
|
+
test 'response should contain errors' do
|
159
164
|
assert @data['errors']
|
160
|
-
assert_equal @data['errors'],
|
165
|
+
assert_equal @data['errors'],
|
166
|
+
[I18n.t('devise_token_auth.sessions.user_not_found')]
|
161
167
|
end
|
162
168
|
end
|
163
169
|
|
164
170
|
describe 'failure' do
|
165
171
|
before do
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
}
|
172
|
+
post :create,
|
173
|
+
params: { email: @existing_user.email,
|
174
|
+
password: 'bogus' }
|
170
175
|
|
171
176
|
@resource = assigns(:resource)
|
172
177
|
@data = JSON.parse(response.body)
|
173
178
|
end
|
174
179
|
|
175
|
-
test
|
180
|
+
test 'request should fail' do
|
176
181
|
assert_equal 401, response.status
|
177
182
|
end
|
178
183
|
|
179
|
-
test
|
184
|
+
test 'response should contain errors' do
|
180
185
|
assert @data['errors']
|
181
|
-
assert_equal @data['errors'],
|
186
|
+
assert_equal @data['errors'],
|
187
|
+
[I18n.t('devise_token_auth.sessions.bad_credentials')]
|
182
188
|
end
|
183
189
|
end
|
184
190
|
|
@@ -190,31 +196,29 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
190
196
|
# which initializes client_id
|
191
197
|
@controller.current_user
|
192
198
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
}
|
199
|
+
post :create,
|
200
|
+
params: { email: @existing_user.email,
|
201
|
+
password: 'bogus' }
|
197
202
|
|
198
203
|
@resource = assigns(:resource)
|
199
204
|
@data = JSON.parse(response.body)
|
200
205
|
end
|
201
206
|
|
202
|
-
test
|
207
|
+
test 'request should fail' do
|
203
208
|
assert_equal 401, response.status
|
204
209
|
end
|
205
210
|
|
206
|
-
test
|
211
|
+
test 'response should contain errors' do
|
207
212
|
assert @data['errors']
|
208
|
-
assert_equal @data['errors'], [I18n.t(
|
213
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.bad_credentials')]
|
209
214
|
end
|
210
215
|
|
211
216
|
after do
|
212
|
-
|
217
|
+
DeviseTokenAuth.change_headers_on_each_request = true
|
213
218
|
end
|
214
219
|
end
|
215
220
|
|
216
221
|
describe 'case-insensitive email' do
|
217
|
-
|
218
222
|
before do
|
219
223
|
@resource_class = User
|
220
224
|
@request_params = {
|
@@ -223,51 +227,49 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
223
227
|
}
|
224
228
|
end
|
225
229
|
|
226
|
-
test
|
230
|
+
test 'request should succeed if configured' do
|
227
231
|
@resource_class.case_insensitive_keys = [:email]
|
228
|
-
|
232
|
+
post :create, params: @request_params
|
229
233
|
assert_equal 200, response.status
|
230
234
|
end
|
231
235
|
|
232
|
-
test
|
236
|
+
test 'request should fail if not configured' do
|
233
237
|
@resource_class.case_insensitive_keys = []
|
234
|
-
|
238
|
+
post :create, params: @request_params
|
235
239
|
assert_equal 401, response.status
|
236
240
|
end
|
237
|
-
|
238
241
|
end
|
239
242
|
end
|
240
243
|
|
241
|
-
describe
|
244
|
+
describe 'Unconfirmed user' do
|
242
245
|
before do
|
243
246
|
@unconfirmed_user = users(:unconfirmed_email_user)
|
244
|
-
|
245
|
-
|
246
|
-
password: 'secret123'
|
247
|
-
}
|
247
|
+
post :create, params: { email: @unconfirmed_user.email,
|
248
|
+
password: 'secret123' }
|
248
249
|
@resource = assigns(:resource)
|
249
250
|
@data = JSON.parse(response.body)
|
250
251
|
end
|
251
252
|
|
252
|
-
test
|
253
|
+
test 'request should fail' do
|
253
254
|
assert_equal 401, response.status
|
254
255
|
end
|
255
256
|
|
256
|
-
test
|
257
|
+
test 'response should contain errors' do
|
257
258
|
assert @data['errors']
|
258
|
-
assert_equal @data['errors'],
|
259
|
+
assert_equal @data['errors'],
|
260
|
+
[I18n.t('devise_token_auth.sessions.not_confirmed',
|
261
|
+
email: @unconfirmed_user.email)]
|
259
262
|
end
|
260
263
|
end
|
261
264
|
|
262
|
-
describe
|
265
|
+
describe 'Unconfirmed user with allowed unconfirmed access' do
|
263
266
|
before do
|
264
267
|
@original_duration = Devise.allow_unconfirmed_access_for
|
265
268
|
Devise.allow_unconfirmed_access_for = 3.days
|
266
269
|
@recent_unconfirmed_user = users(:recent_unconfirmed_email_user)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
}
|
270
|
+
post :create,
|
271
|
+
params: { email: @recent_unconfirmed_user.email,
|
272
|
+
password: 'secret123' }
|
271
273
|
@resource = assigns(:resource)
|
272
274
|
@data = JSON.parse(response.body)
|
273
275
|
end
|
@@ -276,24 +278,23 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
276
278
|
Devise.allow_unconfirmed_access_for = @original_duration
|
277
279
|
end
|
278
280
|
|
279
|
-
test
|
281
|
+
test 'request should succeed' do
|
280
282
|
assert_equal 200, response.status
|
281
283
|
end
|
282
284
|
|
283
|
-
test
|
285
|
+
test 'request should return user data' do
|
284
286
|
assert_equal @recent_unconfirmed_user.email, @data['data']['email']
|
285
287
|
end
|
286
288
|
end
|
287
289
|
|
288
|
-
describe
|
290
|
+
describe 'Unconfirmed user with expired unconfirmed access' do
|
289
291
|
before do
|
290
292
|
@original_duration = Devise.allow_unconfirmed_access_for
|
291
293
|
Devise.allow_unconfirmed_access_for = 3.days
|
292
294
|
@unconfirmed_user = users(:unconfirmed_email_user)
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
}
|
295
|
+
post :create,
|
296
|
+
params: { email: @unconfirmed_user.email,
|
297
|
+
password: 'secret123' }
|
297
298
|
@resource = assigns(:resource)
|
298
299
|
@data = JSON.parse(response.body)
|
299
300
|
end
|
@@ -302,35 +303,34 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
302
303
|
Devise.allow_unconfirmed_access_for = @original_duration
|
303
304
|
end
|
304
305
|
|
305
|
-
test
|
306
|
+
test 'request should fail' do
|
306
307
|
assert_equal 401, response.status
|
307
308
|
end
|
308
309
|
|
309
|
-
test
|
310
|
+
test 'response should contain errors' do
|
310
311
|
assert @data['errors']
|
311
312
|
end
|
312
313
|
end
|
313
314
|
|
314
|
-
describe
|
315
|
+
describe 'Non-existing user' do
|
315
316
|
before do
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
}
|
317
|
+
post :create,
|
318
|
+
params: { email: -> { Faker::Internet.email },
|
319
|
+
password: -> { Faker::Number.number(10) } }
|
320
320
|
@resource = assigns(:resource)
|
321
321
|
@data = JSON.parse(response.body)
|
322
322
|
end
|
323
323
|
|
324
|
-
test
|
324
|
+
test 'request should fail' do
|
325
325
|
assert_equal 401, response.status
|
326
326
|
end
|
327
327
|
|
328
|
-
test
|
328
|
+
test 'response should contain errors' do
|
329
329
|
assert @data['errors']
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
333
|
-
describe
|
333
|
+
describe 'Alternate user class' do
|
334
334
|
setup do
|
335
335
|
@request.env['devise.mapping'] = Devise.mappings[:mang]
|
336
336
|
end
|
@@ -344,20 +344,19 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
344
344
|
@existing_user.skip_confirmation!
|
345
345
|
@existing_user.save!
|
346
346
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
}
|
347
|
+
post :create,
|
348
|
+
params: { email: @existing_user.email,
|
349
|
+
password: 'secret123' }
|
351
350
|
|
352
351
|
@resource = assigns(:resource)
|
353
352
|
@data = JSON.parse(response.body)
|
354
353
|
end
|
355
354
|
|
356
|
-
test
|
355
|
+
test 'request should succeed' do
|
357
356
|
assert_equal 200, response.status
|
358
357
|
end
|
359
358
|
|
360
|
-
test
|
359
|
+
test 'request should return user data' do
|
361
360
|
assert_equal @existing_user.email, @data['data']['email']
|
362
361
|
end
|
363
362
|
end
|
@@ -375,10 +374,9 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
375
374
|
@existing_user = only_email_users(:user)
|
376
375
|
@existing_user.save!
|
377
376
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
}
|
377
|
+
post :create,
|
378
|
+
params: { email: @existing_user.email,
|
379
|
+
password: 'secret123' }
|
382
380
|
|
383
381
|
@resource = assigns(:resource)
|
384
382
|
@data = JSON.parse(response.body)
|
@@ -390,7 +388,7 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
390
388
|
end
|
391
389
|
end
|
392
390
|
|
393
|
-
describe
|
391
|
+
describe 'Lockable User' do
|
394
392
|
setup do
|
395
393
|
@request.env['devise.mapping'] = Devise.mappings[:lockable_user]
|
396
394
|
end
|
@@ -414,65 +412,62 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
414
412
|
Devise.unlock_strategy = @original_unlock_strategy
|
415
413
|
end
|
416
414
|
|
417
|
-
describe
|
415
|
+
describe 'locked user' do
|
418
416
|
before do
|
419
417
|
@locked_user = lockable_users(:locked_user)
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
}
|
418
|
+
post :create,
|
419
|
+
params: { email: @locked_user.email,
|
420
|
+
password: 'secret123' }
|
424
421
|
@data = JSON.parse(response.body)
|
425
422
|
end
|
426
423
|
|
427
|
-
test
|
424
|
+
test 'request should fail' do
|
428
425
|
assert_equal 401, response.status
|
429
426
|
end
|
430
427
|
|
431
|
-
test
|
428
|
+
test 'response should contain errors' do
|
432
429
|
assert @data['errors']
|
433
|
-
assert_equal @data['errors'], [I18n.t(
|
430
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.not_confirmed', email: @locked_user.email)]
|
434
431
|
end
|
435
432
|
end
|
436
433
|
|
437
|
-
describe
|
434
|
+
describe 'unlocked user with bad password' do
|
438
435
|
before do
|
439
436
|
@unlocked_user = lockable_users(:unlocked_user)
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
}
|
437
|
+
post :create,
|
438
|
+
params: { email: @unlocked_user.email,
|
439
|
+
password: 'bad-password' }
|
444
440
|
@data = JSON.parse(response.body)
|
445
441
|
end
|
446
442
|
|
447
|
-
test
|
443
|
+
test 'request should fail' do
|
448
444
|
assert_equal 401, response.status
|
449
445
|
end
|
450
446
|
|
451
|
-
test
|
447
|
+
test 'should increase failed_attempts' do
|
452
448
|
assert_equal 1, @unlocked_user.reload.failed_attempts
|
453
449
|
end
|
454
450
|
|
455
|
-
test
|
451
|
+
test 'response should contain errors' do
|
456
452
|
assert @data['errors']
|
457
|
-
assert_equal @data['errors'], [I18n.t(
|
453
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.bad_credentials')]
|
458
454
|
end
|
459
455
|
|
460
456
|
describe 'after maximum_attempts should block the user' do
|
461
457
|
before do
|
462
458
|
4.times do
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
}
|
459
|
+
post :create,
|
460
|
+
params: { email: @unlocked_user.email,
|
461
|
+
password: 'bad-password' }
|
467
462
|
end
|
468
463
|
@data = JSON.parse(response.body)
|
469
464
|
end
|
470
465
|
|
471
|
-
test
|
466
|
+
test 'should increase failed_attempts' do
|
472
467
|
assert_equal 5, @unlocked_user.reload.failed_attempts
|
473
468
|
end
|
474
469
|
|
475
|
-
test
|
470
|
+
test 'should block the user' do
|
476
471
|
assert_equal true, @unlocked_user.reload.access_locked?
|
477
472
|
end
|
478
473
|
end
|