devise_g5_authenticatable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +23 -0
- data/LICENSE +20 -0
- data/README.md +243 -0
- data/Rakefile +20 -0
- data/app/controllers/devise_g5_authenticatable/registrations_controller.rb +5 -0
- data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +58 -0
- data/circle.yml +4 -0
- data/config/initializers/devise_g5_authenticatable.rb +3 -0
- data/config/locales/en.yml +6 -0
- data/devise_g5_authenticatable.gemspec +24 -0
- data/lib/devise_g5_authenticatable.rb +16 -0
- data/lib/devise_g5_authenticatable/controllers/helpers.rb +37 -0
- data/lib/devise_g5_authenticatable/controllers/url_helpers.rb +13 -0
- data/lib/devise_g5_authenticatable/engine.rb +11 -0
- data/lib/devise_g5_authenticatable/g5.rb +4 -0
- data/lib/devise_g5_authenticatable/g5/auth_password_validator.rb +30 -0
- data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +48 -0
- data/lib/devise_g5_authenticatable/g5/auth_user_updater.rb +43 -0
- data/lib/devise_g5_authenticatable/g5/user_exporter.rb +61 -0
- data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +99 -0
- data/lib/devise_g5_authenticatable/models/protected_attributes.rb +16 -0
- data/lib/devise_g5_authenticatable/omniauth.rb +9 -0
- data/lib/devise_g5_authenticatable/routes.rb +58 -0
- data/lib/devise_g5_authenticatable/version.rb +3 -0
- data/lib/tasks/g5/export_users.rake +13 -0
- data/spec/controllers/helpers_spec.rb +295 -0
- data/spec/controllers/sessions_controller_spec.rb +256 -0
- data/spec/controllers/url_helpers_spec.rb +332 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/custom_sessions.js +2 -0
- data/spec/dummy/app/assets/javascripts/home.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/custom_sessions.css +4 -0
- data/spec/dummy/app/assets/stylesheets/home.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/custom_registrations_controllers.rb +2 -0
- data/spec/dummy/app/controllers/custom_sessions_controller.rb +2 -0
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/custom_sessions_helper.rb +2 -0
- data/spec/dummy/app/helpers/home_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/admin.rb +3 -0
- data/spec/dummy/app/models/user.rb +10 -0
- data/spec/dummy/app/views/anonymous/new.html.erb +0 -0
- data/spec/dummy/app/views/home/index.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +64 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml.ci +6 -0
- data/spec/dummy/config/database.yml.sample +13 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +39 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +259 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +60 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +70 -0
- data/spec/dummy/db/migrate/20131230235849_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20140102213131_drop_database_authenticatable.rb +16 -0
- data/spec/dummy/db/migrate/20140103032308_drop_recoverable.rb +16 -0
- data/spec/dummy/db/migrate/20140103042329_drop_rememberable.rb +13 -0
- data/spec/dummy/db/migrate/20140103174810_add_omniauth_columns_to_users.rb +18 -0
- data/spec/dummy/db/migrate/20140103191601_add_email_back_to_user.rb +8 -0
- data/spec/dummy/db/migrate/20140113202948_devise_create_admins.rb +42 -0
- data/spec/dummy/db/migrate/20140113233821_add_provider_and_uid_to_admins.rb +8 -0
- data/spec/dummy/db/schema.rb +50 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/factories/admin.rb +10 -0
- data/spec/factories/user.rb +10 -0
- data/spec/features/edit_registration_spec.rb +109 -0
- data/spec/features/registration_spec.rb +99 -0
- data/spec/features/sign_in_spec.rb +91 -0
- data/spec/features/sign_out_spec.rb +7 -0
- data/spec/g5/auth_password_validator_spec.rb +81 -0
- data/spec/g5/auth_user_creator_spec.rb +100 -0
- data/spec/g5/auth_user_updater_spec.rb +113 -0
- data/spec/g5/user_exporter_spec.rb +105 -0
- data/spec/models/g5_authenticatable_spec.rb +540 -0
- data/spec/models/protected_attributes_spec.rb +17 -0
- data/spec/routing/registrations_routing_spec.rb +107 -0
- data/spec/routing/sessions_routing_spec.rb +111 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/devise.rb +3 -0
- data/spec/support/omniauth.rb +3 -0
- data/spec/support/shared_contexts/oauth_error.rb +9 -0
- data/spec/support/shared_contexts/rake.rb +21 -0
- data/spec/support/shared_examples/registration_error.rb +15 -0
- data/spec/support/user_feature_methods.rb +26 -0
- data/spec/tasks/export_users_spec.rb +90 -0
- metadata +293 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DeviseG5Authenticatable::Models::ProtectedAttributes do
|
4
|
+
subject { model }
|
5
|
+
|
6
|
+
let(:model_class) { User }
|
7
|
+
let(:model) { model_class.new }
|
8
|
+
|
9
|
+
it { should allow_mass_assignment_of(:email) }
|
10
|
+
it { should allow_mass_assignment_of(:password) }
|
11
|
+
it { should allow_mass_assignment_of(:password_confirmation) }
|
12
|
+
it { should allow_mass_assignment_of(:provider) }
|
13
|
+
it { should allow_mass_assignment_of(:uid) }
|
14
|
+
it { should_not allow_mass_assignment_of(:g5_access_token) }
|
15
|
+
it { should allow_mass_assignment_of(:current_password) }
|
16
|
+
it { should allow_mass_assignment_of(:updated_by) }
|
17
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Registrations controller' do
|
4
|
+
describe 'routing' do
|
5
|
+
context 'with user scope' do
|
6
|
+
it 'should route GET /users/sign_up' do
|
7
|
+
expect(get '/users/sign_up').to route_to(controller: 'devise_g5_authenticatable/registrations',
|
8
|
+
action: 'new')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should route POST /users' do
|
12
|
+
expect(post '/users').to route_to(controller: 'devise_g5_authenticatable/registrations',
|
13
|
+
action: 'create')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should route GET /users/edit' do
|
17
|
+
expect(get '/users/edit').to route_to(controller: 'devise_g5_authenticatable/registrations',
|
18
|
+
action: 'edit')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should route PUT /users' do
|
22
|
+
expect(put '/users').to route_to(controller: 'devise_g5_authenticatable/registrations',
|
23
|
+
action: 'update')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should route DELETE /users' do
|
27
|
+
expect(delete '/users').to route_to(controller: 'devise_g5_authenticatable/registrations',
|
28
|
+
action: 'destroy')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should route GET /users/cancel' do
|
32
|
+
expect(get '/users/cancel').to route_to(controller: 'devise_g5_authenticatable/registrations',
|
33
|
+
action: 'cancel')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with admin scope' do
|
38
|
+
it 'should route GET /registered/admins/custom_sign_up' do
|
39
|
+
expect(get '/registered/admins/custom_sign_up').to route_to(controller: 'custom_registrations',
|
40
|
+
action: 'new')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should route POST /registered/admins' do
|
44
|
+
expect(post '/registered/admins').to route_to(controller: 'custom_registrations',
|
45
|
+
action: 'create')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should route GET /registered/admins/edit' do
|
49
|
+
expect(get '/registered/admins/edit').to route_to(controller: 'custom_registrations',
|
50
|
+
action: 'edit')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should route PUT /registered/admins' do
|
54
|
+
expect(put '/registered/admins').to route_to(controller: 'custom_registrations',
|
55
|
+
action: 'update')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should route DELETE /registered/admins' do
|
59
|
+
expect(delete '/registered/admins').to route_to(controller: 'custom_registrations',
|
60
|
+
action: 'destroy')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should route GET /registered/admins/custom_cancel' do
|
64
|
+
expect(get '/registered/admins/custom_cancel').to route_to(controller: 'custom_registrations',
|
65
|
+
action: 'cancel')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'generated url helpers' do
|
71
|
+
context 'with user scope' do
|
72
|
+
it 'should generate new_user_registration_path' do
|
73
|
+
expect(new_user_registration_path).to eq('/users/sign_up')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should generate user_registration_path' do
|
77
|
+
expect(user_registration_path).to eq('/users')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should generate edit_user_registration_path' do
|
81
|
+
expect(edit_user_registration_path).to eq('/users/edit')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should generate cancel_user_registration_path' do
|
85
|
+
expect(cancel_user_registration_path).to eq('/users/cancel')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'with admin scope' do
|
90
|
+
it 'should generate new_admin_registration_path' do
|
91
|
+
expect(new_admin_registration_path).to eq('/registered/admins/custom_sign_up')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should generate admin_registration_path' do
|
95
|
+
expect(admin_registration_path).to eq('/registered/admins')
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should generate edit_admin_registration_path' do
|
99
|
+
expect(edit_admin_registration_path).to eq('/registered/admins/edit')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should generate cancel_admin_registration_path' do
|
103
|
+
expect(cancel_admin_registration_path).to eq('/registered/admins/custom_cancel')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Sessions controller' do
|
4
|
+
describe 'routing' do
|
5
|
+
context 'with user scope' do
|
6
|
+
it 'should route GET /users/sign_in' do
|
7
|
+
expect(get '/users/sign_in').to route_to(controller: 'devise_g5_authenticatable/sessions',
|
8
|
+
action: 'new')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should route DELETE /users/sign_out' do
|
12
|
+
expect(delete '/users/sign_out').to route_to(controller: 'devise_g5_authenticatable/sessions',
|
13
|
+
action: 'destroy')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should route GET /users/auth/g5' do
|
17
|
+
expect(get '/users/auth/g5').to route_to(controller: 'devise_g5_authenticatable/sessions',
|
18
|
+
action: 'omniauth_passthru')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should route POST /users/auth/g5' do
|
22
|
+
expect(post '/users/auth/g5').to route_to(controller: 'devise_g5_authenticatable/sessions',
|
23
|
+
action: 'omniauth_passthru')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should route GET /users/auth/g5/callback' do
|
27
|
+
expect(get '/users/auth/g5/callback').to route_to(controller: 'devise_g5_authenticatable/sessions',
|
28
|
+
action: 'create')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should route POST /users/auth/g5/callback' do
|
32
|
+
expect(post '/users/auth/g5/callback').to route_to(controller: 'devise_g5_authenticatable/sessions',
|
33
|
+
action: 'create')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should set the OmniAuth path prefix' do
|
37
|
+
expect(OmniAuth.config.path_prefix).to eq('/users/auth')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with admin scope' do
|
42
|
+
it 'should route GET /registered/admins/custom_sign_in' do
|
43
|
+
expect(get '/registered/admins/custom_sign_in').to route_to(controller: 'custom_sessions',
|
44
|
+
action: 'new')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should route DELETE /registered/admins/custom_sign_out' do
|
48
|
+
expect(delete '/registered/admins/custom_sign_out').to route_to(controller: 'custom_sessions',
|
49
|
+
action: 'destroy')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should route GET /registered/admins/auth/g5' do
|
53
|
+
expect(get '/registered/admins/auth/g5').to route_to(controller: 'custom_sessions',
|
54
|
+
action: 'omniauth_passthru')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should route POST /registered/admins/auth/g5' do
|
58
|
+
expect(post '/registered/admins/auth/g5').to route_to(controller: 'custom_sessions',
|
59
|
+
action: 'omniauth_passthru')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should route GET /registered/admins/auth/g5/callback' do
|
63
|
+
expect(get '/registered/admins/auth/g5/callback').to route_to(controller: 'custom_sessions',
|
64
|
+
action: 'create')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should route POST /registered/admins/auth/g5/callback' do
|
68
|
+
expect(post '/registered/admins/auth/g5/callback').to route_to(controller: 'custom_sessions',
|
69
|
+
action: 'create')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'generated url helpers' do
|
75
|
+
context 'with user scope' do
|
76
|
+
it 'should generate new_user_session_path' do
|
77
|
+
expect(new_user_session_path).to eq('/users/sign_in')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should generate destroy_user_session_path' do
|
81
|
+
expect(destroy_user_session_path).to eq('/users/sign_out')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should generate user_g5_authorize_path' do
|
85
|
+
expect(user_g5_authorize_path).to eq('/users/auth/g5')
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should generate user_g5_callback_path' do
|
89
|
+
expect(user_g5_callback_path).to eq('/users/auth/g5/callback')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'with admin scope' do
|
94
|
+
it 'should route new_admin_session_path' do
|
95
|
+
expect(new_admin_session_path).to eq('/registered/admins/custom_sign_in')
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should route destroy_admin_session_path' do
|
99
|
+
expect(destroy_admin_session_path).to eq('/registered/admins/custom_sign_out')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should generate admin_g5_authorize_path' do
|
103
|
+
expect(admin_g5_authorize_path).to eq('/registered/admins/auth/g5')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should generate admin_g5_callback_path' do
|
107
|
+
expect(admin_g5_callback_path).to eq('/registered/admins/auth/g5/callback')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Setup for test coverage instrumentation (e.g. simplecov, codeclimate)
|
2
|
+
# MUST happen before any other code is loaded
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start 'test_frameworks'
|
5
|
+
|
6
|
+
require 'codeclimate-test-reporter'
|
7
|
+
CodeClimate::TestReporter.start
|
8
|
+
|
9
|
+
require 'pry'
|
10
|
+
|
11
|
+
# Load rails dummy application
|
12
|
+
ENV['RAILS_ENV'] = 'test'
|
13
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
14
|
+
|
15
|
+
require 'rspec/rails'
|
16
|
+
require 'capybara/rspec'
|
17
|
+
require 'webmock/rspec'
|
18
|
+
require 'shoulda-matchers'
|
19
|
+
require 'factory_girl_rails'
|
20
|
+
|
21
|
+
# Load support files
|
22
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.include FactoryGirl::Syntax::Methods
|
26
|
+
|
27
|
+
config.use_transactional_fixtures = true
|
28
|
+
|
29
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
30
|
+
config.run_all_when_everything_filtered = true
|
31
|
+
config.filter_run :focus
|
32
|
+
|
33
|
+
# Run specs in random order to surface order dependencies. If you find an
|
34
|
+
# order dependency and want to debug it, you can fix the order by providing
|
35
|
+
# the seed, which is printed after each run.
|
36
|
+
# --seed 1234
|
37
|
+
config.order = 'random'
|
38
|
+
|
39
|
+
# The integration tests can be run with:
|
40
|
+
# rspec -t type:feature
|
41
|
+
# config.filter_run_excluding type: 'feature'
|
42
|
+
|
43
|
+
config.after(:suite) { WebMock.disable! }
|
44
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
shared_context 'OAuth2::Error' do
|
2
|
+
let(:oauth_error) { OAuth2::Error.new(oauth_response) }
|
3
|
+
let(:oauth_response) do
|
4
|
+
double(:oauth_response,
|
5
|
+
parsed: {'error' => error_message}).as_null_object
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:error_message) { 'Validation failed: Email is already taken' }
|
9
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Based on: http://robots.thoughtbot.com/test-rake-tasks-like-a-boss
|
2
|
+
# Modified for a non-Rails environment
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
shared_context 'rake' do
|
6
|
+
let(:rake) { Rake::Application.new }
|
7
|
+
let(:task_name) { self.class.top_level_description }
|
8
|
+
let(:task_path) { "lib/tasks/#{task_name.split(':').first}/#{task_name.split(':').last}" }
|
9
|
+
let(:root_path) { File.expand_path('../../../..', __FILE__) }
|
10
|
+
subject(:task) { rake[task_name] }
|
11
|
+
|
12
|
+
def loaded_files_excluding_current_rake_file
|
13
|
+
$".reject {|file| file =~ /#{task_path}\.rake$/ }
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
Rake.application = rake
|
18
|
+
Rake.application.rake_require(task_path, [root_path], loaded_files_excluding_current_rake_file)
|
19
|
+
Rake::Task.define_task(:environment)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
shared_examples_for 'a registration validation error' do
|
2
|
+
it 'should not create a user' do
|
3
|
+
expect { subject }.to_not change { User.count }
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'should not create a user on the auth server' do
|
7
|
+
subject
|
8
|
+
expect(auth_client).to_not have_received(:create_user)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should display an error message' do
|
12
|
+
subject
|
13
|
+
expect(page).to have_content(error_message)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module UserFeatureMethods
|
2
|
+
def stub_g5_omniauth(user, options={})
|
3
|
+
OmniAuth.config.mock_auth[:g5] = OmniAuth::AuthHash.new({
|
4
|
+
uid: user.uid,
|
5
|
+
provider: 'g5',
|
6
|
+
info: {email: user.email},
|
7
|
+
credentials: {token: user.g5_access_token}
|
8
|
+
}.merge(options))
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_g5_invalid_credentials
|
12
|
+
OmniAuth.config.mock_auth[:g5] = :invalid_credentials
|
13
|
+
end
|
14
|
+
|
15
|
+
def visit_path_and_login_with(path, user)
|
16
|
+
stub_g5_omniauth(user)
|
17
|
+
visit path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.before(:each) { OmniAuth.config.test_mode = true }
|
23
|
+
config.after(:each) { OmniAuth.config.test_mode = false }
|
24
|
+
|
25
|
+
config.include UserFeatureMethods, type: :feature
|
26
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'g5:export_users' do
|
4
|
+
include_context 'rake'
|
5
|
+
|
6
|
+
let(:user_exporter) { double(:user_exporter, export: nil) }
|
7
|
+
before { allow(G5::UserExporter).to receive(:new).and_return(user_exporter) }
|
8
|
+
|
9
|
+
before { ENV['G5_AUTH_CLIENT_ID'] = default_client_id }
|
10
|
+
let(:default_client_id) { 'default_client_id' }
|
11
|
+
|
12
|
+
before { ENV['G5_AUTH_CLIENT_SECRET'] = default_client_secret }
|
13
|
+
let(:default_client_secret) { 'default_client_secret' }
|
14
|
+
|
15
|
+
before { ENV['G5_AUTH_REDIRECT_URI'] = default_redirect_uri }
|
16
|
+
let(:default_redirect_uri) { 'http://test.host/default' }
|
17
|
+
|
18
|
+
before { ENV['G5_AUTH_ENDPOINT'] = default_endpoint }
|
19
|
+
let(:default_endpoint) { 'https://my.g5auth.host' }
|
20
|
+
|
21
|
+
before { ENV['G5_AUTH_AUTHORIZATION_CODE'] = default_auth_code }
|
22
|
+
let(:default_auth_code) { 'default_auth_code' }
|
23
|
+
|
24
|
+
def expect_init_user_exporter_with(option_name, expected_value)
|
25
|
+
expect(G5::UserExporter).to receive(:new) do |args|
|
26
|
+
expect(args[option_name]).to eq(expected_value)
|
27
|
+
user_exporter
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should use the default authorization code from the environment' do
|
32
|
+
expect_init_user_exporter_with(:authorization_code, default_auth_code)
|
33
|
+
task.invoke
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should allow the default authorization code to be overridden by an argument' do
|
37
|
+
auth_code_arg = 'some new auth code'
|
38
|
+
expect_init_user_exporter_with(:authorization_code, auth_code_arg)
|
39
|
+
task.invoke(auth_code_arg)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should use the default client id from the environment' do
|
43
|
+
expect_init_user_exporter_with(:client_id, default_client_id)
|
44
|
+
task.invoke
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should allow the default client id to be overridden by an argument' do
|
48
|
+
client_id_arg = 'custom_client_id_override'
|
49
|
+
expect_init_user_exporter_with(:client_id, client_id_arg)
|
50
|
+
task.invoke(nil, client_id_arg)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should use the default client secret from the environment' do
|
54
|
+
expect_init_user_exporter_with(:client_secret, default_client_secret)
|
55
|
+
task.invoke
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should allow the default client secret to be overridden by an argument' do
|
59
|
+
client_secret_arg = 'custom client secret'
|
60
|
+
expect_init_user_exporter_with(:client_secret, client_secret_arg)
|
61
|
+
task.invoke(nil, nil, client_secret_arg)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should use the default redirect uri from the environment' do
|
65
|
+
expect_init_user_exporter_with(:redirect_uri, default_redirect_uri)
|
66
|
+
task.invoke
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should allow the default redirect uri to be overridden by an argument' do
|
70
|
+
redirect_uri_arg = 'http://test.localhost/custom/callback'
|
71
|
+
expect_init_user_exporter_with(:redirect_uri, redirect_uri_arg)
|
72
|
+
task.invoke(nil, nil, nil, redirect_uri_arg)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should use the default auth endpoint from the environment' do
|
76
|
+
expect_init_user_exporter_with(:endpoint, default_endpoint)
|
77
|
+
task.invoke
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should allow the default auth endpoint to be overridden by an argument' do
|
81
|
+
endpoint_arg = 'https://custom-arg.auth.host'
|
82
|
+
expect_init_user_exporter_with(:endpoint, endpoint_arg)
|
83
|
+
task.invoke(nil, nil, nil, nil, endpoint_arg)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should export the users' do
|
87
|
+
expect(user_exporter).to receive(:export)
|
88
|
+
task.invoke
|
89
|
+
end
|
90
|
+
end
|