g5_authenticatable 0.9.1.pre.2 → 1.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +23 -9
  5. data/Appraisals +17 -0
  6. data/CHANGELOG.md +14 -0
  7. data/Gemfile +11 -14
  8. data/README.md +40 -13
  9. data/app/controllers/concerns/g5_authenticatable/authorization.rb +4 -1
  10. data/app/controllers/g5_authenticatable/application_controller.rb +3 -0
  11. data/app/controllers/g5_authenticatable/error_controller.rb +3 -2
  12. data/app/controllers/g5_authenticatable/failure_app.rb +35 -0
  13. data/app/controllers/g5_authenticatable/sessions_controller.rb +7 -3
  14. data/app/helpers/g5_authenticatable/application_helper.rb +3 -0
  15. data/app/models/g5_authenticatable/role.rb +5 -2
  16. data/app/models/g5_authenticatable/user.rb +12 -5
  17. data/app/policies/g5_authenticatable/base_policy.rb +75 -58
  18. data/app/policies/g5_updatable/client_policy.rb +5 -5
  19. data/app/policies/g5_updatable/location_policy.rb +6 -5
  20. data/app/policies/g5_updatable/selectable_client_policy.rb +6 -7
  21. data/app/services/g5_authenticatable/impersonate_sessionable.rb +12 -7
  22. data/config/initializers/devise.rb +4 -0
  23. data/config/initializers/impersonate_strategy.rb +5 -2
  24. data/config/initializers/rolify.rb +2 -0
  25. data/config/routes.rb +3 -1
  26. data/g5_authenticatable.gemspec +11 -7
  27. data/gemfiles/rails_4.1.gemfile +28 -0
  28. data/gemfiles/rails_4.2.gemfile +28 -0
  29. data/gemfiles/rails_5.0.gemfile +28 -0
  30. data/gemfiles/rails_5.1.gemfile +28 -0
  31. data/lib/g5_authenticatable.rb +3 -1
  32. data/lib/g5_authenticatable/engine.rb +5 -2
  33. data/lib/g5_authenticatable/rspec.rb +2 -0
  34. data/lib/g5_authenticatable/test/controller_helpers.rb +14 -9
  35. data/lib/g5_authenticatable/test/env_helpers.rb +3 -0
  36. data/lib/g5_authenticatable/test/factories/client_users.rb +45 -0
  37. data/lib/g5_authenticatable/test/factories/global_users.rb +43 -0
  38. data/lib/g5_authenticatable/test/factories/location_users.rb +45 -0
  39. data/lib/g5_authenticatable/test/factories/roles.rb +63 -0
  40. data/lib/g5_authenticatable/test/factory.rb +7 -59
  41. data/lib/g5_authenticatable/test/feature_helpers.rb +31 -17
  42. data/lib/g5_authenticatable/test/request_helpers.rb +5 -1
  43. data/lib/g5_authenticatable/test/token_validation_helpers.rb +15 -10
  44. data/lib/g5_authenticatable/version.rb +3 -1
  45. data/lib/generators/g5_authenticatable/install/install_generator.rb +49 -37
  46. data/lib/generators/g5_authenticatable/install/templates/application_policy.rb +2 -0
  47. data/lib/generators/g5_authenticatable/install/templates/initializer.rb +2 -0
  48. data/lib/generators/g5_authenticatable/install/templates/migrate/add_g5_authenticatable_users_contact_info.rb +3 -1
  49. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_roles.rb +3 -1
  50. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_users.rb +3 -1
  51. data/lib/tasks/g5_authenticatable/purge_users.rake +2 -0
  52. data/spec/config/application_spec.rb +7 -4
  53. data/spec/controllers/application_controller_spec.rb +10 -5
  54. data/spec/controllers/concerns/g5_authenticatable/{authorization.rb → authorization_spec.rb} +11 -6
  55. data/spec/dummy/app/controllers/home_controller.rb +5 -5
  56. data/spec/dummy/app/controllers/rails_api/secure_resources_controller.rb +6 -4
  57. data/spec/dummy/app/models/post.rb +1 -1
  58. data/spec/dummy/config/environments/test.rb +25 -4
  59. data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
  60. data/spec/dummy/db/migrate/20140206070137_create_g5_authenticatable_users.rb +3 -1
  61. data/spec/dummy/db/migrate/20150428182339_add_g5_authenticatable_users_contact_info.rb +3 -1
  62. data/spec/dummy/db/migrate/20150429212919_create_g5_authenticatable_roles.rb +2 -1
  63. data/spec/dummy/db/migrate/20150509061150_create_posts.rb +3 -1
  64. data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb +3 -1
  65. data/spec/dummy/db/migrate/20150603224033_create_integration_setting.g5_updatable.rb +3 -1
  66. data/spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb +3 -1
  67. data/spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb +3 -1
  68. data/spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb +3 -1
  69. data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb +7 -0
  70. data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb +20 -0
  71. data/spec/dummy/db/migrate/20170613201432_add_latitude_longitude_indexes_to_location.g5_updatable.rb +7 -0
  72. data/spec/dummy/db/migrate/{20161122070749_add_amenities.rb → 20170613201433_add_amenities.g5_updatable.rb} +2 -1
  73. data/spec/dummy/db/migrate/{20161209070749_add_client_urn_to_locations.rb → 20170613201434_add_client_urn_to_locations.g5_updatable.rb} +2 -1
  74. data/spec/dummy/db/migrate/20170613201435_add_points_of_interest.g5_updatable.rb +21 -0
  75. data/spec/dummy/db/migrate/20170613201436_add_unique_urn_indexes.g5_updatable.rb +11 -0
  76. data/spec/dummy/db/schema.rb +73 -61
  77. data/spec/factories/post.rb +2 -0
  78. data/spec/features/auth_error_path_spec.rb +3 -3
  79. data/spec/features/default_role_authorization_spec.rb +8 -4
  80. data/spec/features/sign_in_spec.rb +23 -13
  81. data/spec/features/token_validation_spec.rb +4 -2
  82. data/spec/g5_authenticatable/version_spec.rb +3 -1
  83. data/spec/lib/generators/g5_authenticatable/install_generator_spec.rb +73 -28
  84. data/spec/models/g5_authenticatable/role_spec.rb +8 -4
  85. data/spec/models/g5_authenticatable/user_spec.rb +119 -84
  86. data/spec/models/post_spec.rb +4 -2
  87. data/spec/policies/application_policy_spec.rb +80 -47
  88. data/spec/policies/client_policy_spec.rb +8 -5
  89. data/spec/policies/location_policy_spec.rb +21 -8
  90. data/spec/policies/selectable_client_policy_spec.rb +26 -15
  91. data/spec/rails_helper.rb +41 -0
  92. data/spec/requests/default_role_authorization_spec.rb +18 -14
  93. data/spec/requests/grape_api_spec.rb +7 -5
  94. data/spec/requests/rails_api_spec.rb +11 -9
  95. data/spec/requests/sign_out_spec.rb +10 -6
  96. data/spec/requests/token_validation_spec.rb +9 -5
  97. data/spec/routing/auth_error_routing_spec.rb +7 -6
  98. data/spec/routing/sign_out_routing_spec.rb +7 -5
  99. data/spec/services/g5_authenticatable/impersonate_sessionable_spec.rb +41 -18
  100. data/spec/spec_helper.rb +78 -45
  101. data/spec/support/devise.rb +3 -1
  102. data/spec/support/safe_request_helpers.rb +36 -0
  103. data/spec/support/shared_contexts/rake.rb +10 -4
  104. data/spec/support/shared_examples/super_admin_authorizer.rb +3 -1
  105. data/spec/tasks/purge_users_spec.rb +3 -1
  106. metadata +75 -39
  107. data/spec/controllers/.gitkeep +0 -0
@@ -0,0 +1,28 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "active_model_serializers", "<= 0.10.0"
6
+ gem "grape"
7
+ gem "jquery-rails"
8
+ gem "pg"
9
+ gem "rails", "~> 5.1.1"
10
+
11
+ group :test, :development do
12
+ gem "appraisal"
13
+ gem "dotenv-rails"
14
+ gem "pry-byebug"
15
+ gem "rspec-rails", "~> 3.6"
16
+ gem "web-console", "~> 2.0"
17
+ end
18
+
19
+ group :test do
20
+ gem "capybara"
21
+ gem "codeclimate-test-reporter"
22
+ gem "generator_spec"
23
+ gem "rspec-activemodel-mocks"
24
+ gem "shoulda-matchers", "~> 3.1"
25
+ gem "simplecov", require: false
26
+ end
27
+
28
+ gemspec path: "../"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'g5_authenticatable/engine'
2
4
 
3
5
  require 'devise_g5_authenticatable'
@@ -15,6 +17,6 @@ module G5Authenticatable
15
17
  def self.strict_token_validation=(validate)
16
18
  @@strict_token_validation =
17
19
  G5AuthenticatableApi.strict_token_validation =
18
- Devise.g5_strict_token_validation = validate
20
+ Devise.g5_strict_token_validation = validate
19
21
  end
20
22
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rolify'
2
4
  require 'pundit'
3
5
 
4
6
  module G5Authenticatable
7
+ # Rails engine for authentication/authorization against G5 Auth server
5
8
  class Engine < ::Rails::Engine
6
9
  isolate_namespace G5Authenticatable
7
10
 
@@ -11,8 +14,8 @@ module G5Authenticatable
11
14
  g.fixture_replacement :factory_girl, dir: 'spec/factories'
12
15
  end
13
16
 
14
- initializer "g5_authenticatable.filter_access_token" do |app|
15
- app.config.filter_parameters += [ :access_token ]
17
+ initializer 'g5_authenticatable.filter_access_token' do |app|
18
+ app.config.filter_parameters += [:access_token]
16
19
  end
17
20
  end
18
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'g5_authenticatable/test/env_helpers'
2
4
  require 'g5_authenticatable/test/factory'
3
5
  require 'g5_authenticatable/test/token_validation_helpers'
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
2
4
  module Test
5
+ # Helper methods for controller tests
3
6
  module ControllerHelpers
4
7
  def login_user(user)
5
- @request.env["devise.mapping"] = Devise.mappings[:user]
8
+ @request.env['devise.mapping'] = Devise.mappings[:user]
6
9
  sign_in user
7
10
  end
8
11
 
@@ -13,12 +16,12 @@ module G5Authenticatable
13
16
  end
14
17
  end
15
18
 
16
- shared_context 'auth controller', auth_controller: true do
19
+ RSpec.shared_context 'auth controller' do
17
20
  let(:user) { FactoryGirl.create(:g5_authenticatable_user) }
18
21
  include_context 'authorization controller'
19
22
  end
20
23
 
21
- shared_context 'super admin auth controller' do
24
+ RSpec.shared_context 'super admin auth controller' do
22
25
  let(:user) do
23
26
  user = FactoryGirl.create(:g5_authenticatable_user)
24
27
  user.add_role(:super_admin)
@@ -27,7 +30,7 @@ shared_context 'super admin auth controller' do
27
30
  include_context 'authorization controller'
28
31
  end
29
32
 
30
- shared_context 'admin auth controller' do
33
+ RSpec.shared_context 'admin auth controller' do
31
34
  let(:user) do
32
35
  user = FactoryGirl.create(:g5_authenticatable_user)
33
36
  user.add_role(:admin)
@@ -36,7 +39,7 @@ shared_context 'admin auth controller' do
36
39
  include_context 'authorization controller'
37
40
  end
38
41
 
39
- shared_context 'authorization controller' do
42
+ RSpec.shared_context 'authorization controller' do
40
43
  include G5Authenticatable::Test::ControllerHelpers
41
44
 
42
45
  before do
@@ -47,12 +50,12 @@ shared_context 'authorization controller' do
47
50
  after { logout_user(user) }
48
51
  end
49
52
 
50
- shared_examples 'a secure controller' do
53
+ RSpec.shared_examples 'a secure controller' do
51
54
  controller do
52
- before_filter :authenticate_user!
55
+ before_action :authenticate_user!
53
56
 
54
57
  def index
55
- render text: 'content'
58
+ render plain: 'content'
56
59
  end
57
60
  end
58
61
 
@@ -72,6 +75,8 @@ shared_examples 'a secure controller' do
72
75
  end
73
76
 
74
77
  RSpec.configure do |config|
75
- config.include Devise::TestHelpers, type: :controller
78
+ config.include Devise::Test::ControllerHelpers, type: :controller
76
79
  config.include G5Authenticatable::Test::ControllerHelpers, type: :controller
80
+
81
+ config.include_context 'auth controller', auth_controller: true
77
82
  end
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
2
4
  module Test
5
+ # Helper methods for stubbing environment variables
3
6
  module EnvHelpers
4
7
  def stub_env_var(name, value)
5
8
  stub_const('ENV', ENV.to_hash.merge(name => value))
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryGirl.define do
4
+ factory :g5_authenticatable_client_user, parent: :g5_authenticatable_user do
5
+ transient do
6
+ clients nil
7
+ client_count 1
8
+ role_factory :g5_authenticatable_client_role
9
+ end
10
+
11
+ after(:create) do |user, evaluator|
12
+ user.roles.clear
13
+
14
+ user.roles << if evaluator.clients
15
+ evaluator.clients.collect do |client|
16
+ create(evaluator.role_factory, resource: client)
17
+ end
18
+ else
19
+ create_list(evaluator.role_factory,
20
+ evaluator.client_count)
21
+ end
22
+ end
23
+ end
24
+
25
+ factory :g5_authenticatable_client_admin,
26
+ parent: :g5_authenticatable_client_user do
27
+ transient do
28
+ role_factory :g5_authenticatable_client_admin_role
29
+ end
30
+ end
31
+
32
+ factory :g5_authenticatable_client_editor,
33
+ parent: :g5_authenticatable_client_user do
34
+ transient do
35
+ role_factory :g5_authenticatable_client_editor_role
36
+ end
37
+ end
38
+
39
+ factory :g5_authenticatable_client_viewer,
40
+ parent: :g5_authenticatable_client_user do
41
+ transient do
42
+ role_factory :g5_authenticatable_client_viewer_role
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryGirl.define do
4
+ factory :g5_authenticatable_user, class: 'G5Authenticatable::User' do
5
+ sequence(:email) { |n| "test.user#{n}@test.host" }
6
+ provider 'g5'
7
+ sequence(:uid) { |n| "abc123-#{n}" }
8
+ sequence(:g5_access_token) { |n| "secret_token_#{n}" }
9
+ first_name 'Jane'
10
+ last_name 'Doe'
11
+ phone_number '(555) 867-5309'
12
+ title 'Minister of Funny Walks'
13
+ organization_name 'Department of Redundancy Department'
14
+ end
15
+
16
+ factory :g5_authenticatable_super_admin, parent: :g5_authenticatable_user do
17
+ after(:build) do |user|
18
+ user.roles.clear
19
+ user.roles << FactoryGirl.build(:g5_authenticatable_super_admin_role)
20
+ end
21
+ end
22
+
23
+ factory :g5_authenticatable_admin, parent: :g5_authenticatable_user do
24
+ after(:build) do |user|
25
+ user.roles.clear
26
+ user.roles << FactoryGirl.build(:g5_authenticatable_admin_role)
27
+ end
28
+ end
29
+
30
+ factory :g5_authenticatable_editor, parent: :g5_authenticatable_user do
31
+ after(:build) do |user|
32
+ user.roles.clear
33
+ user.roles << FactoryGirl.build(:g5_authenticatable_editor_role)
34
+ end
35
+ end
36
+
37
+ factory :g5_authenticatable_viewer, parent: :g5_authenticatable_user do
38
+ after(:build) do |user|
39
+ user.roles.clear
40
+ user.roles << FactoryGirl.build(:g5_authenticatable_viewer_role)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryGirl.define do
4
+ factory :g5_authenticatable_location_user, parent: :g5_authenticatable_user do
5
+ transient do
6
+ locations nil
7
+ location_count 1
8
+ role_factory :g5_authenticatable_location_role
9
+ end
10
+
11
+ after(:create) do |user, evaluator|
12
+ user.roles.clear
13
+
14
+ user.roles << if evaluator.locations
15
+ evaluator.locations.collect do |location|
16
+ create(evaluator.role_factory, resource: location)
17
+ end
18
+ else
19
+ user.roles << create_list(evaluator.role_factory,
20
+ evaluator.location_count)
21
+ end
22
+ end
23
+ end
24
+
25
+ factory :g5_authenticatable_location_admin,
26
+ parent: :g5_authenticatable_location_user do
27
+ transient do
28
+ role_factory :g5_authenticatable_location_admin_role
29
+ end
30
+ end
31
+
32
+ factory :g5_authenticatable_location_editor,
33
+ parent: :g5_authenticatable_location_user do
34
+ transient do
35
+ role_factory :g5_authenticatable_location_editor_role
36
+ end
37
+ end
38
+
39
+ factory :g5_authenticatable_location_viewer,
40
+ parent: :g5_authenticatable_location_user do
41
+ transient do
42
+ role_factory :g5_authenticatable_location_viewer_role
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryGirl.define do
4
+ factory :g5_authenticatable_role, class: 'G5Authenticatable::Role' do
5
+ sequence(:name) { |n| "role_#{n}" }
6
+ end
7
+
8
+ factory :g5_authenticatable_super_admin_role,
9
+ parent: :g5_authenticatable_role do
10
+ name 'super_admin'
11
+ end
12
+
13
+ factory :g5_authenticatable_admin_role, parent: :g5_authenticatable_role do
14
+ name 'admin'
15
+ end
16
+
17
+ factory :g5_authenticatable_editor_role, parent: :g5_authenticatable_role do
18
+ name 'editor'
19
+ end
20
+
21
+ factory :g5_authenticatable_viewer_role, parent: :g5_authenticatable_role do
22
+ name 'viewer'
23
+ end
24
+
25
+ factory :g5_authenticatable_client_role, parent: :g5_authenticatable_role do
26
+ association :resource, factory: :g5_updatable_client
27
+ end
28
+
29
+ factory :g5_authenticatable_client_admin_role,
30
+ parent: :g5_authenticatable_client_role do
31
+ name 'admin'
32
+ end
33
+
34
+ factory :g5_authenticatable_client_editor_role,
35
+ parent: :g5_authenticatable_client_role do
36
+ name 'editor'
37
+ end
38
+
39
+ factory :g5_authenticatable_client_viewer_role,
40
+ parent: :g5_authenticatable_client_role do
41
+ name 'viewer'
42
+ end
43
+
44
+ factory :g5_authenticatable_location_role,
45
+ parent: :g5_authenticatable_role do
46
+ association :resource, factory: :g5_updatable_location
47
+ end
48
+
49
+ factory :g5_authenticatable_location_admin_role,
50
+ parent: :g5_authenticatable_location_role do
51
+ name 'admin'
52
+ end
53
+
54
+ factory :g5_authenticatable_location_editor_role,
55
+ parent: :g5_authenticatable_location_role do
56
+ name 'editor'
57
+ end
58
+
59
+ factory :g5_authenticatable_location_viewer_role,
60
+ parent: :g5_authenticatable_location_role do
61
+ name 'viewer'
62
+ end
63
+ end
@@ -1,60 +1,8 @@
1
- require 'factory_girl_rails'
2
-
3
- FactoryGirl.define do
4
- factory :g5_authenticatable_user, class: 'G5Authenticatable::User' do
5
- sequence(:email) { |n| "test.user#{n}@test.host" }
6
- provider 'g5'
7
- sequence(:uid) { |n| "abc123-#{n}" }
8
- sequence(:g5_access_token) { |n| "secret_token_#{n}" }
9
- first_name 'Jane'
10
- last_name 'Doe'
11
- phone_number '(555) 867-5309'
12
- title 'Minister of Funny Walks'
13
- organization_name 'Department of Redundancy Department'
14
-
15
- after(:build) do |user|
16
- user.roles << FactoryGirl.build(:g5_authenticatable_viewer_role)
17
- end
18
- end
19
-
20
- factory :g5_authenticatable_super_admin, parent: :g5_authenticatable_user do
21
- after(:build) do |user|
22
- user.roles.clear
23
- user.roles << FactoryGirl.build(:g5_authenticatable_super_admin_role)
24
- end
25
- end
26
-
27
- factory :g5_authenticatable_admin, parent: :g5_authenticatable_user do
28
- after(:build) do |user|
29
- user.roles.clear
30
- user.roles << FactoryGirl.build(:g5_authenticatable_admin_role)
31
- end
32
- end
33
-
34
- factory :g5_authenticatable_editor, parent: :g5_authenticatable_user do
35
- after(:build) do |user|
36
- user.roles.clear
37
- user.roles << FactoryGirl.build(:g5_authenticatable_editor_role)
38
- end
39
- end
1
+ # frozen_string_literal: true
40
2
 
41
- factory :g5_authenticatable_role, class: 'G5Authenticatable::Role' do
42
- sequence(:name) { |n| "role_#{n}" }
43
- end
44
-
45
- factory :g5_authenticatable_super_admin_role, parent: :g5_authenticatable_role do
46
- name 'super_admin'
47
- end
48
-
49
- factory :g5_authenticatable_admin_role, parent: :g5_authenticatable_role do
50
- name 'admin'
51
- end
52
-
53
- factory :g5_authenticatable_editor_role, parent: :g5_authenticatable_role do
54
- name 'editor'
55
- end
56
-
57
- factory :g5_authenticatable_viewer_role, parent: :g5_authenticatable_role do
58
- name 'viewer'
59
- end
60
- end
3
+ require 'factory_girl_rails'
4
+ require 'g5_updatable/factories'
5
+ require 'g5_authenticatable/test/factories/roles'
6
+ require 'g5_authenticatable/test/factories/global_users'
7
+ require 'g5_authenticatable/test/factories/client_users'
8
+ require 'g5_authenticatable/test/factories/location_users'
@@ -1,25 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module G5Authenticatable
2
4
  module Test
5
+ # Helpers for feature specs
3
6
  module FeatureHelpers
4
- def stub_g5_omniauth(user, options={})
7
+ def stub_g5_omniauth(user, options = {})
5
8
  OmniAuth.config.mock_auth[:g5] = OmniAuth::AuthHash.new({
6
9
  uid: user.uid,
7
10
  provider: 'g5',
8
- info: {
9
- email: user.email,
10
- first_name: user.first_name,
11
- last_name: user.last_name,
12
- phone: user.phone_number
13
- },
14
- credentials: {token: user.g5_access_token},
15
- extra: {
16
- title: user.title,
17
- organization_name: user.organization_name,
18
- roles: user.roles.collect do |role|
19
- {name: role.name, type: 'GLOBAL', urn: nil}
20
- end,
21
- raw_info: {}
22
- }
11
+ info: basic_auth_info(user),
12
+ credentials: { token: user.g5_access_token },
13
+ extra: extra_auth_info(user)
23
14
  }.merge(options))
24
15
  end
25
16
 
@@ -32,11 +23,33 @@ module G5Authenticatable
32
23
  stub_valid_access_token(user.g5_access_token)
33
24
  visit path
34
25
  end
26
+
27
+ private
28
+
29
+ def basic_auth_info(user)
30
+ {
31
+ email: user.email,
32
+ first_name: user.first_name,
33
+ last_name: user.last_name,
34
+ phone: user.phone_number
35
+ }
36
+ end
37
+
38
+ def extra_auth_info(user)
39
+ {
40
+ title: user.title,
41
+ organization_name: user.organization_name,
42
+ roles: user.roles.collect do |role|
43
+ { name: role.name, type: 'GLOBAL', urn: nil }
44
+ end,
45
+ raw_info: {}
46
+ }
47
+ end
35
48
  end
36
49
  end
37
50
  end
38
51
 
39
- shared_context 'auth', auth: true do
52
+ RSpec.shared_context 'auth' do
40
53
  include G5Authenticatable::Test::FeatureHelpers
41
54
 
42
55
  let(:user) { FactoryGirl.create(:g5_authenticatable_user) }
@@ -52,4 +65,5 @@ RSpec.configure do |config|
52
65
  config.after(:each) { OmniAuth.config.test_mode = false }
53
66
 
54
67
  config.include G5Authenticatable::Test::FeatureHelpers, type: :feature
68
+ config.include_context 'auth', auth: true
55
69
  end