devise-remote-user 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48592394d5ad5267cdcdc0bc948a590670611ff8
4
- data.tar.gz: 46b4a6ffb866678720842a98258f9cfc0757f32c
3
+ metadata.gz: 5c22c1528b31943554d224bf190fcc0ff7abb81c
4
+ data.tar.gz: c5dd7031e1926d72301aac9694ae375e317802a3
5
5
  SHA512:
6
- metadata.gz: b72a73def63dbe2cd8157e1e50bd4c582a406562f61223611d534c6079545e92c96494a4beb858882100ac340cad67f3e56534127d41f01eac8735bdfd92d62b
7
- data.tar.gz: 363d81d3272248acd1d83ea1812110f413180fa47cbb42cbab76fa6c34be117a03e4d554198f208c48d6fff9ce2acaf4af5040ffc51f7b31dc296267b6f31c7a
6
+ metadata.gz: 75dac7385bbdb025cac7159f6e14b6ab40d28ca3eaa3cc0abd520b05a3161cc2da80f9f8c03d622f7b5ee6fdf6a849ec8c7670c472ad76b7d97651bc2fc945fb
7
+ data.tar.gz: 526eb0280f61dc90f3d7cd3261a4528af94c31d8548a2b8881ed2e55e6ddf2c6d544e87ec082baf1f7775b98fe3ff314234495e71d2fd19532d31ced3483d01b
data/README.md CHANGED
@@ -19,7 +19,7 @@ bundle install
19
19
 
20
20
  Sorry, there are no generators yet, so ...
21
21
 
22
- - Add `:remote_user_authenticatable` symbol to `devise` statement in User model.
22
+ - Add `:remote_user_authenticatable` symbol to `devise` statement in User model, before other authentication strategies (e.g., `:database_authenticatable`).
23
23
  - Add `before_filter :authenticate_user!` to ApplicationController, if not already present. This ensures that remote user is logged in locally (via database)
24
24
 
25
25
  Configuration options:
@@ -28,17 +28,19 @@ Configuration options:
28
28
  - `attribute_map` - Hash (default: `{}`). Map of User model attributes to request environment keys for updating the local user when auto-creation is enabled.
29
29
  - `auto_create` - Boolean (default: `false`). Whether to auto-create a local user from the remote user attributes. Note: Also requires adding the Warden callbacks as shown below.
30
30
  - `auto_update` - Boolean (default: `false`). Whether to auto-update authenticated user attributes from remote user attributes.
31
+ - `logout_url` - String (default: `'/'`). For redirecting to a remote user logout URL after signing out of the Rails application. Include `DeviseRemoteUser::ControllerBehavior` in your application controller to enable (by overriding Devise's `after_sign_out_path_for`).
31
32
 
32
- Set options in `config/intializers/devise.rb`:
33
+ Set options in a Rails initializer (e.g., `config/intializers/devise.rb`):
33
34
 
34
35
  ```ruby
35
- require 'devise-remote-user'
36
+ require 'devise_remote_user'
36
37
 
37
38
  DeviseRemoteUser.configure do |config|
38
39
  config.env_key = 'REMOTE_USER'
39
40
  config.auto_create = true
40
41
  config.auto_update = true
41
42
  config.attribute_map = {email: 'mail'}
43
+ config.logout_url = "http://my.host/path.to.remote.logout"
42
44
  end
43
45
  ```
44
46
 
@@ -18,10 +18,10 @@ Gem::Specification.new do |s|
18
18
  s.test_files = Dir["spec/**/*"]
19
19
  s.extra_rdoc_files = ["LICENSE", "README.md"]
20
20
  s.require_paths = ["lib"]
21
- s.add_dependency "rails", ">= 3.2"
21
+ s.add_dependency "rails", ">= 3.2", "< 5.0"
22
22
  s.add_dependency "devise"
23
23
  s.add_development_dependency "sqlite3"
24
- s.add_development_dependency "rspec-rails"
24
+ s.add_development_dependency "rspec-rails", "~> 2.14.1"
25
25
  s.add_development_dependency "factory_girl_rails"
26
26
  s.add_development_dependency "capybara"
27
27
  end
@@ -1,5 +1,6 @@
1
1
  require 'devise'
2
2
  require 'devise_remote_user/engine'
3
+ require 'devise_remote_user/controller_behavior'
3
4
 
4
5
  module DeviseRemoteUser
5
6
 
@@ -25,6 +26,12 @@ module DeviseRemoteUser
25
26
  mattr_accessor :attribute_map
26
27
  @@attribute_map = {}
27
28
 
29
+ # Settings for redirecting to the remote user logout URL
30
+ # Enable by including DeviseRemoteUser::Controllers::Helpers in ApplicationController
31
+ # (it overrides Devise's after_sign_out_path_for method).
32
+ mattr_accessor :logout_url
33
+ @@logout_url = '/'
34
+
28
35
  def self.configure
29
36
  yield self
30
37
  end
@@ -0,0 +1,16 @@
1
+ module DeviseRemoteUser
2
+ module ControllerBehavior
3
+
4
+ def after_sign_out_path_for(resource_or_scope)
5
+ return DeviseRemoteUser.logout_url if remote_user_authenticated? and DeviseRemoteUser.logout_url
6
+ super
7
+ end
8
+
9
+ private
10
+
11
+ def remote_user_authenticated?
12
+ request.env[DeviseRemoteUser.env_key].present?
13
+ end
14
+
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module DeviseRemoteUser
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -12,45 +12,45 @@ describe ApplicationController do
12
12
  end
13
13
  end
14
14
 
15
+ after { User.destroy_all }
16
+
15
17
  describe "remote user authentication" do
16
- describe "remote user exists" do
18
+
19
+ describe "when remote user exists" do
17
20
  let(:user) { FactoryGirl.create(:user) }
18
- after { user.delete }
21
+ before { controller.remote_user_name = user.email }
19
22
  it "should login the remote user" do
20
- controller.remote_user_name = user.email
21
23
  get :index
22
- controller.user_signed_in?.should be_true
23
- controller.current_user.should eq(user)
24
+ expect(controller.user_signed_in?).to be_true
25
+ expect(controller.current_user).to eq(user)
24
26
  end
25
27
  end
26
- describe "remote user not present" do
28
+
29
+ describe "when remote user is not present" do
30
+ before { controller.remote_user_name = nil }
27
31
  it "should do nothing" do
28
- controller.remote_user_name = nil
29
32
  get :index
30
- controller.user_signed_in?.should be_false
33
+ expect(controller.user_signed_in?).to be_false
31
34
  end
32
35
  end
33
- describe "remote user does not exist" do
36
+
37
+ describe "when remote user does not exist" do
34
38
  let(:email) { "foo@bar.com" }
35
- describe "auto-creation enabled" do
36
- before { DeviseRemoteUser.auto_create = true }
37
- after { @user.delete }
39
+ before { controller.remote_user_name = email }
40
+
41
+ describe "and auto-creation is enabled" do
42
+ before { allow(DeviseRemoteUser).to receive(:auto_create) { true } }
38
43
  it "should create and sign in a new user" do
39
- User.find_by_email(email).should be_nil
40
- controller.remote_user_name = email
41
44
  get :index
42
- response.should be_successful
43
- controller.user_signed_in?.should be_true
44
- @user = User.find_by_email(email)
45
- @user.should_not be_nil
46
- controller.current_user.should eq(@user)
45
+ expect(response).to be_successful
46
+ expect(controller.user_signed_in?).to be_true
47
+ expect(User.find_by_email(email)).to eq(controller.current_user)
47
48
  end
48
49
  end
49
- describe "auto-creation disabled" do
50
- before { DeviseRemoteUser.auto_create = false }
50
+
51
+ describe "and auto-creation is disabled" do
52
+ before { allow(DeviseRemoteUser).to receive(:auto_create) { false } }
51
53
  it "should not create a user for the remote user" do
52
- User.find_by_email(email).should be_nil
53
- controller.remote_user_name = email
54
54
  get :index
55
55
  response.should_not be_successful
56
56
  controller.user_signed_in?.should be_false
@@ -58,47 +58,49 @@ describe ApplicationController do
58
58
  end
59
59
  end
60
60
  end
61
- describe "a local database user is already signed in" do
61
+
62
+ describe "when a local database user is already signed in" do
62
63
  let(:local_user) { FactoryGirl.create(:user) }
63
64
  before do
64
- DeviseRemoteUser.auto_create = true
65
+ allow(DeviseRemoteUser).to receive(:auto_create) { true }
65
66
  controller.remote_user_name = remote_user.email
66
67
  sign_in local_user
67
68
  end
68
- after { local_user.delete }
69
- describe "remote user exists" do
69
+
70
+ describe "and remote user exists" do
70
71
  let(:remote_user) { FactoryGirl.create(:user) }
71
- after { remote_user.delete }
72
72
  it "should not clobber the existing user session" do
73
73
  get :index
74
- controller.current_user.should eq(local_user)
75
- controller.current_user.should_not eq(remote_user)
74
+ expect(controller.current_user).to eq(local_user)
75
+ expect(controller.current_user).not_to eq(remote_user)
76
76
  end
77
77
  end
78
- describe "remote user does not exist" do
78
+
79
+ describe "and remote user does not exist" do
79
80
  let(:remote_user) { FactoryGirl.build(:user) }
80
81
  it "should not clobber the existing user session" do
81
82
  get :index
82
- controller.current_user.should eq(local_user)
83
- controller.current_user.should_not eq(remote_user)
84
- User.find_by_email(remote_user.email).should be_nil
83
+ expect(controller.current_user).to eq(local_user)
84
+ expect(controller.current_user).not_to eq(remote_user)
85
+ expect(User.find_by_email(remote_user.email)).to be_nil
85
86
  end
86
87
  end
87
88
  end
89
+
88
90
  describe "auto-updating user attributes" do
89
91
  let(:user) { FactoryGirl.create(:user, first_name: 'Hardy', last_name: 'HarHar', nickname: "Laurel's Buddy", display_name: 'Hardy HarHar') }
90
92
  before do
91
- DeviseRemoteUser.attribute_map = {
92
- first_name: 'givenName',
93
- nickname: 'eduPersonNickname',
94
- last_name: 'sn',
95
- display_name: 'displayName'
96
- }
93
+ allow(DeviseRemoteUser).to receive(:attribute_map) do
94
+ { first_name: 'givenName',
95
+ nickname: 'eduPersonNickname',
96
+ last_name: 'sn',
97
+ display_name: 'displayName' }
98
+ end
97
99
  end
98
- after { user.delete }
99
- describe "auto-creation disabled" do
100
- before { DeviseRemoteUser.auto_update = false }
101
- it "should not update the user attributes" do
100
+
101
+ describe "when auto-creation is disabled" do
102
+ before do
103
+ allow(DeviseRemoteUser).to receive(:auto_update) { false }
102
104
  controller.remote_user_name = user.email
103
105
  controller.remote_user_attributes = {
104
106
  'givenName' => 'Fleece',
@@ -106,35 +108,42 @@ describe ApplicationController do
106
108
  'eduPersonNickname' => 'Iconoclast',
107
109
  'displayName' => 'Fleece Vest (Iconoclast)'
108
110
  }
111
+ end
112
+ it "should not update the user attributes" do
109
113
  get :index
110
114
  user.reload
111
- user.first_name.should == 'Hardy'
112
- user.last_name.should == 'HarHar'
113
- user.display_name.should == 'Hardy HarHar'
114
- user.nickname.should == "Laurel's Buddy"
115
+ expect(user.first_name).to eq('Hardy')
116
+ expect(user.last_name).to eq('HarHar')
117
+ expect(user.display_name).to eq('Hardy HarHar')
118
+ expect(user.nickname).to eq("Laurel's Buddy")
115
119
  end
116
120
  end
117
- describe "auto-creation enabled" do
118
- before { DeviseRemoteUser.auto_update = true }
119
- describe "database authentication wins" do
121
+
122
+ describe "when auto-creation is enabled" do
123
+ before do
124
+ allow(DeviseRemoteUser).to receive(:auto_update) { true }
125
+ controller.remote_user_attributes = {
126
+ 'givenName' => 'Fleece',
127
+ 'sn' => 'Vest',
128
+ 'eduPersonNickname' => 'Iconoclast',
129
+ 'displayName' => 'Fleece Vest (Iconoclast)'
130
+ }
131
+ end
132
+
133
+ describe "and database authentication wins" do
134
+ before { sign_in user }
120
135
  it "should not update the user attributes" do
121
- sign_in user
122
- controller.remote_user_attributes = {
123
- 'givenName' => 'Fleece',
124
- 'sn' => 'Vest',
125
- 'eduPersonNickname' => 'Iconoclast',
126
- 'displayName' => 'Fleece Vest (Iconoclast)'
127
- }
128
136
  get :index
129
137
  user.reload
130
- user.first_name.should == 'Hardy'
131
- user.last_name.should == 'HarHar'
132
- user.display_name.should == 'Hardy HarHar'
133
- user.nickname.should == "Laurel's Buddy"
138
+ expect(user.first_name).to eq('Hardy')
139
+ expect(user.last_name).to eq('HarHar')
140
+ expect(user.display_name).to eq('Hardy HarHar')
141
+ expect(user.nickname).to eq("Laurel's Buddy")
134
142
  end
135
143
  end
136
- describe "remote user authentication wins" do
137
- it "should update the user attributes" do
144
+
145
+ describe "and remote user authentication wins" do
146
+ before do
138
147
  controller.remote_user_name = user.email
139
148
  controller.remote_user_attributes = {
140
149
  'givenName' => 'Fleece',
@@ -142,16 +151,19 @@ describe ApplicationController do
142
151
  'eduPersonNickname' => 'Iconoclast',
143
152
  'displayName' => 'Fleece Vest (Iconoclast)'
144
153
  }
154
+ end
155
+ it "should update the user attributes" do
145
156
  get :index
146
157
  user.reload
147
- user.first_name.should == 'Fleece'
148
- user.last_name.should == 'Vest'
149
- user.display_name.should == 'Fleece Vest (Iconoclast)'
150
- user.nickname.should == 'Iconoclast'
158
+ expect(user.first_name).to eq('Fleece')
159
+ expect(user.last_name).to eq('Vest')
160
+ expect(user.display_name).to eq('Fleece Vest (Iconoclast)')
161
+ expect(user.nickname).to eq('Iconoclast')
151
162
  end
152
163
  end
153
164
  end
154
165
  end
166
+
155
167
  end
156
168
 
157
169
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::SessionsController do
4
+ before { @request.env["devise.mapping"] = Devise.mappings[:user] }
5
+ describe "logout" do
6
+ let(:user) { FactoryGirl.create(:user) }
7
+ describe "when user is remotely authenticated" do
8
+ before { @request.env[DeviseRemoteUser.env_key] = user.email }
9
+ it "should redirect to DeviseRemoteUser.logout_url" do
10
+ expect(get :destroy).to redirect_to(DeviseRemoteUser.logout_url)
11
+ end
12
+ end
13
+ describe "when user is not remotely authenticated" do
14
+ it "should redirect to the root path (Devise default)" do
15
+ expect(get :destroy).to redirect_to(root_path)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::SessionsController do
4
+ before { @request.env["devise.mapping"] = Devise.mappings[:user] }
5
+ describe "logout" do
6
+ let(:user) { FactoryGirl.create(:user) }
7
+ describe "when user is remotely authenticated" do
8
+ before { controller.remote_user_name = user.email }
9
+ it "should redirect to DeviseRemoteUser.logout_url" do
10
+ expect(get :destroy).to redirect_to(DeviseRemoteUser.logout_url)
11
+ end
12
+ end
13
+ describe "when user is not remotely authenticated" do
14
+ it "should redirect to the root path (Devise default)" do
15
+ expect(get :destroy).to redirect_to(root_path)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
5
5
 
6
6
  before_filter :authenticate_user!
7
7
 
8
+ include DeviseRemoteUser::ControllerBehavior
9
+
8
10
  def index
9
11
  render text: "You have reached your destination!"
10
12
  end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-remote-user
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.2'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: devise
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +62,16 @@ dependencies:
56
62
  name: rspec-rails
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - '>='
65
+ - - ~>
60
66
  - !ruby/object:Gem::Version
61
- version: '0'
67
+ version: 2.14.1
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - '>='
72
+ - - ~>
67
73
  - !ruby/object:Gem::Version
68
- version: '0'
74
+ version: 2.14.1
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: factory_girl_rails
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -112,12 +118,16 @@ files:
112
118
  - Rakefile
113
119
  - devise_remote_user.gemspec
114
120
  - lib/devise_remote_user.rb
121
+ - lib/devise_remote_user/controller_behavior.rb
115
122
  - lib/devise_remote_user/engine.rb
116
123
  - lib/devise_remote_user/manager.rb
117
124
  - lib/devise_remote_user/model.rb
118
125
  - lib/devise_remote_user/strategy.rb
119
126
  - lib/devise_remote_user/version.rb
120
127
  - spec/controllers/application_controller_spec.rb
128
+ - spec/controllers/application_controller_spec.rb~
129
+ - spec/controllers/devise/sessions_controller_spec.rb
130
+ - spec/controllers/devise/sessions_controller_spec.rb~
121
131
  - spec/dummy/README.rdoc
122
132
  - spec/dummy/Rakefile
123
133
  - spec/dummy/app/assets/images/.keep
@@ -130,6 +140,7 @@ files:
130
140
  - spec/dummy/app/models/.keep
131
141
  - spec/dummy/app/models/concerns/.keep
132
142
  - spec/dummy/app/models/user.rb
143
+ - spec/dummy/app/models/user.rb~
133
144
  - spec/dummy/app/views/layouts/application.html.erb
134
145
  - spec/dummy/bin/bundle
135
146
  - spec/dummy/bin/rails
@@ -153,31 +164,30 @@ files:
153
164
  - spec/dummy/config/locales/devise.en.yml
154
165
  - spec/dummy/config/locales/en.yml
155
166
  - spec/dummy/config/routes.rb
167
+ - spec/dummy/db/development.sqlite3
156
168
  - spec/dummy/db/migrate/20131101150807_devise_create_users.rb
157
169
  - spec/dummy/db/migrate/20131101184256_add_name_fields_to_user.rb
170
+ - spec/dummy/db/migrate/20131101184256_add_name_fields_to_user.rb~
158
171
  - spec/dummy/db/schema.rb
172
+ - spec/dummy/db/test.sqlite3
159
173
  - spec/dummy/lib/assets/.keep
160
174
  - spec/dummy/log/.keep
175
+ - spec/dummy/log/development.log
176
+ - spec/dummy/log/test.log
161
177
  - spec/dummy/public/404.html
162
178
  - spec/dummy/public/422.html
163
179
  - spec/dummy/public/500.html
164
180
  - spec/dummy/public/favicon.ico
165
- - spec/factories/user_factories.rb
166
- - spec/spec_helper.rb
167
- - spec/controllers/application_controller_spec.rb~
168
- - spec/dummy/app/models/user.rb~
169
- - spec/dummy/db/development.sqlite3
170
- - spec/dummy/db/migrate/20131101184256_add_name_fields_to_user.rb~
171
- - spec/dummy/db/test.sqlite3
172
- - spec/dummy/log/development.log
173
- - spec/dummy/log/test.log
181
+ - spec/dummy/spec/features/#logout_spec.rb#
174
182
  - spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705
175
183
  - spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af
176
184
  - spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953
177
185
  - spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994
178
186
  - spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6
179
187
  - spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655
188
+ - spec/factories/user_factories.rb
180
189
  - spec/factories/user_factories.rb~
190
+ - spec/spec_helper.rb
181
191
  homepage: http://github.com/duke-libraries/devise-remote-user
182
192
  licenses:
183
193
  - BSD
@@ -198,13 +208,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
208
  version: '0'
199
209
  requirements: []
200
210
  rubyforge_project:
201
- rubygems_version: 2.0.6
211
+ rubygems_version: 2.2.2
202
212
  signing_key:
203
213
  specification_version: 4
204
214
  summary: A devise extension for remote user authentication.
205
215
  test_files:
206
216
  - spec/controllers/application_controller_spec.rb
207
217
  - spec/controllers/application_controller_spec.rb~
218
+ - spec/controllers/devise/sessions_controller_spec.rb
219
+ - spec/controllers/devise/sessions_controller_spec.rb~
208
220
  - spec/dummy/app/assets/javascripts/application.js
209
221
  - spec/dummy/app/assets/stylesheets/application.css
210
222
  - spec/dummy/app/controllers/application_controller.rb
@@ -248,6 +260,7 @@ test_files:
248
260
  - spec/dummy/public/favicon.ico
249
261
  - spec/dummy/Rakefile
250
262
  - spec/dummy/README.rdoc
263
+ - spec/dummy/spec/features/#logout_spec.rb#
251
264
  - spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705
252
265
  - spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af
253
266
  - spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953