devise_jwt_auth 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/app/controllers/devise_jwt_auth/application_controller.rb +15 -13
  4. data/app/controllers/devise_jwt_auth/concerns/resource_finder.rb +2 -6
  5. data/app/controllers/devise_jwt_auth/concerns/{set_user_by_jwt_token.rb → set_user_by_token.rb} +23 -19
  6. data/app/controllers/devise_jwt_auth/confirmations_controller.rb +10 -19
  7. data/app/controllers/devise_jwt_auth/omniauth_callbacks_controller.rb +32 -33
  8. data/app/controllers/devise_jwt_auth/passwords_controller.rb +29 -19
  9. data/app/controllers/devise_jwt_auth/refresh_token_controller.rb +4 -1
  10. data/app/controllers/devise_jwt_auth/registrations_controller.rb +40 -21
  11. data/app/controllers/devise_jwt_auth/sessions_controller.rb +21 -21
  12. data/app/controllers/devise_jwt_auth/unlocks_controller.rb +5 -4
  13. data/app/models/devise_jwt_auth/concerns/active_record_support.rb +3 -0
  14. data/app/models/devise_jwt_auth/concerns/confirmable_support.rb +7 -4
  15. data/app/models/devise_jwt_auth/concerns/mongoid_support.rb +3 -0
  16. data/app/models/devise_jwt_auth/concerns/tokens_serialization.rb +4 -1
  17. data/app/models/devise_jwt_auth/concerns/user.rb +18 -9
  18. data/app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb +11 -3
  19. data/app/validators/devise_jwt_auth_email_validator.rb +5 -4
  20. data/lib/devise_jwt_auth/blacklist.rb +2 -0
  21. data/lib/devise_jwt_auth/controllers/url_helpers.rb +1 -2
  22. data/lib/devise_jwt_auth/engine.rb +4 -4
  23. data/lib/devise_jwt_auth/rails/routes.rb +35 -24
  24. data/lib/devise_jwt_auth/token_factory.rb +3 -2
  25. data/lib/devise_jwt_auth/url.rb +2 -4
  26. data/lib/devise_jwt_auth/version.rb +1 -1
  27. data/lib/generators/devise_jwt_auth/install_generator.rb +7 -6
  28. data/lib/generators/devise_jwt_auth/install_generator_helpers.rb +27 -6
  29. data/lib/generators/devise_jwt_auth/install_mongoid_generator.rb +3 -2
  30. data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth.rb +15 -16
  31. data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth_create_users.rb.erb +15 -11
  32. data/lib/generators/devise_jwt_auth/templates/user.rb.erb +2 -2
  33. data/test/controllers/custom/custom_confirmations_controller_test.rb +2 -2
  34. data/test/controllers/custom/custom_passwords_controller_test.rb +4 -4
  35. data/test/controllers/custom/custom_refresh_token_controller_test.rb +2 -3
  36. data/test/controllers/custom/custom_registrations_controller_test.rb +2 -2
  37. data/test/controllers/demo_mang_controller_test.rb +206 -210
  38. data/test/controllers/demo_user_controller_test.rb +358 -374
  39. data/test/controllers/devise_jwt_auth/confirmations_controller_test.rb +5 -5
  40. data/test/controllers/devise_jwt_auth/omniauth_callbacks_controller_test.rb +6 -7
  41. data/test/controllers/devise_jwt_auth/passwords_controller_test.rb +11 -13
  42. data/test/controllers/devise_jwt_auth/refresh_token_controller_test.rb +8 -12
  43. data/test/controllers/devise_jwt_auth/registrations_controller_test.rb +23 -25
  44. data/test/controllers/devise_jwt_auth/sessions_controller_test.rb +32 -34
  45. data/test/controllers/devise_jwt_auth/unlocks_controller_test.rb +2 -2
  46. data/test/controllers/overrides/confirmations_controller_test.rb +1 -1
  47. data/test/controllers/overrides/passwords_controller_test.rb +1 -1
  48. data/test/controllers/overrides/refresh_token_controller_test.rb +1 -2
  49. data/test/controllers/overrides/registrations_controller_test.rb +1 -1
  50. data/test/dummy/app/controllers/application_controller.rb +1 -1
  51. data/test/dummy/app/controllers/custom/refresh_token_controller.rb +2 -1
  52. data/test/dummy/app/controllers/custom/registrations_controller.rb +1 -1
  53. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +4 -4
  54. data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +4 -4
  55. data/test/dummy/app/controllers/overrides/passwords_controller.rb +4 -4
  56. data/test/dummy/app/controllers/overrides/refresh_token_controller.rb +1 -1
  57. data/test/dummy/app/controllers/overrides/registrations_controller.rb +2 -2
  58. data/test/dummy/app/controllers/overrides/sessions_controller.rb +2 -2
  59. data/test/dummy/app/models/concerns/favorite_color.rb +11 -9
  60. data/test/dummy/config.ru +2 -2
  61. data/test/dummy/config/application.rb +1 -0
  62. data/test/dummy/config/boot.rb +1 -1
  63. data/test/dummy/config/environments/test.rb +11 -7
  64. data/test/dummy/config/initializers/figaro.rb +1 -1
  65. data/test/dummy/config/initializers/omniauth.rb +2 -2
  66. data/test/dummy/config/routes.rb +8 -8
  67. data/test/dummy/db/migrate/{20140715061447_devise_token_auth_create_users.rb → 20140715061447_devise_jwt_auth_create_users.rb} +0 -0
  68. data/test/dummy/db/migrate/{20140715061805_devise_token_auth_create_mangs.rb → 20140715061805_devise_jwt_auth_create_mangs.rb} +0 -0
  69. data/test/dummy/db/migrate/{20141222035835_devise_token_auth_create_only_email_users.rb → 20141222035835_devise_jwt_auth_create_only_email_users.rb} +9 -9
  70. data/test/dummy/db/migrate/{20141222053502_devise_token_auth_create_unregisterable_users.rb → 20141222053502_devise_jwt_auth_create_unregisterable_users.rb} +0 -0
  71. data/test/dummy/db/migrate/{20150708104536_devise_token_auth_create_unconfirmable_users.rb → 20150708104536_devise_jwt_auth_create_unconfirmable_users.rb} +0 -0
  72. data/test/dummy/db/migrate/{20160103235141_devise_token_auth_create_scoped_users.rb → 20160103235141_devise_jwt_auth_create_scoped_users.rb} +0 -0
  73. data/test/dummy/db/migrate/{20160629184441_devise_token_auth_create_lockable_users.rb → 20160629184441_devise_jwt_auth_create_lockable_users.rb} +0 -0
  74. data/test/dummy/db/migrate/{20190924101113_devise_token_auth_create_confirmable_users.rb → 20190924101113_devise_jwt_auth_create_confirmable_users.rb} +6 -5
  75. data/test/dummy/db/schema.rb +170 -170
  76. data/test/dummy/tmp/generators/app/controllers/application_controller.rb +6 -0
  77. data/test/dummy/tmp/generators/app/models/user.rb +9 -0
  78. data/test/dummy/tmp/generators/config/initializers/devise_jwt_auth.rb +73 -0
  79. data/test/dummy/tmp/generators/db/migrate/20201006030349_devise_jwt_auth_create_users.rb +54 -0
  80. data/test/factories/users.rb +5 -3
  81. data/test/lib/devise_jwt_auth/token_factory_test.rb +6 -6
  82. data/test/lib/generators/devise_jwt_auth/install_generator_test.rb +3 -20
  83. data/test/lib/generators/devise_jwt_auth/install_generator_with_namespace_test.rb +4 -21
  84. data/test/models/concerns/tokens_serialization_test.rb +68 -68
  85. data/test/models/user_test.rb +35 -37
  86. data/test/support/controllers/routes.rb +7 -5
  87. data/test/test_helper.rb +1 -1
  88. metadata +70 -76
@@ -15,7 +15,7 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
15
15
  before do
16
16
  @resource = create(:user, :confirmed)
17
17
  @auth_headers = @resource.create_named_token_pair
18
-
18
+
19
19
  # @token = @auth_headers['access-token']
20
20
  # @client_id = @auth_headers['client']
21
21
  # @expiry = @auth_headers['expiry']
@@ -58,43 +58,41 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
58
58
  assert_equal 200, response.status
59
59
  end
60
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
61
+ # it 'should receive new token after successful request' do
62
+ # refute_equal @token, @resp_token
63
+ # end
64
+ #
65
+ # it 'should preserve the client id from the first request' do
66
+ # assert_equal @client_id, @resp_client_id
67
+ # end
68
+ #
69
+ # it "should return the user's uid in the auth header" do
70
+ # assert_equal @resource.uid, @resp_uid
71
+ # end
72
+ #
73
+ # it 'should not treat this request as a batch request' do
74
+ # refute assigns(:is_batch_request)
75
+ # end
76
+ #
77
+ # describe 'subsequent requests' do
78
+ # before do
79
+ # @resource.reload
80
+ # # ensure that request is not treated as batch request
81
+ # # age_token(@resource, @client_id)
82
+ #
83
+ # get '/demo/members_only',
84
+ # params: {},
85
+ # headers: @auth_headers.merge('access-token' => @resp_token)
86
+ # end
87
+ #
88
+ # it 'should not treat this request as a batch request' do
89
+ # refute assigns(:is_batch_request)
90
+ # end
91
+ #
92
+ # it 'should allow a new request to be made using new token' do
93
+ # assert_equal 200, response.status
94
+ # end
95
+ # end
98
96
  end
99
97
 
100
98
  describe 'failed request' do
@@ -112,204 +110,202 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
112
110
  assert_equal 401, response.status
113
111
  end
114
112
  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
113
+ # describe 'disable change_headers_on_each_request' do
114
+ # before do
115
+ # DeviseJwtAuth.change_headers_on_each_request = false
116
+ # @resource.reload
117
+ # # age_token(@resource, @client_id)
118
+ #
119
+ # get '/demo/members_only',
120
+ # params: {},
121
+ # headers: @auth_headers
122
+ #
123
+ # @first_is_batch_request = assigns(:is_batch_request)
124
+ # @first_user = assigns(:resource).dup
125
+ # @first_access_token = response.headers['access-token']
126
+ # @first_response_status = response.status
127
+ #
128
+ # @resource.reload
129
+ # # age_token(@resource, @client_id)
130
+ #
131
+ # # use expired auth header
132
+ # get '/demo/members_only',
133
+ # params: {},
134
+ # headers: @auth_headers
135
+ #
136
+ # @second_is_batch_request = assigns(:is_batch_request)
137
+ # @second_user = assigns(:resource).dup
138
+ # @second_access_token = response.headers['access-token']
139
+ # @second_response_status = response.status
140
+ # end
141
+ #
142
+ # after do
143
+ # DeviseJwtAuth.change_headers_on_each_request = true
144
+ # end
145
+ #
146
+ # it 'should allow the first request through' do
147
+ # assert_equal 200, @first_response_status
148
+ # end
149
+ #
150
+ # it 'should allow the second request through' do
151
+ # assert_equal 200, @second_response_status
152
+ # end
153
+ #
154
+ # it 'should return auth headers from the first request' do
155
+ # assert @first_access_token
156
+ # end
157
+ #
158
+ # it 'should not treat either requests as batch requests' do
159
+ # refute @first_is_batch_request
160
+ # refute @second_is_batch_request
161
+ # end
162
+ #
163
+ # it 'should return auth headers from the second request' do
164
+ # assert @second_access_token
165
+ # end
166
+ #
167
+ # it 'should define user during first request' do
168
+ # assert @first_user
169
+ # end
170
+ #
171
+ # it 'should define user during second request' do
172
+ # assert @second_user
173
+ # end
174
+ # end
175
+ #
176
+ # describe 'batch requests' do
177
+ # describe 'success' do
178
+ # before do
179
+ # # age_token(@resource, @client_id)
180
+ #
181
+ # get '/demo/members_only',
182
+ # params: {},
183
+ # headers: @auth_headers
184
+ #
185
+ # @first_is_batch_request = assigns(:is_batch_request)
186
+ # @first_user = assigns(:resource)
187
+ # @first_access_token = response.headers['access-token']
188
+ #
189
+ # get '/demo/members_only',
190
+ # params: {},
191
+ # headers: @auth_headers
192
+ #
193
+ # @second_is_batch_request = assigns(:is_batch_request)
194
+ # @second_user = assigns(:resource)
195
+ # @second_access_token = response.headers['access-token']
196
+ # end
197
+ #
198
+ # it 'should allow both requests through' do
199
+ # assert_equal 200, response.status
200
+ # end
201
+ #
202
+ # it 'should not treat the first request as a batch request' do
203
+ # refute @first_is_batch_request
204
+ # end
205
+ #
206
+ # it 'should treat the second request as a batch request' do
207
+ # assert @second_is_batch_request
208
+ # end
209
+ #
210
+ # it 'should return access token for first (non-batch) request' do
211
+ # assert @first_access_token
212
+ # end
213
+ #
214
+ # it 'should not return auth headers for second (batched) requests' do
215
+ # assert_equal ' ', @second_access_token
216
+ # end
217
+ # end
218
+ #
219
+ # describe 'unbatch' do
220
+ # before do
221
+ # @resource.reload
222
+ # # age_token(@resource, @client_id)
223
+ #
224
+ # get '/demo/members_only',
225
+ # params: {},
226
+ # headers: @auth_headers
227
+ #
228
+ # @first_is_batch_request = assigns(:is_batch_request)
229
+ # @first_user = assigns(:resource).dup
230
+ # @first_access_token = response.headers['access-token']
231
+ # @first_response_status = response.status
232
+ #
233
+ # get '/demo/members_only?unbatch=true',
234
+ # params: {},
235
+ # headers: @auth_headers
236
+ #
237
+ # @second_is_batch_request = assigns(:is_batch_request)
238
+ # @second_user = assigns(:resource)
239
+ # @second_access_token = response.headers['access-token']
240
+ # @second_response_status = response.status
241
+ # end
242
+ #
243
+ # it 'should NOT treat the second request as a batch request when "unbatch" param is set' do
244
+ # refute @second_is_batch_request
245
+ # end
246
+ # end
247
+ #
248
+ # describe 'time out' do
249
+ # before do
250
+ # @resource.reload
251
+ # # age_token(@resource, @client_id)
252
+ #
253
+ # get '/demo/members_only',
254
+ # params: {},
255
+ # headers: @auth_headers
256
+ #
257
+ # @first_is_batch_request = assigns(:is_batch_request)
258
+ # @first_user = assigns(:resource).dup
259
+ # @first_access_token = response.headers['access-token']
260
+ # @first_response_status = response.status
261
+ #
262
+ # @resource.reload
263
+ # # age_token(@resource, @client_id)
264
+ #
265
+ # # use expired auth header
266
+ # get '/demo/members_only',
267
+ # params: {},
268
+ # headers: @auth_headers
269
+ #
270
+ # @second_is_batch_request = assigns(:is_batch_request)
271
+ # @second_user = assigns(:resource)
272
+ # @second_access_token = response.headers['access-token']
273
+ # @second_response_status = response.status
274
+ # end
275
+ #
276
+ # it 'should allow the first request through' do
277
+ # assert_equal 200, @first_response_status
278
+ # end
279
+ #
280
+ # it 'should not allow the second request through' do
281
+ # assert_equal 401, @second_response_status
282
+ # end
283
+ #
284
+ # it 'should not treat first request as batch request' do
285
+ # refute @second_is_batch_request
286
+ # end
287
+ #
288
+ # it 'should return auth headers from the first request' do
289
+ # assert @first_access_token
290
+ # end
291
+ #
292
+ # it 'should not treat second request as batch request' do
293
+ # refute @second_is_batch_request
294
+ # end
295
+ #
296
+ # it 'should not return auth headers from the second request' do
297
+ # refute @second_access_token
298
+ # end
299
+ #
300
+ # it 'should define user during first request' do
301
+ # assert @first_user
302
+ # end
303
+ #
304
+ # it 'should not define user during second request' do
305
+ # refute @second_user
306
+ # end
307
+ # end
308
+ # end
313
309
 
314
310
  describe 'successful password change' do
315
311
  before do
@@ -353,121 +349,114 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
353
349
  end
354
350
  end
355
351
 
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
352
+ # describe 'request including destroy of token' do
353
+ # describe 'when change_headers_on_each_request is set to false' do
354
+ # before do
355
+ # DeviseJwtAuth.change_headers_on_each_request = false
356
+ # # age_token(@resource, @client_id)
357
+ #
358
+ # get '/demo/members_only_remove_token',
359
+ # params: {},
360
+ # headers: @auth_headers
361
+ # end
362
+ #
363
+ # after do
364
+ # DeviseJwtAuth.change_headers_on_each_request = true
365
+ # end
366
+ #
367
+ # it 'should not return auth-headers' do
368
+ # refute response.headers['access-token']
369
+ # end
370
+ # end
371
+ #
372
+ # describe 'when change_headers_on_each_request is set to true' do
373
+ # before do
374
+ # # age_token(@resource, @client_id)
375
+ # get '/demo/members_only_remove_token',
376
+ # params: {},
377
+ # headers: @auth_headers
378
+ # end
379
+ #
380
+ # it 'should not return auth-headers' do
381
+ # refute response.headers['access-token']
382
+ # end
383
+ # end
384
+ # end
391
385
 
392
386
  describe 'when access-token name has been changed' do
393
387
  before do
394
388
  # ensure that request is not treated as batch request
395
389
  # DeviseJwtAuth.headers_names[:'access-token'] = 'new-access-token'
396
390
  DeviseJwtAuth.access_token_name = 'new-access-token'
397
-
398
-
391
+
399
392
  auth_headers_modified = @resource.create_named_token_pair
400
-
393
+
401
394
  # client_id = auth_headers_modified['client']
402
395
  # age_token(@resource, client_id)
403
-
396
+
404
397
  get '/demo/members_only',
405
- params: {},
406
- headers: auth_headers_modified
407
-
398
+ params: {},
399
+ headers: auth_headers_modified
400
+
408
401
  # @resp_token = response.headers['new-access-token']
409
402
  # TODO: do we want to send access-tokens with every response?
410
403
  @data = JSON.parse(response.body)
411
404
  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
405
+ # it 'should have "new-access-token" in reponse' do
406
+ # # assert @resp_token.present?
407
+ # # assert @data['new-access-token']
408
+ # end
418
409
  after do
419
410
  # DeviseJwtAuth.headers_names[:'access-token'] = 'access-token'
420
411
  DeviseJwtAuth.access_token_name = 'access-token'
421
412
  end
422
413
  end
423
414
 
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
-
466
- after do
467
- DeviseJwtAuth.max_number_of_devices = 10
468
- end
469
- end
470
- =end
415
+ # describe 'maximum concurrent devices per user' do
416
+ # before do
417
+ # # Set the max_number_of_devices to a lower number
418
+ # # to expedite tests! (Default is 10)
419
+ # DeviseJwtAuth.max_number_of_devices = 5
420
+ # end
421
+ #
422
+ # it 'should limit the maximum number of concurrent devices' do
423
+ # # increment the number of devices until the maximum is exceeded
424
+ # 1.upto(DeviseJwtAuth.max_number_of_devices + 1).each do |n|
425
+ #
426
+ # assert_equal(
427
+ # [n, DeviseJwtAuth.max_number_of_devices].min,
428
+ # @resource.reload.tokens.length
429
+ # )
430
+ #
431
+ # # Add a new device (and token) ahead of the next iteration
432
+ # # @resource.create_new_auth_token
433
+ # create_token_header(@resource)
434
+ # end
435
+ # end
436
+ #
437
+ # it 'should drop the oldest token when the maximum number of devices is exceeded' do
438
+ # # create the maximum number of tokens
439
+ # 1.upto(DeviseJwtAuth.max_number_of_devices).each do
440
+ # # @resource.create_new_auth_token
441
+ # create_token_header(@resource)
442
+ # end
443
+ #
444
+ # # get the oldest token client_id
445
+ # oldest_client_id, = @resource.reload.tokens.min_by do |cid, v|
446
+ # v[:expiry] || v['expiry']
447
+ # end # => [ 'CLIENT_ID', {token: ...} ]
448
+ #
449
+ # # create another token, thereby dropping the oldest token
450
+ # # @resource.create_new_auth_token
451
+ # create_token_header(@resource)
452
+ #
453
+ # assert_not_includes @resource.reload.tokens.keys, oldest_client_id
454
+ # end
455
+ #
456
+ # after do
457
+ # DeviseJwtAuth.max_number_of_devices = 10
458
+ # end
459
+ # end
471
460
  end
472
461
 
473
462
  describe 'bypass_sign_in' do
@@ -560,30 +549,27 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
560
549
  it 'should not define current_mang' do
561
550
  refute_equal @resource, @controller.current_mang
562
551
  end
563
-
564
552
  end
565
553
 
566
554
  it 'should return success status' do
567
555
  assert_equal 200, response.status
568
556
  end
569
557
 
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
558
+ # it 'should receive new token after successful request' do
559
+ # assert @resp_token
560
+ # end
561
+ #
562
+ # it 'should set the token expiry in the auth header' do
563
+ # assert @resp_expiry
564
+ # end
565
+ #
566
+ # it 'should return the client id in the auth header' do
567
+ # assert @resp_client_id
568
+ # end
569
+ #
570
+ # it "should return the user's uid in the auth header" do
571
+ # assert @resp_uid
572
+ # end
587
573
  end
588
574
 
589
575
  describe 'existing Warden authentication with ignored token data' do
@@ -619,31 +605,29 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
619
605
  assert_equal 200, response.status
620
606
  end
621
607
 
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
608
+ # it 'should receive new token after successful request' do
609
+ # assert @resp_token
610
+ # end
611
+ #
612
+ # it 'should set the token expiry in the auth header' do
613
+ # assert @resp_expiry
614
+ # end
615
+ #
616
+ # it 'should return the client id in the auth header' do
617
+ # assert @resp_client_id
618
+ # end
619
+ #
620
+ # it "should not use the existing token's client" do
621
+ # refute_equal @auth_headers['client'], @resp_client_id
622
+ # end
623
+ #
624
+ # it "should return the user's uid in the auth header" do
625
+ # assert @resp_uid
626
+ # end
627
+ #
628
+ # it "should not return the token user's uid in the auth header" do
629
+ # refute_equal @resp_uid, @auth_headers['uid']
630
+ # end
647
631
  end
648
632
  end
649
633
  end