devise_jwt_auth 0.1.1 → 0.1.6

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.
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
@@ -5,38 +5,38 @@ DeviseJwtAuth.setup do |config|
5
5
  # user. To receive new access tokens, you should either reauthenticate or
6
6
  # use the HTTP only refresh cookie that is sent during the authentication
7
7
  # process and make refresh token requests.
8
- # self.send_new_access_token_on_each_request = false
9
-
8
+ # config.send_new_access_token_on_each_request = false
9
+
10
10
  # By default, refresh token HTTP Only cookies last for 2 weeks. These tokens
11
11
  # are used for requesting shorter-lived acccess tokens.
12
- # self.refresh_token_lifespan = 2.weeks
12
+ # config.refresh_token_lifespan = 2.weeks
13
13
 
14
14
  # By default, access tokens last for 15 minutes. These tokens are used to
15
15
  # access protected resources. When these tokens expire, you need to
16
16
  # reauthenticate the user or use a refresh token cookie to get a new access
17
17
  # token.
18
- # self.access_token_lifespan = 15.minutes
18
+ # config.access_token_lifespan = 15.minutes
19
19
 
20
20
  # This is the name of the HTTP Only cookie that will be sent to the client
21
21
  # for the purpose of requesting new access tokens.
22
- # self.refresh_token_name = 'refresh-token'
22
+ # config.refresh_token_name = 'refresh-token'
23
23
 
24
24
  # This is the name of the token that will be sent in the JSON responses used
25
25
  # for accessing protected resources. NEVER store this token in a cookie or
26
26
  # any form of local storage on the client. Save it in memory as a javascript
27
27
  # variable or in some kind of context manager like Redux. Send it in your
28
28
  # request headers when you want to be authenticated.
29
- # self.access_token_name = 'access-token'
29
+ # config.access_token_name = 'access-token'
30
30
 
31
31
  # This is the refresh token encryption key. You should set this in an
32
32
  # environment variable or secret key base that isn't store in a repository.
33
33
  # Also, its a good idea to NOT use the same key for access tokens.
34
- self.refresh_token_encryption_key = 'your-refresh-token-secret-key-here'
35
-
34
+ config.refresh_token_encryption_key = 'your-refresh-token-secret-key-here'
35
+
36
36
  # This is the refresh token encryption key. You should set this in an
37
37
  # environment variable or secret key base that isn't store in a repository.
38
38
  # Also, its a good idea to NOT use the same key for access tokens.
39
- self.access_token_encryption_key = 'your-access-token-secret-key-here'
39
+ config.access_token_encryption_key = 'your-access-token-secret-key-here'
40
40
 
41
41
  # This route will be the prefix for all oauth2 redirect callbacks. For
42
42
  # example, using the default '/omniauth', the github oauth2 provider will
@@ -64,11 +64,10 @@ DeviseJwtAuth.setup do |config|
64
64
  # config.send_confirmation_email = true
65
65
 
66
66
  # TODO: Document these settings
67
- # self.default_confirm_success_url = nil
68
- # self.default_password_reset_url = nil
69
- # self.redirect_whitelist = nil
70
- # self.update_token_version_after_password_reset = true
71
- # self.bypass_sign_in = true
72
- # self.require_client_password_reset_token = false
73
-
67
+ # config.default_confirm_success_url = nil
68
+ # config.default_password_reset_url = nil
69
+ # config.redirect_whitelist = nil
70
+ # config.update_token_version_after_password_reset = true
71
+ # config.bypass_sign_in = true
72
+ # config.require_client_password_reset_token = false
74
73
  end
@@ -2,12 +2,18 @@
2
2
 
3
3
  class DeviseJwtAuthCreate<%= user_class.pluralize.gsub("::","") %> < ActiveRecord::Migration<%= "[#{Rails::VERSION::STRING[0..2]}]" if Rails::VERSION::MAJOR > 4 %>
4
4
  def change
5
- <% table_name = @user_class.pluralize.gsub("::","").underscore %>
6
- create_table(:<%= table_name %><%= primary_key_type %>) do |t|
5
+ <% table_name = @user_class.pluralize.gsub("::","").underscore -%>
6
+ create_table(:<%= table_name %><%= primary_key_type %>) do |t|
7
7
  ## Required
8
8
  t.string :provider, null: false, default: 'email'
9
9
  t.string :uid, null: false, default: ''
10
10
 
11
+ ## User Info
12
+ t.string :name
13
+ t.string :nickname
14
+ t.string :image
15
+ t.string :email
16
+
11
17
  ## Database authenticatable
12
18
  t.string :encrypted_password, null: false, default: ''
13
19
 
@@ -19,6 +25,13 @@ class DeviseJwtAuthCreate<%= user_class.pluralize.gsub("::","") %> < ActiveRecor
19
25
  ## Rememberable
20
26
  t.datetime :remember_created_at
21
27
 
28
+ ## Trackable
29
+ # t.integer :sign_in_count, default: 0, null: false
30
+ # t.datetime :current_sign_in_at
31
+ # t.datetime :last_sign_in_at
32
+ # t.<%= ip_column %> :current_sign_in_ip
33
+ # t.<%= ip_column %> :last_sign_in_ip
34
+
22
35
  ## Confirmable
23
36
  t.string :confirmation_token
24
37
  t.datetime :confirmed_at
@@ -30,15 +43,6 @@ class DeviseJwtAuthCreate<%= user_class.pluralize.gsub("::","") %> < ActiveRecor
30
43
  # t.string :unlock_token # Only if unlock strategy is :email or :both
31
44
  # t.datetime :locked_at
32
45
 
33
- ## User Info
34
- t.string :name
35
- t.string :nickname
36
- t.string :image
37
- t.string :email
38
-
39
- ## Tokens
40
- <%= json_supported_database? ? 't.json :tokens' : 't.text :tokens' %>
41
-
42
46
  t.timestamps
43
47
  end
44
48
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  class <%= user_class %> < ActiveRecord::Base
4
4
  # Include default devise modules. Others available are:
5
- # :confirmable, :lockable, :timeoutable and :omniauthable
5
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
6
6
  devise :database_authenticatable, :registerable,
7
- :recoverable, :rememberable, :trackable, :validatable
7
+ :recoverable, :rememberable, :validatable
8
8
  include DeviseJwtAuth::Concerns::User
9
9
  end
@@ -10,8 +10,8 @@ class Custom::ConfirmationsControllerTest < ActionController::TestCase
10
10
  @redirect_url = Faker::Internet.url
11
11
  @new_user = create(:user)
12
12
  @new_user.send_confirmation_instructions(redirect_url: @redirect_url)
13
- @mail = ActionMailer::Base.deliveries.last
14
- @token = @mail.body.match(/confirmation_token=([^&]*)&/)[1]
13
+ @mail = ActionMailer::Base.deliveries.last
14
+ @token = @mail.body.match(/confirmation_token=([^&]*)&/)[1]
15
15
  @client_config = @mail.body.match(/config=([^&]*)&/)[1]
16
16
 
17
17
  get :show,
@@ -13,7 +13,7 @@ class Custom::PasswordsControllerTest < ActionController::TestCase
13
13
 
14
14
  test 'yield resource to block on create success' do
15
15
  post :create,
16
- params: { email: @resource.email,
16
+ params: { email: @resource.email,
17
17
  redirect_url: @redirect_url }
18
18
 
19
19
  @mail = ActionMailer::Base.deliveries.last
@@ -21,7 +21,7 @@ class Custom::PasswordsControllerTest < ActionController::TestCase
21
21
 
22
22
  @mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
23
23
  @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
24
- @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
24
+ @mail_reset_token = @mail.body.match(/reset_password_token=(.*)"/)[1]
25
25
 
26
26
  assert @controller.create_block_called?,
27
27
  'create failed to yield resource to provided block'
@@ -32,7 +32,7 @@ class Custom::PasswordsControllerTest < ActionController::TestCase
32
32
  @redirect_url = 'http://ng-token-auth.dev'
33
33
 
34
34
  post :create,
35
- params: { email: @resource.email,
35
+ params: { email: @resource.email,
36
36
  redirect_url: @redirect_url },
37
37
  xhr: true
38
38
 
@@ -41,7 +41,7 @@ class Custom::PasswordsControllerTest < ActionController::TestCase
41
41
 
42
42
  @mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
43
43
  @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
44
- @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
44
+ @mail_reset_token = @mail.body.match(/reset_password_token=(.*)"/)[1]
45
45
 
46
46
  get :edit,
47
47
  params: { reset_password_token: @mail_reset_token,
@@ -9,8 +9,7 @@ class Custom::RefreshTokenControllerTest < ActionDispatch::IntegrationTest
9
9
  before do
10
10
  @resource = create(:user, :confirmed)
11
11
  @auth_headers = get_cookie_header(DeviseJwtAuth.refresh_token_name,
12
- @resource.create_refresh_token
13
- )
12
+ @resource.create_refresh_token)
14
13
  end
15
14
 
16
15
  test 'yield resource to block on refresh_token success' do
@@ -33,4 +32,4 @@ class Custom::RefreshTokenControllerTest < ActionDispatch::IntegrationTest
33
32
  assert_equal @data['custom'], 'foo'
34
33
  end
35
34
  end
36
- end
35
+ end
@@ -8,8 +8,8 @@ class Custom::RegistrationsControllerTest < ActionDispatch::IntegrationTest
8
8
 
9
9
  before do
10
10
  @create_params = attributes_for(:user,
11
- confirm_success_url: Faker::Internet.url,
12
- unpermitted_param: '(x_x)')
11
+ confirm_success_url: Faker::Internet.url,
12
+ unpermitted_param: '(x_x)')
13
13
 
14
14
  @existing_user = create(:user, :confirmed)
15
15
  @auth_headers = @existing_user.create_named_token_pair
@@ -39,61 +39,59 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
39
39
  it 'should define current_mang' do
40
40
  assert_equal @resource, @controller.current_mang
41
41
  end
42
-
42
+
43
43
  it 'should define mang_signed_in?' do
44
44
  assert @controller.mang_signed_in?
45
45
  end
46
-
46
+
47
47
  it 'should not define current_user' do
48
48
  refute_equal @resource, @controller.current_user
49
49
  end
50
-
50
+
51
51
  it 'should define render_authenticate_error' do
52
52
  assert @controller.methods.include?(:render_authenticate_error)
53
53
  end
54
54
  end
55
-
55
+
56
56
  it 'should return success status' do
57
57
  assert_equal 200, response.status
58
58
  end
59
-
60
- =begin
61
- it 'should receive new token after successful request' do
62
- refute_equal @token, @resp_token
63
- end
64
59
 
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_mang',
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
96
- =end
60
+ # it 'should receive new token after successful request' do
61
+ # refute_equal @token, @resp_token
62
+ # end
63
+ #
64
+ # it 'should preserve the client id from the first request' do
65
+ # assert_equal @client_id, @resp_client_id
66
+ # end
67
+ #
68
+ # it "should return the user's uid in the auth header" do
69
+ # assert_equal @resource.uid, @resp_uid
70
+ # end
71
+ #
72
+ # it 'should not treat this request as a batch request' do
73
+ # refute assigns(:is_batch_request)
74
+ # end
75
+ #
76
+ # describe 'subsequent requests' do
77
+ # before do
78
+ # @resource.reload
79
+ # # ensure that request is not treated as batch request
80
+ # # age_token(@resource, @client_id)
81
+ #
82
+ # get '/demo/members_only_mang',
83
+ # params: {},
84
+ # headers: @auth_headers.merge('access-token' => @resp_token)
85
+ # end
86
+ #
87
+ # it 'should not treat this request as a batch request' do
88
+ # refute assigns(:is_batch_request)
89
+ # end
90
+ #
91
+ # it 'should allow a new request to be made using new token' do
92
+ # assert_equal 200, response.status
93
+ # end
94
+ # end
97
95
  end
98
96
 
99
97
  describe 'failed request' do
@@ -112,175 +110,173 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
112
110
  end
113
111
  end
114
112
 
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_mang',
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_mang',
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_mang',
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_mang',
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 'time out' do
223
- before do
224
- @resource.reload
225
- # age_token(@resource, @client_id)
226
-
227
- get '/demo/members_only_mang',
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
- @resource.reload
237
- # age_token(@resource, @client_id)
238
-
239
- # use expired auth header
240
- get '/demo/members_only_mang',
241
- params: {},
242
- headers: @auth_headers
243
-
244
- @second_is_batch_request = assigns(:is_batch_request)
245
- @second_user = assigns(:resource)
246
- @second_access_token = response.headers['access-token']
247
- @second_response_status = response.status
248
- end
249
-
250
- it 'should allow the first request through' do
251
- assert_equal 200, @first_response_status
252
- end
253
-
254
- it 'should not allow the second request through' do
255
- assert_equal 401, @second_response_status
256
- end
257
-
258
- it 'should not treat first request as batch request' do
259
- refute @second_is_batch_request
260
- end
261
-
262
- it 'should return auth headers from the first request' do
263
- assert @first_access_token
264
- end
265
-
266
- it 'should not treat second request as batch request' do
267
- refute @second_is_batch_request
268
- end
269
-
270
- it 'should not return auth headers from the second request' do
271
- refute @second_access_token
272
- end
273
-
274
- it 'should define user during first request' do
275
- assert @first_user
276
- end
277
-
278
- it 'should not define user during second request' do
279
- refute @second_user
280
- end
281
- end
282
- end
283
- =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_mang',
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_mang',
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_mang',
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_mang',
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 'time out' do
220
+ # before do
221
+ # @resource.reload
222
+ # # age_token(@resource, @client_id)
223
+ #
224
+ # get '/demo/members_only_mang',
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
+ # @resource.reload
234
+ # # age_token(@resource, @client_id)
235
+ #
236
+ # # use expired auth header
237
+ # get '/demo/members_only_mang',
238
+ # params: {},
239
+ # headers: @auth_headers
240
+ #
241
+ # @second_is_batch_request = assigns(:is_batch_request)
242
+ # @second_user = assigns(:resource)
243
+ # @second_access_token = response.headers['access-token']
244
+ # @second_response_status = response.status
245
+ # end
246
+ #
247
+ # it 'should allow the first request through' do
248
+ # assert_equal 200, @first_response_status
249
+ # end
250
+ #
251
+ # it 'should not allow the second request through' do
252
+ # assert_equal 401, @second_response_status
253
+ # end
254
+ #
255
+ # it 'should not treat first request as batch request' do
256
+ # refute @second_is_batch_request
257
+ # end
258
+ #
259
+ # it 'should return auth headers from the first request' do
260
+ # assert @first_access_token
261
+ # end
262
+ #
263
+ # it 'should not treat second request as batch request' do
264
+ # refute @second_is_batch_request
265
+ # end
266
+ #
267
+ # it 'should not return auth headers from the second request' do
268
+ # refute @second_access_token
269
+ # end
270
+ #
271
+ # it 'should define user during first request' do
272
+ # assert @first_user
273
+ # end
274
+ #
275
+ # it 'should not define user during second request' do
276
+ # refute @second_user
277
+ # end
278
+ # end
279
+ # end
284
280
  end
285
281
  end
286
282
  end