devise_g5_authenticatable 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -2
- data/circle.yml +1 -1
- data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +13 -2
- data/lib/devise_g5_authenticatable/version.rb +1 -1
- data/spec/dummy/app/controllers/{custom_registrations_controllers.rb → custom_registrations_controller.rb} +0 -0
- data/spec/dummy/app/models/user.rb +0 -3
- data/spec/dummy/config/application.rb +0 -7
- data/spec/dummy/config/environments/development.rb +3 -10
- data/spec/dummy/config/environments/test.rb +2 -6
- data/spec/dummy/config/initializers/devise.rb +4 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -5
- data/spec/features/registration_spec.rb +1 -1
- data/spec/g5/auth_user_creator_spec.rb +73 -53
- data/spec/models/protected_attributes_spec.rb +8 -0
- data/spec/spec_helper.rb +2 -0
- metadata +5 -7
- data/spec/dummy/config/environments/production.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c21c4321163499661d4fd43789dfcff59c38d10a
|
4
|
+
data.tar.gz: 7ae73de16b05661c29a0a092da8191b2242f442b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d75544ee10f7e7749c4f7b7a95504b76ff015d9bfc74dd168f7c369135c61d386622738f102843c20ff9c61f6872379688b20a09b187cbcb20f181645dbf2947
|
7
|
+
data.tar.gz: e73c4a027bdbfa89f39078becfe6f15dd1c6931da06222e3f6456114c7eec55391ba23c87fe44215d2593e7b76a2f6eba85777c9c96ae0c2e69edc15367bd161
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.2
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -4,9 +4,10 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
# Dependencies for the dummy test app
|
7
|
-
gem 'rails', '
|
7
|
+
gem 'rails', '4.1.4'
|
8
8
|
gem 'jquery-rails'
|
9
9
|
gem 'pg'
|
10
|
+
gem 'protected_attributes'
|
10
11
|
|
11
12
|
group :test, :development do
|
12
13
|
gem 'rspec-rails', '~> 2.14'
|
@@ -18,6 +19,6 @@ group :test do
|
|
18
19
|
gem 'simplecov'
|
19
20
|
gem 'codeclimate-test-reporter'
|
20
21
|
gem 'webmock'
|
21
|
-
gem 'shoulda-matchers'
|
22
|
+
gem 'shoulda-matchers', '~> 2.6'
|
22
23
|
gem 'factory_girl_rails', '~> 4.3', require: false
|
23
24
|
end
|
data/circle.yml
CHANGED
@@ -15,9 +15,19 @@ module Devise
|
|
15
15
|
|
16
16
|
private
|
17
17
|
def create_auth_user
|
18
|
-
auth_user = auth_client.create_user(auth_user_args)
|
19
18
|
set_auth_attributes(auth_user)
|
20
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
def auth_user
|
22
|
+
begin
|
23
|
+
auth_client.create_user(auth_user_args)
|
24
|
+
rescue StandardError => e
|
25
|
+
if e.message =~ /Email has already been taken/
|
26
|
+
auth_client.find_user_by_email(model.email)
|
27
|
+
else
|
28
|
+
raise e
|
29
|
+
end
|
30
|
+
end
|
21
31
|
end
|
22
32
|
|
23
33
|
def auth_user_exists?
|
@@ -42,6 +52,7 @@ module Devise
|
|
42
52
|
model.provider = 'g5'
|
43
53
|
model.uid = auth_user.id
|
44
54
|
model.clean_up_passwords
|
55
|
+
model
|
45
56
|
end
|
46
57
|
end
|
47
58
|
end
|
File without changes
|
@@ -4,7 +4,6 @@ require File.expand_path('../boot', __FILE__)
|
|
4
4
|
require 'active_record/railtie'
|
5
5
|
require 'action_controller/railtie'
|
6
6
|
require 'action_mailer/railtie'
|
7
|
-
require 'active_resource/railtie'
|
8
7
|
require 'sprockets/railtie'
|
9
8
|
|
10
9
|
Bundler.require(*Rails.groups)
|
@@ -49,12 +48,6 @@ module Dummy
|
|
49
48
|
# like if you have constraints or database-specific column types
|
50
49
|
# config.active_record.schema_format = :sql
|
51
50
|
|
52
|
-
# Enforce whitelist mode for mass assignment.
|
53
|
-
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
54
|
-
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
55
|
-
# parameters by using an attr_accessible or attr_protected declaration.
|
56
|
-
config.active_record.whitelist_attributes = true
|
57
|
-
|
58
51
|
# Enable the asset pipeline
|
59
52
|
config.assets.enabled = true
|
60
53
|
|
@@ -6,9 +6,6 @@ Dummy::Application.configure do
|
|
6
6
|
# since you don't have to restart the web server when you make code changes.
|
7
7
|
config.cache_classes = false
|
8
8
|
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
11
|
-
|
12
9
|
# Show full error reports and disable caching
|
13
10
|
config.consider_all_requests_local = true
|
14
11
|
config.action_controller.perform_caching = false
|
@@ -21,19 +18,15 @@ Dummy::Application.configure do
|
|
21
18
|
# Print deprecation notices to the Rails logger
|
22
19
|
config.active_support.deprecation = :log
|
23
20
|
|
24
|
-
# Only use best-standards-support built into browsers
|
25
|
-
config.action_dispatch.best_standards_support = :builtin
|
26
|
-
|
27
|
-
# Raise exception on mass assignment protection for Active Record models
|
28
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
29
|
-
|
30
21
|
# Log the query plan for queries taking more than this (works
|
31
22
|
# with SQLite, MySQL, and PostgreSQL)
|
32
23
|
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
33
24
|
|
34
25
|
# Do not compress assets
|
35
|
-
config.assets.
|
26
|
+
config.assets.js_compressor = nil
|
36
27
|
|
37
28
|
# Expands the lines which load the assets
|
38
29
|
config.assets.debug = true
|
30
|
+
|
31
|
+
config.eager_load = false
|
39
32
|
end
|
@@ -11,9 +11,6 @@ Dummy::Application.configure do
|
|
11
11
|
config.serve_static_assets = true
|
12
12
|
config.static_cache_control = "public, max-age=3600"
|
13
13
|
|
14
|
-
# Log error messages when you accidentally call methods on nil
|
15
|
-
config.whiny_nils = true
|
16
|
-
|
17
14
|
# Show full error reports and disable caching
|
18
15
|
config.consider_all_requests_local = true
|
19
16
|
config.action_controller.perform_caching = false
|
@@ -29,9 +26,8 @@ Dummy::Application.configure do
|
|
29
26
|
# ActionMailer::Base.deliveries array.
|
30
27
|
config.action_mailer.delivery_method = :test
|
31
28
|
|
32
|
-
# Raise exception on mass assignment protection for Active Record models
|
33
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
34
|
-
|
35
29
|
# Print deprecation notices to the stderr
|
36
30
|
config.active_support.deprecation = :stderr
|
31
|
+
|
32
|
+
config.eager_load = false
|
37
33
|
end
|
@@ -21,6 +21,10 @@ Devise.setup do |config|
|
|
21
21
|
# available as additional gems.
|
22
22
|
require 'devise/orm/active_record'
|
23
23
|
|
24
|
+
# Require optional support for protected_attributes in devise
|
25
|
+
# models
|
26
|
+
require 'devise_g5_authenticatable/models/protected_attributes'
|
27
|
+
|
24
28
|
# ==> Configuration for any authentication mechanism
|
25
29
|
# Configure which keys are used when authenticating a user. The default is
|
26
30
|
# just :email. You can configure it to use [:username, :subdomain], so for
|
@@ -5,3 +5,4 @@
|
|
5
5
|
# Make sure the secret is at least 30 characters and all random,
|
6
6
|
# no regular words or you'll be exposed to dictionary attacks.
|
7
7
|
Dummy::Application.config.secret_token = '647a56085c4f52cc5e906029f424ff1fa1d118d66800fb131b28c7ef7467f379f253ec847cc15af0036a8c55a4c547c9ef73d09d17bf00f9ecbd6823e90edbae'
|
8
|
+
Dummy::Application.config.secret_key_base = '77ca04658d54f9b0e5ec8d6331964640bb6237e145d03031b88a0186a13cb584b6e5031e6956ba23f37941a216f91387b6f1b9999eae0fb0ba598d798fa58367'
|
@@ -76,7 +76,7 @@ describe 'User registration' do
|
|
76
76
|
let(:password_confirmation) { 'something else entirely' }
|
77
77
|
|
78
78
|
it_should_behave_like 'a registration validation error' do
|
79
|
-
let(:error_message) { "Password doesn't match
|
79
|
+
let(:error_message) { "Password confirmation doesn't match" }
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -16,84 +16,104 @@ describe Devise::G5::AuthUserCreator do
|
|
16
16
|
let(:password) { 'new password' }
|
17
17
|
let(:password_confirmation) { 'new password confirmation' }
|
18
18
|
|
19
|
-
let(:auth_client) { double(:g5_authentication_client
|
20
|
-
let(:auth_user) { double(:auth_user, id: uid, email: model.email) }
|
19
|
+
let(:auth_client) { double(:g5_authentication_client) }
|
20
|
+
let(:auth_user) { double(:auth_user, id: uid, email: model.email, clean_up_passwords: nil) }
|
21
21
|
let(:uid) { 'remote-auth-user-42' }
|
22
|
+
|
22
23
|
before do
|
23
24
|
allow(G5AuthenticationClient::Client).to receive(:new).and_return(auth_client)
|
24
25
|
end
|
25
26
|
|
26
|
-
context 'when
|
27
|
-
before
|
27
|
+
context 'when there is an existing auth user' do
|
28
|
+
before do
|
29
|
+
model.uid = nil
|
30
|
+
allow(auth_client).to receive(:create_user).and_raise(StandardError.new('Email has already been taken'))
|
31
|
+
allow(auth_client).to receive(:find_user_by_email).and_return(auth_user)
|
32
|
+
create
|
33
|
+
end
|
28
34
|
|
29
|
-
|
30
|
-
|
35
|
+
it 'should create the local user with the existing uid' do
|
36
|
+
expect(model.uid).to eq(uid)
|
37
|
+
end
|
38
|
+
end
|
31
39
|
|
32
|
-
|
40
|
+
context 'when there is no existing auth user' do
|
41
|
+
before do
|
42
|
+
allow(auth_client).to receive(:create_user).and_return(auth_user)
|
43
|
+
end
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
with(access_token: updated_by.g5_access_token)
|
37
|
-
end
|
45
|
+
context 'when the new model has no uid' do
|
46
|
+
before { model.uid = nil }
|
38
47
|
|
39
|
-
|
40
|
-
|
41
|
-
with(hash_including(email: model.email))
|
42
|
-
end
|
48
|
+
context 'when updated by an existing user' do
|
49
|
+
let(:updated_by) { build_stubbed(:user) }
|
43
50
|
|
44
|
-
|
45
|
-
expect(auth_client).to have_received(:create_user).
|
46
|
-
with(hash_including(password: password))
|
47
|
-
end
|
51
|
+
before { create }
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
it 'should use the token for updated_by user to call g5 auth' do
|
54
|
+
expect(G5AuthenticationClient::Client).to have_received(:new).
|
55
|
+
with(access_token: updated_by.g5_access_token)
|
56
|
+
end
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
it 'should create a new auth user with the correct email' do
|
59
|
+
expect(auth_client).to have_received(:create_user).
|
60
|
+
with(hash_including(email: model.email))
|
61
|
+
end
|
57
62
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
it 'should create a new auth user with the correct password' do
|
64
|
+
expect(auth_client).to have_received(:create_user).
|
65
|
+
with(hash_including(password: password))
|
66
|
+
end
|
62
67
|
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
it 'should create a new auth user with the correct password confirmation' do
|
69
|
+
expect(auth_client).to have_received(:create_user).
|
70
|
+
with(hash_including(password_confirmation: password_confirmation))
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should reset the password' do
|
74
|
+
expect(model.password).to be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should reset the password_confirmation' do
|
78
|
+
expect(model.password_confirmation).to be_nil
|
79
|
+
end
|
66
80
|
end
|
67
81
|
|
68
|
-
|
69
|
-
|
82
|
+
context 'when auth service returns an error' do
|
83
|
+
before do
|
84
|
+
allow(auth_client).to receive(:create_user).and_raise('Error!')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should raise an exception' do
|
88
|
+
expect { create }.to raise_error('Error!')
|
89
|
+
end
|
70
90
|
end
|
71
|
-
end
|
72
91
|
|
73
|
-
|
74
|
-
|
92
|
+
context 'when not updated by an existing user' do
|
93
|
+
before { create }
|
75
94
|
|
76
|
-
|
77
|
-
|
78
|
-
|
95
|
+
it 'should use the user token to call g5 auth' do
|
96
|
+
expect(G5AuthenticationClient::Client).to have_received(:new).
|
97
|
+
with(access_token: model.g5_access_token)
|
98
|
+
end
|
79
99
|
end
|
80
100
|
end
|
81
|
-
end
|
82
101
|
|
83
|
-
|
84
|
-
|
85
|
-
|
102
|
+
context 'when new model already has a uid' do
|
103
|
+
before { model.uid = 'remote-user-42' }
|
104
|
+
before { create }
|
86
105
|
|
87
|
-
|
88
|
-
|
89
|
-
|
106
|
+
it 'should not create a user' do
|
107
|
+
expect(auth_client).to_not have_received(:create_user)
|
108
|
+
end
|
90
109
|
|
91
|
-
|
92
|
-
|
93
|
-
|
110
|
+
it 'should not reset the password' do
|
111
|
+
expect(model.password).to_not be_blank
|
112
|
+
end
|
94
113
|
|
95
|
-
|
96
|
-
|
114
|
+
it 'should not reset the password_confirmation' do
|
115
|
+
expect(model.password_confirmation).to_not be_blank
|
116
|
+
end
|
97
117
|
end
|
98
118
|
end
|
99
119
|
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DeviseG5Authenticatable::Models::ProtectedAttributes do
|
4
|
+
before do
|
5
|
+
Dummy::Application.config.active_record.whitelist_attributes = true
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
Dummy::Application.config.active_record.whitelist_attributes = false
|
10
|
+
end
|
11
|
+
|
4
12
|
subject { model }
|
5
13
|
|
6
14
|
let(:model_class) { User }
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_g5_authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maeve Revels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -102,7 +102,7 @@ files:
|
|
102
102
|
- spec/dummy/app/assets/stylesheets/custom_sessions.css
|
103
103
|
- spec/dummy/app/assets/stylesheets/home.css
|
104
104
|
- spec/dummy/app/controllers/application_controller.rb
|
105
|
-
- spec/dummy/app/controllers/
|
105
|
+
- spec/dummy/app/controllers/custom_registrations_controller.rb
|
106
106
|
- spec/dummy/app/controllers/custom_sessions_controller.rb
|
107
107
|
- spec/dummy/app/controllers/home_controller.rb
|
108
108
|
- spec/dummy/app/helpers/application_helper.rb
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- spec/dummy/config/database.yml.sample
|
122
122
|
- spec/dummy/config/environment.rb
|
123
123
|
- spec/dummy/config/environments/development.rb
|
124
|
-
- spec/dummy/config/environments/production.rb
|
125
124
|
- spec/dummy/config/environments/test.rb
|
126
125
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
127
126
|
- spec/dummy/config/initializers/devise.rb
|
@@ -197,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
196
|
version: '0'
|
198
197
|
requirements: []
|
199
198
|
rubyforge_project:
|
200
|
-
rubygems_version: 2.2.
|
199
|
+
rubygems_version: 2.2.2
|
201
200
|
signing_key:
|
202
201
|
specification_version: 4
|
203
202
|
summary: Devise extension for the G5 Auth service
|
@@ -216,7 +215,7 @@ test_files:
|
|
216
215
|
- spec/dummy/app/assets/stylesheets/custom_sessions.css
|
217
216
|
- spec/dummy/app/assets/stylesheets/home.css
|
218
217
|
- spec/dummy/app/controllers/application_controller.rb
|
219
|
-
- spec/dummy/app/controllers/
|
218
|
+
- spec/dummy/app/controllers/custom_registrations_controller.rb
|
220
219
|
- spec/dummy/app/controllers/custom_sessions_controller.rb
|
221
220
|
- spec/dummy/app/controllers/home_controller.rb
|
222
221
|
- spec/dummy/app/helpers/application_helper.rb
|
@@ -235,7 +234,6 @@ test_files:
|
|
235
234
|
- spec/dummy/config/database.yml.sample
|
236
235
|
- spec/dummy/config/environment.rb
|
237
236
|
- spec/dummy/config/environments/development.rb
|
238
|
-
- spec/dummy/config/environments/production.rb
|
239
237
|
- spec/dummy/config/environments/test.rb
|
240
238
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
241
239
|
- spec/dummy/config/initializers/devise.rb
|
@@ -1,67 +0,0 @@
|
|
1
|
-
Dummy::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# Code is not reloaded between requests
|
5
|
-
config.cache_classes = true
|
6
|
-
|
7
|
-
# Full error reports are disabled and caching is turned on
|
8
|
-
config.consider_all_requests_local = false
|
9
|
-
config.action_controller.perform_caching = true
|
10
|
-
|
11
|
-
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
-
config.serve_static_assets = false
|
13
|
-
|
14
|
-
# Compress JavaScripts and CSS
|
15
|
-
config.assets.compress = true
|
16
|
-
|
17
|
-
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
-
config.assets.compile = false
|
19
|
-
|
20
|
-
# Generate digests for assets URLs
|
21
|
-
config.assets.digest = true
|
22
|
-
|
23
|
-
# Defaults to nil and saved in location specified by config.assets.prefix
|
24
|
-
# config.assets.manifest = YOUR_PATH
|
25
|
-
|
26
|
-
# Specifies the header that your server uses for sending files
|
27
|
-
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
-
|
30
|
-
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
-
# config.force_ssl = true
|
32
|
-
|
33
|
-
# See everything in the log (default is :info)
|
34
|
-
# config.log_level = :debug
|
35
|
-
|
36
|
-
# Prepend all log lines with the following tags
|
37
|
-
# config.log_tags = [ :subdomain, :uuid ]
|
38
|
-
|
39
|
-
# Use a different logger for distributed setups
|
40
|
-
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
41
|
-
|
42
|
-
# Use a different cache store in production
|
43
|
-
# config.cache_store = :mem_cache_store
|
44
|
-
|
45
|
-
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
46
|
-
# config.action_controller.asset_host = "http://assets.example.com"
|
47
|
-
|
48
|
-
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
-
# config.assets.precompile += %w( search.js )
|
50
|
-
|
51
|
-
# Disable delivery errors, bad email addresses will be ignored
|
52
|
-
# config.action_mailer.raise_delivery_errors = false
|
53
|
-
|
54
|
-
# Enable threaded mode
|
55
|
-
# config.threadsafe!
|
56
|
-
|
57
|
-
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
-
# the I18n.default_locale when a translation can not be found)
|
59
|
-
config.i18n.fallbacks = true
|
60
|
-
|
61
|
-
# Send deprecation notices to registered listeners
|
62
|
-
config.active_support.deprecation = :notify
|
63
|
-
|
64
|
-
# Log the query plan for queries taking more than this (works
|
65
|
-
# with SQLite, MySQL, and PostgreSQL)
|
66
|
-
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
|
-
end
|