devise_token_auth_skycocker_fork 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +13 -0
  3. data/README.md +97 -0
  4. data/Rakefile +42 -0
  5. data/app/controllers/devise_token_auth/application_controller.rb +79 -0
  6. data/app/controllers/devise_token_auth/concerns/resource_finder.rb +44 -0
  7. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +178 -0
  8. data/app/controllers/devise_token_auth/confirmations_controller.rb +39 -0
  9. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +239 -0
  10. data/app/controllers/devise_token_auth/passwords_controller.rb +185 -0
  11. data/app/controllers/devise_token_auth/registrations_controller.rb +198 -0
  12. data/app/controllers/devise_token_auth/sessions_controller.rb +131 -0
  13. data/app/controllers/devise_token_auth/token_validations_controller.rb +31 -0
  14. data/app/controllers/devise_token_auth/unlocks_controller.rb +89 -0
  15. data/app/models/devise_token_auth/concerns/active_record_support.rb +34 -0
  16. data/app/models/devise_token_auth/concerns/mongoid_support.rb +19 -0
  17. data/app/models/devise_token_auth/concerns/user.rb +262 -0
  18. data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +28 -0
  19. data/app/validators/devise_token_auth/email_validator.rb +23 -0
  20. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  21. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  22. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  23. data/app/views/devise_token_auth/omniauth_external_window.html.erb +38 -0
  24. data/config/locales/da-DK.yml +50 -0
  25. data/config/locales/de.yml +49 -0
  26. data/config/locales/en.yml +50 -0
  27. data/config/locales/es.yml +49 -0
  28. data/config/locales/fr.yml +49 -0
  29. data/config/locales/it.yml +46 -0
  30. data/config/locales/ja.yml +46 -0
  31. data/config/locales/nl.yml +30 -0
  32. data/config/locales/pl.yml +48 -0
  33. data/config/locales/pt-BR.yml +46 -0
  34. data/config/locales/pt.yml +48 -0
  35. data/config/locales/ro.yml +46 -0
  36. data/config/locales/ru.yml +50 -0
  37. data/config/locales/sq.yml +46 -0
  38. data/config/locales/sv.yml +50 -0
  39. data/config/locales/uk.yml +59 -0
  40. data/config/locales/vi.yml +50 -0
  41. data/config/locales/zh-CN.yml +46 -0
  42. data/config/locales/zh-HK.yml +48 -0
  43. data/config/locales/zh-TW.yml +48 -0
  44. data/lib/devise_token_auth.rb +13 -0
  45. data/lib/devise_token_auth/blacklist.rb +2 -0
  46. data/lib/devise_token_auth/controllers/helpers.rb +161 -0
  47. data/lib/devise_token_auth/controllers/url_helpers.rb +10 -0
  48. data/lib/devise_token_auth/engine.rb +90 -0
  49. data/lib/devise_token_auth/errors.rb +8 -0
  50. data/lib/devise_token_auth/rails/routes.rb +116 -0
  51. data/lib/devise_token_auth/url.rb +41 -0
  52. data/lib/devise_token_auth/version.rb +5 -0
  53. data/lib/generators/devise_token_auth/USAGE +31 -0
  54. data/lib/generators/devise_token_auth/install_generator.rb +91 -0
  55. data/lib/generators/devise_token_auth/install_generator_helpers.rb +98 -0
  56. data/lib/generators/devise_token_auth/install_mongoid_generator.rb +46 -0
  57. data/lib/generators/devise_token_auth/install_views_generator.rb +18 -0
  58. data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +50 -0
  59. data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +56 -0
  60. data/lib/generators/devise_token_auth/templates/user.rb.erb +9 -0
  61. data/lib/generators/devise_token_auth/templates/user_mongoid.rb.erb +63 -0
  62. data/lib/tasks/devise_token_auth_tasks.rake +6 -0
  63. data/test/controllers/custom/custom_confirmations_controller_test.rb +25 -0
  64. data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +33 -0
  65. data/test/controllers/custom/custom_passwords_controller_test.rb +79 -0
  66. data/test/controllers/custom/custom_registrations_controller_test.rb +63 -0
  67. data/test/controllers/custom/custom_sessions_controller_test.rb +39 -0
  68. data/test/controllers/custom/custom_token_validations_controller_test.rb +42 -0
  69. data/test/controllers/demo_group_controller_test.rb +151 -0
  70. data/test/controllers/demo_mang_controller_test.rb +284 -0
  71. data/test/controllers/demo_user_controller_test.rb +629 -0
  72. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +127 -0
  73. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +376 -0
  74. data/test/controllers/devise_token_auth/passwords_controller_test.rb +639 -0
  75. data/test/controllers/devise_token_auth/registrations_controller_test.rb +880 -0
  76. data/test/controllers/devise_token_auth/sessions_controller_test.rb +541 -0
  77. data/test/controllers/devise_token_auth/token_validations_controller_test.rb +102 -0
  78. data/test/controllers/devise_token_auth/unlocks_controller_test.rb +196 -0
  79. data/test/controllers/overrides/confirmations_controller_test.rb +47 -0
  80. data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +53 -0
  81. data/test/controllers/overrides/passwords_controller_test.rb +64 -0
  82. data/test/controllers/overrides/registrations_controller_test.rb +46 -0
  83. data/test/controllers/overrides/sessions_controller_test.rb +35 -0
  84. data/test/controllers/overrides/token_validations_controller_test.rb +43 -0
  85. data/test/dummy/README.rdoc +28 -0
  86. data/test/dummy/app/active_record/lockable_user.rb +7 -0
  87. data/test/dummy/app/active_record/mang.rb +5 -0
  88. data/test/dummy/app/active_record/only_email_user.rb +7 -0
  89. data/test/dummy/app/active_record/scoped_user.rb +9 -0
  90. data/test/dummy/app/active_record/unconfirmable_user.rb +9 -0
  91. data/test/dummy/app/active_record/unregisterable_user.rb +9 -0
  92. data/test/dummy/app/active_record/user.rb +6 -0
  93. data/test/dummy/app/controllers/application_controller.rb +18 -0
  94. data/test/dummy/app/controllers/auth_origin_controller.rb +7 -0
  95. data/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
  96. data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +13 -0
  97. data/test/dummy/app/controllers/custom/passwords_controller.rb +39 -0
  98. data/test/dummy/app/controllers/custom/registrations_controller.rb +39 -0
  99. data/test/dummy/app/controllers/custom/sessions_controller.rb +29 -0
  100. data/test/dummy/app/controllers/custom/token_validations_controller.rb +19 -0
  101. data/test/dummy/app/controllers/demo_group_controller.rb +15 -0
  102. data/test/dummy/app/controllers/demo_mang_controller.rb +14 -0
  103. data/test/dummy/app/controllers/demo_user_controller.rb +27 -0
  104. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +28 -0
  105. data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +16 -0
  106. data/test/dummy/app/controllers/overrides/passwords_controller.rb +35 -0
  107. data/test/dummy/app/controllers/overrides/registrations_controller.rb +29 -0
  108. data/test/dummy/app/controllers/overrides/sessions_controller.rb +36 -0
  109. data/test/dummy/app/controllers/overrides/token_validations_controller.rb +23 -0
  110. data/test/dummy/app/helpers/application_helper.rb +1058 -0
  111. data/test/dummy/app/models/concerns/favorite_color.rb +19 -0
  112. data/test/dummy/app/mongoid/lockable_user.rb +38 -0
  113. data/test/dummy/app/mongoid/mang.rb +53 -0
  114. data/test/dummy/app/mongoid/only_email_user.rb +33 -0
  115. data/test/dummy/app/mongoid/scoped_user.rb +57 -0
  116. data/test/dummy/app/mongoid/unconfirmable_user.rb +51 -0
  117. data/test/dummy/app/mongoid/unregisterable_user.rb +54 -0
  118. data/test/dummy/app/mongoid/user.rb +56 -0
  119. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  120. data/test/dummy/config.ru +18 -0
  121. data/test/dummy/config/application.rb +48 -0
  122. data/test/dummy/config/application.yml.bk +0 -0
  123. data/test/dummy/config/boot.rb +11 -0
  124. data/test/dummy/config/environment.rb +7 -0
  125. data/test/dummy/config/environments/development.rb +46 -0
  126. data/test/dummy/config/environments/production.rb +84 -0
  127. data/test/dummy/config/environments/test.rb +50 -0
  128. data/test/dummy/config/initializers/assets.rb +10 -0
  129. data/test/dummy/config/initializers/backtrace_silencers.rb +9 -0
  130. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  131. data/test/dummy/config/initializers/devise.rb +17 -0
  132. data/test/dummy/config/initializers/devise_token_auth.rb +24 -0
  133. data/test/dummy/config/initializers/figaro.rb +3 -0
  134. data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  135. data/test/dummy/config/initializers/inflections.rb +18 -0
  136. data/test/dummy/config/initializers/mime_types.rb +6 -0
  137. data/test/dummy/config/initializers/omniauth.rb +10 -0
  138. data/test/dummy/config/initializers/session_store.rb +5 -0
  139. data/test/dummy/config/initializers/wrap_parameters.rb +16 -0
  140. data/test/dummy/config/routes.rb +55 -0
  141. data/test/dummy/config/spring.rb +3 -0
  142. data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +65 -0
  143. data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +64 -0
  144. data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +8 -0
  145. data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +7 -0
  146. data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +62 -0
  147. data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +63 -0
  148. data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +63 -0
  149. data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +63 -0
  150. data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +63 -0
  151. data/test/dummy/db/schema.rb +200 -0
  152. data/test/dummy/lib/migration_database_helper.rb +43 -0
  153. data/test/dummy/tmp/generators/app/models/user.rb +9 -0
  154. data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +50 -0
  155. data/test/dummy/tmp/generators/db/migrate/20181030122248_devise_token_auth_create_users.rb +56 -0
  156. data/test/factories/users.rb +40 -0
  157. data/test/lib/devise_token_auth/blacklist_test.rb +11 -0
  158. data/test/lib/devise_token_auth/url_test.rb +26 -0
  159. data/test/lib/generators/devise_token_auth/install_generator_test.rb +217 -0
  160. data/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb +222 -0
  161. data/test/lib/generators/devise_token_auth/install_views_generator_test.rb +25 -0
  162. data/test/models/concerns/mongoid_support_test.rb +31 -0
  163. data/test/models/only_email_user_test.rb +37 -0
  164. data/test/models/user_test.rb +140 -0
  165. data/test/support/controllers/routes.rb +43 -0
  166. data/test/test_helper.rb +103 -0
  167. metadata +443 -0
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # desc "Explaining what the task does"
4
+ # task :devise_token_auth do
5
+ # # Task goes here
6
+ # end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Custom::ConfirmationsControllerTest < ActionController::TestCase
6
+ describe Custom::ConfirmationsController do
7
+ include CustomControllersRoutes
8
+
9
+ before do
10
+ @redirect_url = Faker::Internet.url
11
+ @new_user = create(:user)
12
+ @new_user.send_confirmation_instructions(redirect_url: @redirect_url)
13
+ @mail = ActionMailer::Base.deliveries.last
14
+ @token = @mail.body.match(/confirmation_token=([^&]*)&/)[1]
15
+ @client_config = @mail.body.match(/config=([^&]*)&/)[1]
16
+
17
+ get :show,
18
+ params: { confirmation_token: @token, redirect_url: @redirect_url }
19
+ end
20
+
21
+ test 'yield resource to block on show success' do
22
+ assert @controller.show_block_called?, 'show failed to yield resource to provided block'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Custom::OmniauthCallbacksControllerTest < ActionDispatch::IntegrationTest
6
+ describe Custom::OmniauthCallbacksController do
7
+ include CustomControllersRoutes
8
+
9
+ setup do
10
+ OmniAuth.config.test_mode = true
11
+ OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(
12
+ provider: 'facebook',
13
+ uid: '123545',
14
+ info: {
15
+ name: 'swong',
16
+ email: 'swongsong@yandex.ru'
17
+ }
18
+ )
19
+ end
20
+
21
+ test 'yield resource to block on omniauth_success success' do
22
+ @redirect_url = 'http://ng-token-auth.dev/'
23
+ get '/nice_user_auth/facebook',
24
+ params: { auth_origin_url: @redirect_url,
25
+ omniauth_window_type: 'newWindow' }
26
+
27
+ follow_all_redirects!
28
+
29
+ assert @controller.omniauth_success_block_called?,
30
+ 'omniauth_success failed to yield resource to provided block'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Custom::PasswordsControllerTest < ActionController::TestCase
6
+ describe Custom::PasswordsController do
7
+ include CustomControllersRoutes
8
+
9
+ before do
10
+ @resource = create(:user, :confirmed)
11
+ @redirect_url = 'http://ng-token-auth.dev'
12
+ end
13
+
14
+ test 'yield resource to block on create success' do
15
+ post :create,
16
+ params: { email: @resource.email,
17
+ redirect_url: @redirect_url }
18
+
19
+ @mail = ActionMailer::Base.deliveries.last
20
+ @resource.reload
21
+
22
+ @mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
23
+ @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
24
+ @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
25
+
26
+ assert @controller.create_block_called?,
27
+ 'create failed to yield resource to provided block'
28
+ end
29
+
30
+ test 'yield resource to block on edit success' do
31
+ @resource = create(:user)
32
+ @redirect_url = 'http://ng-token-auth.dev'
33
+
34
+ post :create,
35
+ params: { email: @resource.email,
36
+ redirect_url: @redirect_url },
37
+ xhr: true
38
+
39
+ @mail = ActionMailer::Base.deliveries.last
40
+ @resource.reload
41
+
42
+ @mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
43
+ @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
44
+ @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
45
+
46
+ get :edit,
47
+ params: { reset_password_token: @mail_reset_token,
48
+ redirect_url: @mail_redirect_url },
49
+ xhr: true
50
+ @resource.reload
51
+ assert @controller.edit_block_called?,
52
+ 'edit failed to yield resource to provided block'
53
+ end
54
+
55
+ test 'yield resource to block on update success' do
56
+ @auth_headers = @resource.create_new_auth_token
57
+ request.headers.merge!(@auth_headers)
58
+ @new_password = Faker::Internet.password
59
+ put :update,
60
+ params: { password: @new_password,
61
+ password_confirmation: @new_password }
62
+ assert @controller.update_block_called?, 'update failed to yield resource to provided block'
63
+ end
64
+
65
+ test 'yield resource to block on update success with custom json' do
66
+ @auth_headers = @resource.create_new_auth_token
67
+ request.headers.merge!(@auth_headers)
68
+ @new_password = Faker::Internet.password
69
+ put :update,
70
+ params: { password: @new_password,
71
+ password_confirmation: @new_password }
72
+
73
+ @data = JSON.parse(response.body)
74
+
75
+ assert @controller.update_block_called?, 'update failed to yield resource to provided block'
76
+ assert_equal @data['custom'], 'foo'
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Custom::RegistrationsControllerTest < ActionDispatch::IntegrationTest
6
+ describe Custom::RegistrationsController do
7
+ include CustomControllersRoutes
8
+
9
+ before do
10
+ @create_params = attributes_for(:user,
11
+ confirm_success_url: Faker::Internet.url,
12
+ unpermitted_param: '(x_x)')
13
+
14
+ @existing_user = create(:user, :confirmed)
15
+ @auth_headers = @existing_user.create_new_auth_token
16
+ @client_id = @auth_headers['client']
17
+
18
+ # ensure request is not treated as batch request
19
+ age_token(@existing_user, @client_id)
20
+ end
21
+
22
+ test 'yield resource to block on create success' do
23
+ post '/nice_user_auth', params: @create_params
24
+ assert @controller.create_block_called?,
25
+ 'create failed to yield resource to provided block'
26
+ end
27
+
28
+ test 'yield resource to block on create success with custom json' do
29
+ post '/nice_user_auth', params: @create_params
30
+
31
+ @data = JSON.parse(response.body)
32
+
33
+ assert @controller.create_block_called?,
34
+ 'create failed to yield resource to provided block'
35
+ assert_equal @data['custom'], 'foo'
36
+ end
37
+
38
+ test 'yield resource to block on update success' do
39
+ put '/nice_user_auth',
40
+ params: {
41
+ nickname: "Ol' Sunshine-face"
42
+ },
43
+ headers: @auth_headers
44
+ assert @controller.update_block_called?,
45
+ 'update failed to yield resource to provided block'
46
+ end
47
+
48
+ test 'yield resource to block on destroy success' do
49
+ delete '/nice_user_auth', headers: @auth_headers
50
+ assert @controller.destroy_block_called?,
51
+ 'destroy failed to yield resource to provided block'
52
+ end
53
+
54
+ describe 'when overriding #build_resource' do
55
+ test 'it fails' do
56
+ Custom::RegistrationsController.any_instance.stubs(:build_resource).returns(nil)
57
+ assert_raises DeviseTokenAuth::Errors::NoResourceDefinedError do
58
+ post '/nice_user_auth', params: @create_params
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Custom::SessionsControllerTest < ActionController::TestCase
6
+ describe Custom::SessionsController do
7
+ include CustomControllersRoutes
8
+
9
+ before do
10
+ @existing_user = create(:user, :confirmed)
11
+ end
12
+
13
+ test 'yield resource to block on create success' do
14
+ post :create,
15
+ params: {
16
+ email: @existing_user.email,
17
+ password: @existing_user.password
18
+ }
19
+ assert @controller.create_block_called?,
20
+ 'create failed to yield resource to provided block'
21
+ end
22
+
23
+ test 'yield resource to block on destroy success' do
24
+ @auth_headers = @existing_user.create_new_auth_token
25
+ request.headers.merge!(@auth_headers)
26
+ delete :destroy, format: :json
27
+ assert @controller.destroy_block_called?,
28
+ 'destroy failed to yield resource to provided block'
29
+ end
30
+
31
+ test 'render method override' do
32
+ post :create,
33
+ params: { email: @existing_user.email,
34
+ password: @existing_user.password }
35
+ @data = JSON.parse(response.body)
36
+ assert_equal @data['custom'], 'foo'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Custom::TokenValidationsControllerTest < ActionDispatch::IntegrationTest
6
+ describe Custom::TokenValidationsController do
7
+ include CustomControllersRoutes
8
+
9
+ before do
10
+ @resource = create(:user, :confirmed)
11
+
12
+ @auth_headers = @resource.create_new_auth_token
13
+
14
+ @token = @auth_headers['access-token']
15
+ @client_id = @auth_headers['client']
16
+ @expiry = @auth_headers['expiry']
17
+
18
+ # ensure that request is not treated as batch request
19
+ age_token(@resource, @client_id)
20
+ end
21
+
22
+ test 'yield resource to block on validate_token success' do
23
+ get '/nice_user_auth/validate_token',
24
+ params: {},
25
+ headers: @auth_headers
26
+ assert @controller.validate_token_block_called?,
27
+ 'validate_token failed to yield resource to provided block'
28
+ end
29
+
30
+ test 'yield resource to block on validate_token success with custom json' do
31
+ get '/nice_user_auth/validate_token',
32
+ params: {},
33
+ headers: @auth_headers
34
+
35
+ @data = JSON.parse(response.body)
36
+
37
+ assert @controller.validate_token_block_called?,
38
+ 'validate_token failed to yield resource to provided block'
39
+ assert_equal @data['custom'], 'foo'
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ # was the web request successful?
6
+ # was the user redirected to the right page?
7
+ # was the user successfully authenticated?
8
+ # was the correct object stored in the response?
9
+ # was the appropriate message delivered in the json payload?
10
+
11
+ class DemoGroupControllerTest < ActionDispatch::IntegrationTest
12
+ describe DemoGroupController do
13
+ describe 'Token access' do
14
+ before do
15
+ # user
16
+ @resource = create(:user, :confirmed)
17
+
18
+ @resource_auth_headers = @resource.create_new_auth_token
19
+
20
+ @resource_token = @resource_auth_headers['access-token']
21
+ @resource_client_id = @resource_auth_headers['client']
22
+ @resource_expiry = @resource_auth_headers['expiry']
23
+
24
+ # mang
25
+ @mang = create(:mang_user, :confirmed)
26
+
27
+ @mang_auth_headers = @mang.create_new_auth_token
28
+
29
+ @mang_token = @mang_auth_headers['access-token']
30
+ @mang_client_id = @mang_auth_headers['client']
31
+ @mang_expiry = @mang_auth_headers['expiry']
32
+ end
33
+
34
+ describe 'user access' do
35
+ before do
36
+ # ensure that request is not treated as batch request
37
+ age_token(@resource, @resource_client_id)
38
+
39
+ get '/demo/members_only_group',
40
+ params: {},
41
+ headers: @resource_auth_headers
42
+
43
+ @resp_token = response.headers['access-token']
44
+ @resp_client_id = response.headers['client']
45
+ @resp_expiry = response.headers['expiry']
46
+ @resp_uid = response.headers['uid']
47
+ end
48
+
49
+ test 'request is successful' do
50
+ assert_equal 200, response.status
51
+ end
52
+
53
+ describe 'devise mappings' do
54
+ it 'should define current_user' do
55
+ assert_equal @resource, @controller.current_user
56
+ end
57
+
58
+ it 'should define user_signed_in?' do
59
+ assert @controller.user_signed_in?
60
+ end
61
+
62
+ it 'should not define current_mang' do
63
+ refute_equal @resource, @controller.current_mang
64
+ end
65
+
66
+ it 'should define current_member' do
67
+ assert_equal @resource, @controller.current_member
68
+ end
69
+
70
+ it 'should define current_members' do
71
+ assert @controller.current_members.include? @resource
72
+ end
73
+
74
+ it 'should define member_signed_in?' do
75
+ assert @controller.current_members.include? @resource
76
+ end
77
+
78
+ it 'should define render_authenticate_error' do
79
+ assert @controller.methods.include?(:render_authenticate_error)
80
+ end
81
+ end
82
+ end
83
+
84
+ describe 'mang access' do
85
+ before do
86
+ # ensure that request is not treated as batch request
87
+ age_token(@mang, @mang_client_id)
88
+
89
+ get '/demo/members_only_group',
90
+ params: {},
91
+ headers: @mang_auth_headers
92
+
93
+ @resp_token = response.headers['access-token']
94
+ @resp_client_id = response.headers['client']
95
+ @resp_expiry = response.headers['expiry']
96
+ @resp_uid = response.headers['uid']
97
+ end
98
+
99
+ test 'request is successful' do
100
+ assert_equal 200, response.status
101
+ end
102
+
103
+ describe 'devise mappings' do
104
+ it 'should define current_mang' do
105
+ assert_equal @mang, @controller.current_mang
106
+ end
107
+
108
+ it 'should define mang_signed_in?' do
109
+ assert @controller.mang_signed_in?
110
+ end
111
+
112
+ it 'should not define current_mang' do
113
+ refute_equal @mang, @controller.current_user
114
+ end
115
+
116
+ it 'should define current_member' do
117
+ assert_equal @mang, @controller.current_member
118
+ end
119
+
120
+ it 'should define current_members' do
121
+ assert @controller.current_members.include? @mang
122
+ end
123
+
124
+ it 'should define member_signed_in?' do
125
+ assert @controller.current_members.include? @mang
126
+ end
127
+
128
+ it 'should define render_authenticate_error' do
129
+ assert @controller.methods.include?(:render_authenticate_error)
130
+ end
131
+ end
132
+ end
133
+
134
+ describe 'failed access' do
135
+ before do
136
+ get '/demo/members_only_group',
137
+ params: {},
138
+ headers: @mang_auth_headers.merge('access-token' => 'bogus')
139
+ end
140
+
141
+ it 'should not return any auth headers' do
142
+ refute response.headers['access-token']
143
+ end
144
+
145
+ it 'should return error: unauthorized status' do
146
+ assert_equal 401, response.status
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end