devise_jwt_auth 0.1.4 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/controllers/devise_jwt_auth/application_controller.rb +11 -22
- data/app/controllers/devise_jwt_auth/concerns/resource_finder.rb +3 -7
- data/app/controllers/devise_jwt_auth/concerns/set_user_by_token.rb +22 -18
- data/app/controllers/devise_jwt_auth/confirmations_controller.rb +10 -19
- data/app/controllers/devise_jwt_auth/omniauth_callbacks_controller.rb +38 -46
- data/app/controllers/devise_jwt_auth/passwords_controller.rb +34 -36
- data/app/controllers/devise_jwt_auth/refresh_token_controller.rb +4 -1
- data/app/controllers/devise_jwt_auth/registrations_controller.rb +40 -21
- data/app/controllers/devise_jwt_auth/sessions_controller.rb +21 -21
- data/app/controllers/devise_jwt_auth/unlocks_controller.rb +5 -4
- data/app/models/devise_jwt_auth/concerns/active_record_support.rb +3 -0
- data/app/models/devise_jwt_auth/concerns/confirmable_support.rb +7 -14
- data/app/models/devise_jwt_auth/concerns/mongoid_support.rb +3 -0
- data/app/models/devise_jwt_auth/concerns/tokens_serialization.rb +4 -1
- data/app/models/devise_jwt_auth/concerns/user.rb +18 -11
- data/app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb +11 -3
- data/app/validators/devise_jwt_auth_email_validator.rb +12 -2
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/lib/devise_jwt_auth/blacklist.rb +3 -1
- data/lib/devise_jwt_auth/controllers/url_helpers.rb +1 -2
- data/lib/devise_jwt_auth/engine.rb +4 -4
- data/lib/devise_jwt_auth/rails/routes.rb +35 -24
- data/lib/devise_jwt_auth/token_factory.rb +3 -2
- data/lib/devise_jwt_auth/url.rb +2 -4
- data/lib/devise_jwt_auth/version.rb +1 -1
- data/lib/generators/devise_jwt_auth/USAGE +1 -1
- data/lib/generators/devise_jwt_auth/install_generator.rb +7 -6
- data/lib/generators/devise_jwt_auth/install_generator_helpers.rb +27 -6
- data/lib/generators/devise_jwt_auth/install_mongoid_generator.rb +3 -2
- data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth.rb +6 -7
- data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth_create_users.rb.erb +15 -11
- data/lib/generators/devise_jwt_auth/templates/user.rb.erb +2 -2
- data/test/controllers/custom/custom_confirmations_controller_test.rb +2 -2
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +1 -1
- data/test/controllers/custom/custom_passwords_controller_test.rb +8 -8
- data/test/controllers/custom/custom_refresh_token_controller_test.rb +2 -3
- data/test/controllers/custom/custom_registrations_controller_test.rb +2 -2
- data/test/controllers/demo_group_controller_test.rb +0 -24
- data/test/controllers/demo_mang_controller_test.rb +4 -224
- data/test/controllers/demo_user_controller_test.rb +6 -432
- data/test/controllers/devise_jwt_auth/confirmations_controller_test.rb +5 -5
- data/test/controllers/devise_jwt_auth/omniauth_callbacks_controller_test.rb +9 -10
- data/test/controllers/devise_jwt_auth/passwords_controller_test.rb +34 -35
- data/test/controllers/devise_jwt_auth/refresh_token_controller_test.rb +8 -12
- data/test/controllers/devise_jwt_auth/registrations_controller_test.rb +12 -26
- data/test/controllers/devise_jwt_auth/sessions_controller_test.rb +32 -34
- data/test/controllers/devise_jwt_auth/unlocks_controller_test.rb +2 -2
- data/test/controllers/overrides/confirmations_controller_test.rb +1 -1
- data/test/controllers/overrides/passwords_controller_test.rb +1 -6
- data/test/controllers/overrides/refresh_token_controller_test.rb +1 -2
- data/test/controllers/overrides/registrations_controller_test.rb +1 -1
- data/test/dummy/app/controllers/custom/refresh_token_controller.rb +2 -1
- data/test/dummy/app/controllers/custom/registrations_controller.rb +1 -1
- data/test/dummy/app/controllers/overrides/confirmations_controller.rb +3 -16
- data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +4 -4
- data/test/dummy/app/controllers/overrides/passwords_controller.rb +4 -16
- data/test/dummy/app/controllers/overrides/refresh_token_controller.rb +1 -1
- data/test/dummy/app/controllers/overrides/registrations_controller.rb +2 -2
- data/test/dummy/app/controllers/overrides/sessions_controller.rb +2 -2
- data/test/dummy/app/models/concerns/favorite_color.rb +11 -9
- data/test/dummy/config/application.rb +1 -0
- data/test/dummy/config/boot.rb +1 -1
- data/test/dummy/config/environments/development.rb +2 -2
- data/test/dummy/config/environments/test.rb +11 -7
- data/test/dummy/config/initializers/devise_jwt_auth.rb +1 -0
- data/test/dummy/config/initializers/figaro.rb +1 -1
- data/test/dummy/config/initializers/omniauth.rb +2 -2
- data/test/dummy/config/routes.rb +10 -8
- data/test/dummy/config.ru +2 -2
- data/test/dummy/db/migrate/20141222035835_devise_jwt_auth_create_only_email_users.rb +9 -9
- data/test/dummy/db/migrate/20190924101113_devise_jwt_auth_create_confirmable_users.rb +6 -5
- data/test/dummy/db/schema.rb +170 -170
- data/test/dummy/tmp/generators/app/models/user.rb +8 -0
- data/test/dummy/tmp/generators/config/initializers/devise_jwt_auth.rb +6 -7
- data/test/dummy/tmp/generators/db/migrate/{20200210193225_devise_jwt_auth_create_azpire_v1_human_resource_users.rb → 20220123023137_devise_jwt_auth_create_users.rb} +20 -17
- data/test/factories/users.rb +5 -3
- data/test/lib/devise_jwt_auth/blacklist_test.rb +2 -2
- data/test/lib/devise_jwt_auth/token_factory_test.rb +7 -7
- data/test/lib/generators/devise_jwt_auth/install_generator_test.rb +3 -20
- data/test/lib/generators/devise_jwt_auth/install_generator_with_namespace_test.rb +4 -21
- data/test/models/concerns/tokens_serialization_test.rb +68 -68
- data/test/models/user_test.rb +0 -38
- data/test/support/controllers/routes.rb +7 -5
- data/test/test_helper.rb +1 -1
- metadata +45 -71
- data/test/dummy/tmp/generators/app/models/azpire/v1/human_resource/user.rb +0 -9
@@ -15,25 +15,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
15
15
|
before do
|
16
16
|
@resource = create(:user, :confirmed)
|
17
17
|
@auth_headers = @resource.create_named_token_pair
|
18
|
-
|
19
|
-
# @token = @auth_headers['access-token']
|
20
|
-
# @client_id = @auth_headers['client']
|
21
|
-
# @expiry = @auth_headers['expiry']
|
22
18
|
end
|
23
19
|
|
24
20
|
describe 'successful request' do
|
25
21
|
before do
|
26
|
-
# ensure that request is not treated as batch request
|
27
|
-
# age_token(@resource, @client_id)
|
28
|
-
|
29
22
|
get '/demo/members_only',
|
30
23
|
params: {},
|
31
24
|
headers: @auth_headers
|
32
|
-
|
33
|
-
# @resp_token = response.headers['access-token']
|
34
|
-
# @resp_client_id = response.headers['client']
|
35
|
-
# @resp_expiry = response.headers['expiry']
|
36
|
-
# @resp_uid = response.headers['uid']
|
37
25
|
end
|
38
26
|
|
39
27
|
describe 'devise mappings' do
|
@@ -57,44 +45,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
57
45
|
it 'should return success status' do
|
58
46
|
assert_equal 200, response.status
|
59
47
|
end
|
60
|
-
|
61
|
-
=begin
|
62
|
-
it 'should receive new token after successful request' do
|
63
|
-
refute_equal @token, @resp_token
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should preserve the client id from the first request' do
|
67
|
-
assert_equal @client_id, @resp_client_id
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return the user's uid in the auth header" do
|
71
|
-
assert_equal @resource.uid, @resp_uid
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should not treat this request as a batch request' do
|
75
|
-
refute assigns(:is_batch_request)
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'subsequent requests' do
|
79
|
-
before do
|
80
|
-
@resource.reload
|
81
|
-
# ensure that request is not treated as batch request
|
82
|
-
# age_token(@resource, @client_id)
|
83
|
-
|
84
|
-
get '/demo/members_only',
|
85
|
-
params: {},
|
86
|
-
headers: @auth_headers.merge('access-token' => @resp_token)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should not treat this request as a batch request' do
|
90
|
-
refute assigns(:is_batch_request)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should allow a new request to be made using new token' do
|
94
|
-
assert_equal 200, response.status
|
95
|
-
end
|
96
|
-
end
|
97
|
-
=end
|
98
48
|
end
|
99
49
|
|
100
50
|
describe 'failed request' do
|
@@ -112,216 +62,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
112
62
|
assert_equal 401, response.status
|
113
63
|
end
|
114
64
|
end
|
115
|
-
=begin
|
116
|
-
describe 'disable change_headers_on_each_request' do
|
117
|
-
before do
|
118
|
-
DeviseJwtAuth.change_headers_on_each_request = false
|
119
|
-
@resource.reload
|
120
|
-
# age_token(@resource, @client_id)
|
121
|
-
|
122
|
-
get '/demo/members_only',
|
123
|
-
params: {},
|
124
|
-
headers: @auth_headers
|
125
|
-
|
126
|
-
@first_is_batch_request = assigns(:is_batch_request)
|
127
|
-
@first_user = assigns(:resource).dup
|
128
|
-
@first_access_token = response.headers['access-token']
|
129
|
-
@first_response_status = response.status
|
130
|
-
|
131
|
-
@resource.reload
|
132
|
-
# age_token(@resource, @client_id)
|
133
|
-
|
134
|
-
# use expired auth header
|
135
|
-
get '/demo/members_only',
|
136
|
-
params: {},
|
137
|
-
headers: @auth_headers
|
138
|
-
|
139
|
-
@second_is_batch_request = assigns(:is_batch_request)
|
140
|
-
@second_user = assigns(:resource).dup
|
141
|
-
@second_access_token = response.headers['access-token']
|
142
|
-
@second_response_status = response.status
|
143
|
-
end
|
144
|
-
|
145
|
-
after do
|
146
|
-
DeviseJwtAuth.change_headers_on_each_request = true
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'should allow the first request through' do
|
150
|
-
assert_equal 200, @first_response_status
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'should allow the second request through' do
|
154
|
-
assert_equal 200, @second_response_status
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should return auth headers from the first request' do
|
158
|
-
assert @first_access_token
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'should not treat either requests as batch requests' do
|
162
|
-
refute @first_is_batch_request
|
163
|
-
refute @second_is_batch_request
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should return auth headers from the second request' do
|
167
|
-
assert @second_access_token
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'should define user during first request' do
|
171
|
-
assert @first_user
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'should define user during second request' do
|
175
|
-
assert @second_user
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe 'batch requests' do
|
180
|
-
describe 'success' do
|
181
|
-
before do
|
182
|
-
# age_token(@resource, @client_id)
|
183
|
-
|
184
|
-
get '/demo/members_only',
|
185
|
-
params: {},
|
186
|
-
headers: @auth_headers
|
187
|
-
|
188
|
-
@first_is_batch_request = assigns(:is_batch_request)
|
189
|
-
@first_user = assigns(:resource)
|
190
|
-
@first_access_token = response.headers['access-token']
|
191
|
-
|
192
|
-
get '/demo/members_only',
|
193
|
-
params: {},
|
194
|
-
headers: @auth_headers
|
195
|
-
|
196
|
-
@second_is_batch_request = assigns(:is_batch_request)
|
197
|
-
@second_user = assigns(:resource)
|
198
|
-
@second_access_token = response.headers['access-token']
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'should allow both requests through' do
|
202
|
-
assert_equal 200, response.status
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'should not treat the first request as a batch request' do
|
206
|
-
refute @first_is_batch_request
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'should treat the second request as a batch request' do
|
210
|
-
assert @second_is_batch_request
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'should return access token for first (non-batch) request' do
|
214
|
-
assert @first_access_token
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'should not return auth headers for second (batched) requests' do
|
218
|
-
assert_equal ' ', @second_access_token
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe 'unbatch' do
|
223
|
-
before do
|
224
|
-
@resource.reload
|
225
|
-
# age_token(@resource, @client_id)
|
226
|
-
|
227
|
-
get '/demo/members_only',
|
228
|
-
params: {},
|
229
|
-
headers: @auth_headers
|
230
|
-
|
231
|
-
@first_is_batch_request = assigns(:is_batch_request)
|
232
|
-
@first_user = assigns(:resource).dup
|
233
|
-
@first_access_token = response.headers['access-token']
|
234
|
-
@first_response_status = response.status
|
235
|
-
|
236
|
-
get '/demo/members_only?unbatch=true',
|
237
|
-
params: {},
|
238
|
-
headers: @auth_headers
|
239
|
-
|
240
|
-
@second_is_batch_request = assigns(:is_batch_request)
|
241
|
-
@second_user = assigns(:resource)
|
242
|
-
@second_access_token = response.headers['access-token']
|
243
|
-
@second_response_status = response.status
|
244
|
-
end
|
245
|
-
|
246
|
-
it 'should NOT treat the second request as a batch request when "unbatch" param is set' do
|
247
|
-
refute @second_is_batch_request
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe 'time out' do
|
252
|
-
before do
|
253
|
-
@resource.reload
|
254
|
-
# age_token(@resource, @client_id)
|
255
|
-
|
256
|
-
get '/demo/members_only',
|
257
|
-
params: {},
|
258
|
-
headers: @auth_headers
|
259
|
-
|
260
|
-
@first_is_batch_request = assigns(:is_batch_request)
|
261
|
-
@first_user = assigns(:resource).dup
|
262
|
-
@first_access_token = response.headers['access-token']
|
263
|
-
@first_response_status = response.status
|
264
|
-
|
265
|
-
@resource.reload
|
266
|
-
# age_token(@resource, @client_id)
|
267
|
-
|
268
|
-
# use expired auth header
|
269
|
-
get '/demo/members_only',
|
270
|
-
params: {},
|
271
|
-
headers: @auth_headers
|
272
|
-
|
273
|
-
@second_is_batch_request = assigns(:is_batch_request)
|
274
|
-
@second_user = assigns(:resource)
|
275
|
-
@second_access_token = response.headers['access-token']
|
276
|
-
@second_response_status = response.status
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'should allow the first request through' do
|
280
|
-
assert_equal 200, @first_response_status
|
281
|
-
end
|
282
|
-
|
283
|
-
it 'should not allow the second request through' do
|
284
|
-
assert_equal 401, @second_response_status
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'should not treat first request as batch request' do
|
288
|
-
refute @second_is_batch_request
|
289
|
-
end
|
290
|
-
|
291
|
-
it 'should return auth headers from the first request' do
|
292
|
-
assert @first_access_token
|
293
|
-
end
|
294
|
-
|
295
|
-
it 'should not treat second request as batch request' do
|
296
|
-
refute @second_is_batch_request
|
297
|
-
end
|
298
|
-
|
299
|
-
it 'should not return auth headers from the second request' do
|
300
|
-
refute @second_access_token
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'should define user during first request' do
|
304
|
-
assert @first_user
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'should not define user during second request' do
|
308
|
-
refute @second_user
|
309
|
-
end
|
310
|
-
end
|
311
|
-
end
|
312
|
-
=end
|
313
65
|
|
314
66
|
describe 'successful password change' do
|
315
67
|
before do
|
316
|
-
# DeviseJwtAuth.remove_tokens_after_password_reset = true
|
317
|
-
|
318
68
|
# adding one more token to simulate another logged in device
|
319
69
|
@old_auth_headers = @auth_headers
|
320
70
|
@auth_headers = @resource.create_named_token_pair
|
321
71
|
|
322
|
-
# age_token(@resource, @client_id)
|
323
|
-
# assert @resource.tokens.count > 1
|
324
|
-
|
325
72
|
# password changed from new device
|
326
73
|
@resource.update(password: 'newsecret123',
|
327
74
|
password_confirmation: 'newsecret123')
|
@@ -331,14 +78,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
331
78
|
headers: @auth_headers
|
332
79
|
end
|
333
80
|
|
334
|
-
after do
|
335
|
-
# DeviseJwtAuth.remove_tokens_after_password_reset = false
|
336
|
-
end
|
337
|
-
|
338
|
-
# it 'should have only one token' do
|
339
|
-
# assert_equal 1, @resource.tokens.count
|
340
|
-
# end
|
341
|
-
|
342
81
|
it 'new request should be successful' do
|
343
82
|
assert 200, response.status
|
344
83
|
end
|
@@ -353,139 +92,34 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
353
92
|
end
|
354
93
|
end
|
355
94
|
|
356
|
-
=begin
|
357
|
-
describe 'request including destroy of token' do
|
358
|
-
describe 'when change_headers_on_each_request is set to false' do
|
359
|
-
before do
|
360
|
-
DeviseJwtAuth.change_headers_on_each_request = false
|
361
|
-
# age_token(@resource, @client_id)
|
362
|
-
|
363
|
-
get '/demo/members_only_remove_token',
|
364
|
-
params: {},
|
365
|
-
headers: @auth_headers
|
366
|
-
end
|
367
|
-
|
368
|
-
after do
|
369
|
-
DeviseJwtAuth.change_headers_on_each_request = true
|
370
|
-
end
|
371
|
-
|
372
|
-
it 'should not return auth-headers' do
|
373
|
-
refute response.headers['access-token']
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
describe 'when change_headers_on_each_request is set to true' do
|
378
|
-
before do
|
379
|
-
# age_token(@resource, @client_id)
|
380
|
-
get '/demo/members_only_remove_token',
|
381
|
-
params: {},
|
382
|
-
headers: @auth_headers
|
383
|
-
end
|
384
|
-
|
385
|
-
it 'should not return auth-headers' do
|
386
|
-
refute response.headers['access-token']
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
=end
|
391
|
-
|
392
95
|
describe 'when access-token name has been changed' do
|
393
96
|
before do
|
394
|
-
# ensure that request is not treated as batch request
|
395
|
-
# DeviseJwtAuth.headers_names[:'access-token'] = 'new-access-token'
|
396
97
|
DeviseJwtAuth.access_token_name = 'new-access-token'
|
397
|
-
|
398
|
-
|
98
|
+
|
399
99
|
auth_headers_modified = @resource.create_named_token_pair
|
400
|
-
|
401
|
-
# client_id = auth_headers_modified['client']
|
402
|
-
# age_token(@resource, client_id)
|
403
|
-
|
100
|
+
|
404
101
|
get '/demo/members_only',
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
# @resp_token = response.headers['new-access-token']
|
102
|
+
params: {},
|
103
|
+
headers: auth_headers_modified
|
104
|
+
|
409
105
|
# TODO: do we want to send access-tokens with every response?
|
410
106
|
@data = JSON.parse(response.body)
|
411
107
|
end
|
412
|
-
=begin
|
413
|
-
it 'should have "new-access-token" in reponse' do
|
414
|
-
# assert @resp_token.present?
|
415
|
-
# assert @data['new-access-token']
|
416
|
-
end
|
417
|
-
=end
|
418
|
-
after do
|
419
|
-
# DeviseJwtAuth.headers_names[:'access-token'] = 'access-token'
|
420
|
-
DeviseJwtAuth.access_token_name = 'access-token'
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
=begin
|
425
|
-
describe 'maximum concurrent devices per user' do
|
426
|
-
before do
|
427
|
-
# Set the max_number_of_devices to a lower number
|
428
|
-
# to expedite tests! (Default is 10)
|
429
|
-
DeviseJwtAuth.max_number_of_devices = 5
|
430
|
-
end
|
431
|
-
|
432
|
-
it 'should limit the maximum number of concurrent devices' do
|
433
|
-
# increment the number of devices until the maximum is exceeded
|
434
|
-
1.upto(DeviseJwtAuth.max_number_of_devices + 1).each do |n|
|
435
|
-
|
436
|
-
assert_equal(
|
437
|
-
[n, DeviseJwtAuth.max_number_of_devices].min,
|
438
|
-
@resource.reload.tokens.length
|
439
|
-
)
|
440
|
-
|
441
|
-
# Add a new device (and token) ahead of the next iteration
|
442
|
-
# @resource.create_new_auth_token
|
443
|
-
create_token_header(@resource)
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
it 'should drop the oldest token when the maximum number of devices is exceeded' do
|
448
|
-
# create the maximum number of tokens
|
449
|
-
1.upto(DeviseJwtAuth.max_number_of_devices).each do
|
450
|
-
# @resource.create_new_auth_token
|
451
|
-
create_token_header(@resource)
|
452
|
-
end
|
453
|
-
|
454
|
-
# get the oldest token client_id
|
455
|
-
oldest_client_id, = @resource.reload.tokens.min_by do |cid, v|
|
456
|
-
v[:expiry] || v['expiry']
|
457
|
-
end # => [ 'CLIENT_ID', {token: ...} ]
|
458
|
-
|
459
|
-
# create another token, thereby dropping the oldest token
|
460
|
-
# @resource.create_new_auth_token
|
461
|
-
create_token_header(@resource)
|
462
|
-
|
463
|
-
assert_not_includes @resource.reload.tokens.keys, oldest_client_id
|
464
|
-
end
|
465
108
|
|
466
109
|
after do
|
467
|
-
DeviseJwtAuth.
|
110
|
+
DeviseJwtAuth.access_token_name = 'access-token'
|
468
111
|
end
|
469
112
|
end
|
470
|
-
=end
|
471
113
|
end
|
472
114
|
|
473
115
|
describe 'bypass_sign_in' do
|
474
116
|
before do
|
475
117
|
@resource = create(:user)
|
476
118
|
@auth_headers = @resource.create_named_token_pair
|
477
|
-
|
478
|
-
# @token = @auth_headers['access-token']
|
479
|
-
# @client_id = @auth_headers['client']
|
480
|
-
# @expiry = @auth_headers['expiry']
|
481
119
|
end
|
482
120
|
describe 'is default value (true)' do
|
483
121
|
before do
|
484
|
-
# age_token(@resource, @client_id)
|
485
|
-
|
486
122
|
get '/demo/members_only', params: {}, headers: @auth_headers
|
487
|
-
|
488
|
-
# @access_token = response.headers['access-token']
|
489
123
|
@response_status = response.status
|
490
124
|
end
|
491
125
|
|
@@ -493,10 +127,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
493
127
|
assert_equal 200, @response_status
|
494
128
|
end
|
495
129
|
|
496
|
-
# it 'should return auth headers' do
|
497
|
-
# assert @access_token
|
498
|
-
# end
|
499
|
-
|
500
130
|
it 'should set current user' do
|
501
131
|
assert_equal @controller.current_user, @resource
|
502
132
|
end
|
@@ -504,7 +134,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
504
134
|
describe 'is false' do
|
505
135
|
before do
|
506
136
|
DeviseJwtAuth.bypass_sign_in = false
|
507
|
-
# age_token(@resource, @client_id)
|
508
137
|
|
509
138
|
get '/demo/members_only', params: {}, headers: @auth_headers
|
510
139
|
|
@@ -541,11 +170,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
541
170
|
get '/demo/members_only',
|
542
171
|
params: {},
|
543
172
|
headers: nil
|
544
|
-
|
545
|
-
# @resp_token = response.headers['access-token']
|
546
|
-
# @resp_client_id = response.headers['client']
|
547
|
-
# @resp_expiry = response.headers['expiry']
|
548
|
-
# @resp_uid = response.headers['uid']
|
549
173
|
end
|
550
174
|
|
551
175
|
describe 'devise mappings' do
|
@@ -560,30 +184,11 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
560
184
|
it 'should not define current_mang' do
|
561
185
|
refute_equal @resource, @controller.current_mang
|
562
186
|
end
|
563
|
-
|
564
187
|
end
|
565
188
|
|
566
189
|
it 'should return success status' do
|
567
190
|
assert_equal 200, response.status
|
568
191
|
end
|
569
|
-
|
570
|
-
=begin
|
571
|
-
it 'should receive new token after successful request' do
|
572
|
-
assert @resp_token
|
573
|
-
end
|
574
|
-
|
575
|
-
it 'should set the token expiry in the auth header' do
|
576
|
-
assert @resp_expiry
|
577
|
-
end
|
578
|
-
|
579
|
-
it 'should return the client id in the auth header' do
|
580
|
-
assert @resp_client_id
|
581
|
-
end
|
582
|
-
|
583
|
-
it "should return the user's uid in the auth header" do
|
584
|
-
assert @resp_uid
|
585
|
-
end
|
586
|
-
=end
|
587
192
|
end
|
588
193
|
|
589
194
|
describe 'existing Warden authentication with ignored token data' do
|
@@ -594,11 +199,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
594
199
|
get '/demo/members_only',
|
595
200
|
params: {},
|
596
201
|
headers: @auth_headers
|
597
|
-
|
598
|
-
# @resp_token = response.headers['access-token']
|
599
|
-
# @resp_client_id = response.headers['client']
|
600
|
-
# @resp_expiry = response.headers['expiry']
|
601
|
-
# @resp_uid = response.headers['uid']
|
602
202
|
end
|
603
203
|
|
604
204
|
describe 'devise mappings' do
|
@@ -618,32 +218,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
618
218
|
it 'should return success status' do
|
619
219
|
assert_equal 200, response.status
|
620
220
|
end
|
621
|
-
|
622
|
-
=begin
|
623
|
-
it 'should receive new token after successful request' do
|
624
|
-
assert @resp_token
|
625
|
-
end
|
626
|
-
|
627
|
-
it 'should set the token expiry in the auth header' do
|
628
|
-
assert @resp_expiry
|
629
|
-
end
|
630
|
-
|
631
|
-
it 'should return the client id in the auth header' do
|
632
|
-
assert @resp_client_id
|
633
|
-
end
|
634
|
-
|
635
|
-
it "should not use the existing token's client" do
|
636
|
-
refute_equal @auth_headers['client'], @resp_client_id
|
637
|
-
end
|
638
|
-
|
639
|
-
it "should return the user's uid in the auth header" do
|
640
|
-
assert @resp_uid
|
641
|
-
end
|
642
|
-
|
643
|
-
it "should not return the token user's uid in the auth header" do
|
644
|
-
refute_equal @resp_uid, @auth_headers['uid']
|
645
|
-
end
|
646
|
-
=end
|
647
221
|
end
|
648
222
|
end
|
649
223
|
end
|
@@ -59,7 +59,7 @@ class DeviseJwtAuth::ConfirmationsControllerTest < ActionController::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
test 'redirect url includes token params' do
|
62
|
-
assert
|
62
|
+
assert(@token_params.all? { |param| response.body.include?(param) })
|
63
63
|
assert response.body.include?('account_confirmation_success')
|
64
64
|
end
|
65
65
|
end
|
@@ -84,7 +84,7 @@ class DeviseJwtAuth::ConfirmationsControllerTest < ActionController::TestCase
|
|
84
84
|
end
|
85
85
|
|
86
86
|
test 'redirect url does not include token params' do
|
87
|
-
refute
|
87
|
+
refute(@token_params.any? { |param| response.body.include?(param) })
|
88
88
|
assert response.body.include?('account_confirmation_success')
|
89
89
|
end
|
90
90
|
end
|
@@ -92,9 +92,9 @@ class DeviseJwtAuth::ConfirmationsControllerTest < ActionController::TestCase
|
|
92
92
|
describe 'resend confirmation' do
|
93
93
|
before do
|
94
94
|
post :create,
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
params: { email: @new_user.email,
|
96
|
+
redirect_url: @redirect_url },
|
97
|
+
xhr: true
|
98
98
|
@resource = assigns(:resource)
|
99
99
|
|
100
100
|
@mail = ActionMailer::Base.deliveries.last
|
@@ -14,11 +14,11 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
14
14
|
end
|
15
15
|
|
16
16
|
before do
|
17
|
-
@redirect_url = 'http://ng-
|
17
|
+
@redirect_url = 'http://ng-jwt-auth.dev/'
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_parsed_data_json
|
21
|
-
encoded_json_data = @response.body.match(/var data
|
21
|
+
encoded_json_data = @response.body.match(/var data = JSON.parse\(decodeURIComponent\('(.+)'\)\);/)[1]
|
22
22
|
JSON.parse(URI.unescape(encoded_json_data))
|
23
23
|
end
|
24
24
|
|
@@ -58,8 +58,8 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
58
58
|
|
59
59
|
test 'session vars have been cleared' do
|
60
60
|
get_success
|
61
|
-
refute request.session['
|
62
|
-
refute request.session['
|
61
|
+
refute request.session['dja.omniauth.auth']
|
62
|
+
refute request.session['dja.omniauth.params']
|
63
63
|
end
|
64
64
|
|
65
65
|
test 'sign_in was called' do
|
@@ -286,9 +286,9 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
286
286
|
describe 'failure callback' do
|
287
287
|
setup do
|
288
288
|
OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
|
289
|
-
OmniAuth.config.on_failure = proc
|
289
|
+
OmniAuth.config.on_failure = proc do |env|
|
290
290
|
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
|
291
|
-
|
291
|
+
end
|
292
292
|
end
|
293
293
|
|
294
294
|
test 'renders expected data' do
|
@@ -331,8 +331,7 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
331
331
|
end
|
332
332
|
|
333
333
|
describe 'Using redirect_whitelist' do
|
334
|
-
|
335
|
-
describe "newWindow" do
|
334
|
+
describe 'newWindow' do
|
336
335
|
before do
|
337
336
|
@user_email = 'slemp.diggler@sillybandz.gov'
|
338
337
|
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(
|
@@ -361,7 +360,7 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
361
360
|
|
362
361
|
data = get_parsed_data_json
|
363
362
|
assert_equal "Redirect to '#{@bad_redirect_url}' not allowed.",
|
364
|
-
|
363
|
+
data['error']
|
365
364
|
# TODO: parse data and assert no access or refresh tokens were sent.
|
366
365
|
end
|
367
366
|
|
@@ -395,7 +394,7 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
395
394
|
end
|
396
395
|
end
|
397
396
|
|
398
|
-
describe
|
397
|
+
describe 'sameWindow' do
|
399
398
|
before do
|
400
399
|
@user_email = 'slemp.diggler@sillybandz.gov'
|
401
400
|
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(
|