doorkeeper_sso 0.2.7 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe5ab16d2f2e2a47ac7661e14aaf1e3fb65e3623
4
- data.tar.gz: 2c16456bf1eeb023a47c79b96bdae2a6e421f515
3
+ metadata.gz: 1b37cfaca0f0f4f0087f9bd86254651caf44e15a
4
+ data.tar.gz: 8fa3028938be6f401d24481df77f61f8e72d4fbd
5
5
  SHA512:
6
- metadata.gz: 141aae2e35e3f82733a6f3d58e949d63ea1c04bc640a1fb3185edc25af8da4179ea3c18e4fdbcc25c097e21ffe5ed0a23fb66a5dad0e02ebc5ff6d14523d5c08
7
- data.tar.gz: 3514b67ddedd75de55802a4b7b5275b177734893dfe19aed9454e8558b373c9b8a9df2a0f7778f63ec31cc39a53a4c3a3a04f74d358673bae7cba749daad8bf6
6
+ metadata.gz: 81c4872126d84a3cfd6629b4f805c7b0c71093ae118c667051874d30744118e9a36cbf5ba12f82f493b1ec331827a85911799210a999d0459274cf54c4a3bca6
7
+ data.tar.gz: 1a44dec7b5b5b93820b44e255fcd0b63095f2508e0223b206f9d89b790ee9d50642ab2dfd8bd9b37ff07c8a890ff0a263972ea32babe3dc1713e31060658b992
data/lib/sso/engine.rb CHANGED
@@ -32,7 +32,7 @@ module Sso
32
32
  ::Doorkeeper::TokensController.send(:include, Sso::Doorkeeper::TokensControllerMixin)
33
33
  ::Doorkeeper::AuthorizationsController.send(:include, Sso::Doorkeeper::AuthorizationsControllerMixin)
34
34
 
35
- ::Warden::Manager.after_authentication(scope: :user, &::Sso::Warden::Hooks::AfterAuthentication.to_proc)
35
+ ::Warden::Manager.after_set_user(scope: :user, &::Sso::Warden::Hooks::CreateMasterSession.to_proc)
36
36
  ::Warden::Manager.before_logout(scope: :user, &::Sso::Warden::Hooks::BeforeLogout.to_proc)
37
37
 
38
38
  # TODO : Do we want to ensure that session is always active?
data/lib/sso/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sso
2
- VERSION = "0.2.7"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,12 +1,16 @@
1
1
  module Sso
2
2
  module Warden
3
3
  module Hooks
4
- class AfterAuthentication
4
+ class CreateMasterSession
5
5
  include ::Sso::Warden::Support
6
6
 
7
7
  def call
8
- debug { "Starting hook because this is considered the first login of the current session..." }
9
- generate_session
8
+ if logged_in?
9
+ debug { "Starting hook because this is considered the first login of the current session..." }
10
+ debug { "Log out previous Sso:Session if exists : ID session['sso_session_id']" }
11
+ ::Sso::Session.logout(session["sso_session_id"])
12
+ generate_session
13
+ end
10
14
  return nil
11
15
  end
12
16
 
data/lib/sso.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "sso/engine"
2
2
  require "sso/logging"
3
3
  require "sso/warden/support"
4
- require "sso/warden/hooks/after_authentication"
4
+ require "sso/warden/hooks/create_master_session"
5
5
  require "sso/warden/hooks/before_logout"
6
6
  require "sso/warden/hooks/session_check"
7
7
  require "sso/doorkeeper/access_grant_mixin"
@@ -1,24 +1,9 @@
1
1
  require 'rails_helper'
2
2
 
3
- RSpec.describe Sso::Warden::Hooks::AfterAuthentication do
3
+ RSpec.describe Sso::Warden::Hooks::CreateMasterSession do
4
4
 
5
5
  # Set up user
6
6
  let(:user) { Fabricate(:user) }
7
- # let(:application) { Fabricate('Doorkeeper::Application') }
8
- # let(:access_token) { Fabricate('Doorkeeper::AccessToken',
9
- # resource_owner_id: user.id) }
10
- # let!(:access_grant) { Fabricate('Doorkeeper::AccessGrant',
11
- # application_id: application.id,
12
- # resource_owner_id: user.id,
13
- # redirect_uri: 'http://localhost:3002/oauth/callback'
14
- # ) }
15
-
16
- # # Set up Session
17
- # let(:session) { Fabricate('Sso::Session', owner: user) }
18
- # let!(:client) { Fabricate('Sso::Client', session: session,
19
- # application_id: application.id,
20
- # access_token_id: access_token.id,
21
- # access_grant_id: access_grant.id) }
22
7
 
23
8
  # Set up rack
24
9
  let(:proc) { described_class.to_proc }
@@ -45,7 +30,44 @@ RSpec.describe Sso::Warden::Hooks::AfterAuthentication do
45
30
  expect(rack.call).to be_nil
46
31
  end
47
32
 
48
- it "run #generate_session" do
33
+ context 'existing session' do
34
+ let(:sso_params) { { :ip => "202.188.0.133", :agent => "Chrome" } }
35
+ let(:sso_session) { ::Sso::Session.generate_master(user, sso_params ) }
36
+ let!(:session_params) { { "sso_session_id" => sso_session.id } }
37
+
38
+ before() { rack.call }
39
+
40
+ it { expect(::Sso::Session.count).to eq 2 }
41
+ it { expect(::Sso::Session.find_by_id(sso_session.id).revoke_reason).to eq "logout" }
42
+
43
+ it "runs Sso::Session.logout" do
44
+ expect(::Sso::Session).to receive(:logout).with(nil)
45
+ rack.call
46
+ end
47
+ end
48
+
49
+ context 'logged out' do
50
+ let(:user) { nil }
51
+
52
+ before() { rack.call }
53
+
54
+ it "will not run Sso::Session.logout" do
55
+ expect(::Sso::Session).not_to receive(:logout)
56
+ rack.call
57
+ end
58
+
59
+ it "will not run #generate_session" do
60
+ expect(rack).not_to receive(:generate_session)
61
+ rack.call
62
+ end
63
+ end
64
+
65
+ it "runs Sso::Session.logout" do
66
+ expect(::Sso::Session).to receive(:logout).with(nil)
67
+ rack.call
68
+ end
69
+
70
+ it "runs #generate_session" do
49
71
  expect(rack).to receive(:generate_session)
50
72
  rack.call
51
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper_sso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: warden
@@ -344,8 +344,8 @@ files:
344
344
  - lib/sso/engine.rb
345
345
  - lib/sso/logging.rb
346
346
  - lib/sso/version.rb
347
- - lib/sso/warden/hooks/after_authentication.rb
348
347
  - lib/sso/warden/hooks/before_logout.rb
348
+ - lib/sso/warden/hooks/create_master_session.rb
349
349
  - lib/sso/warden/hooks/session_check.rb
350
350
  - lib/sso/warden/support.rb
351
351
  - lib/tasks/sso_tasks.rake
@@ -363,8 +363,8 @@ files:
363
363
  - spec/lib/doorkeeper/application_mixin_spec.rb
364
364
  - spec/lib/doorkeeper/authorizations_controller_mixin_spec.rb
365
365
  - spec/lib/doorkeeper/tokens_controller_mixin_spec.rb
366
- - spec/lib/sso/warden/hooks/after_authentication_spec.rb
367
366
  - spec/lib/sso/warden/hooks/before_logout_spec.rb
367
+ - spec/lib/sso/warden/hooks/create_master_session_spec.rb
368
368
  - spec/models/sso/client_spec.rb
369
369
  - spec/models/sso/pingback_spec.rb
370
370
  - spec/models/sso/session_spec.rb
@@ -423,8 +423,8 @@ test_files:
423
423
  - spec/lib/doorkeeper/application_mixin_spec.rb
424
424
  - spec/lib/doorkeeper/authorizations_controller_mixin_spec.rb
425
425
  - spec/lib/doorkeeper/tokens_controller_mixin_spec.rb
426
- - spec/lib/sso/warden/hooks/after_authentication_spec.rb
427
426
  - spec/lib/sso/warden/hooks/before_logout_spec.rb
427
+ - spec/lib/sso/warden/hooks/create_master_session_spec.rb
428
428
  - spec/models/sso/client_spec.rb
429
429
  - spec/models/sso/pingback_spec.rb
430
430
  - spec/models/sso/session_spec.rb