ff-tbl-macros 2.0.1 → 2.0.2

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
  SHA256:
3
- metadata.gz: 85cfc86c605d10943cd0b90f68a3bcbc6665e7d66895862352c899d6b9b9a78d
4
- data.tar.gz: 47b25e98f0cea82e20cce41539796456dac69f54c4b80d1cc8b84e4c82da3524
3
+ metadata.gz: 9ab61cc8e2b7d908e6f9c1cb1dc102ab14c250f77f85a319d07b9870a186c04c
4
+ data.tar.gz: 612b7db20cb5f8e808a86f1c00597b0f056865ea64239dee7c144c98ac5504ff
5
5
  SHA512:
6
- metadata.gz: 248ba8ec756b1198b3fb1e190a86fe4490fa6490beb55a9dddfc4b6765b1ecb717273e4dab262134badcabd8f861b2862e0200270df800eb6f0a00a4667b2050
7
- data.tar.gz: 17e08c9ac95a49da3d73b7889b4e01a4766042b622691a3247a27a3d84cbaf7e66fceb530e95b5e20482e0469d0f56acf1b861164bf29f78745f2f3b01135a52
6
+ metadata.gz: a37dbde0076242c7e11766234dedbc866abd58ac62a0e3a01160df5796ce97e35ade8cb8f357898bcc019c0c565da562377ead9c7a66406043f523c718b12de4
7
+ data.tar.gz: 9bf6cedb38df7e2fbb31bac449b5b8e91216b37b779372542ba1adde055563d60bbd7c81716777382babdadd0162c501a17bf3a9370a7541951eab1ac39f7ab1
@@ -1,8 +1,11 @@
1
1
  # Changelog
2
2
 
3
3
  ## [Unreleased]
4
+
5
+ ## [2.0.2] - 2019-06-20
4
6
  ### Added
5
- - add gem [rubocop-performance](https://github.com/rubocop-hq/rubocop-performance) to satisfy future Rubocop deprecations.
7
+ - Add gem [rubocop-performance](https://github.com/rubocop-hq/rubocop-performance) to satisfy future Rubocop deprecations.
8
+ - Add new Auth Macros, SignOutAllScopes and ExpireSessionData
6
9
 
7
10
  ## [2.0.1] - 2019-05-16
8
11
  ### Fixed
@@ -32,7 +35,7 @@
32
35
  - Add missing documentation
33
36
 
34
37
  ### Changed
35
- - Use rubygems version insted GitHub one
38
+ - Use rubygems version instead GitHub one
36
39
 
37
40
  ### Added
38
41
  - Add Travis setup
data/README.md CHANGED
@@ -65,6 +65,8 @@ There are several types of macros organized in namespaces.
65
65
  - `Macros::Auth::Authenticate`
66
66
  - `Macros::Auth::SignIn`
67
67
  - `Macros::Auth::SignOut`
68
+ - `Macros::Auth::SignOutAllScopes`
69
+ - `Macros::Auth::ExpireSessionData`
68
70
 
69
71
  ### Contract Macros
70
72
 
@@ -5,5 +5,7 @@ module Macros
5
5
  register :authenticate
6
6
  register :sign_in
7
7
  register :sign_out
8
+ register :sign_out_all_scopes
9
+ register :expire_session_data
8
10
  end
9
11
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Macros
4
+ class Auth
5
+ # Expire session data
6
+ # Macro is used in other Devise' related macros because of the bug
7
+ # https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/sign_in_out.rb#L108
8
+ #
9
+ # @example
10
+ # step Macros::Auth::ExpireSessionData()
11
+ #
12
+ class ExpireSessionData < Macros::Base
13
+ # @return [Macros::Auth::ExpireSessionData] step macro instance
14
+ def initialize; end
15
+
16
+ # @param ctx [Trailblazer::Skill] tbl context hash
17
+ def call(ctx, **)
18
+ session = ctx[:warden].session_serializer.session
19
+
20
+ session.empty?
21
+ session.keys.grep(/^devise\./).each { |k| session.delete(k) }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Macros
4
+ class Auth
5
+ # Sign out users of all scopes
6
+ #
7
+ # @example
8
+ # step Macros::Auth::SignOutAllScopes()
9
+ #
10
+ # @example specify scopes to skip sign out from
11
+ # step Macros::Auth::SignOutAllScopes(except: [:admin])
12
+ class SignOutAllScopes < Macros::Base
13
+ # @return [Macros::Auth::SignOutAllScopes] step macro instance
14
+ # @param expect [Array] list of scopes to skip sign out
15
+ def initialize(except: [])
16
+ @except = except.is_a?(Array) ? except : [except]
17
+ end
18
+
19
+ # Performs a step by sign out users
20
+ # @param ctx [Trailblazer::Skill] tbl context hash
21
+ def call(ctx, **)
22
+ warden = ctx[:warden]
23
+
24
+ if @except.empty?
25
+ warden.logout
26
+ else
27
+ (Devise.mappings.keys - @except).each do |scope|
28
+ warden.logout(scope) if warden.authenticated?(scope: scope)
29
+ end
30
+ end
31
+
32
+ Macros::Auth::ExpireSessionData.new.call(ctx)
33
+ warden.clear_strategies_cache!
34
+ warden.lock!
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Macros
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.2'
5
5
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::Auth::ExpireSessionData do
4
+ include Warden::Test::Mock
5
+
6
+ subject(:step) { described_class.new }
7
+ let(:ctx) { { warden: warden } }
8
+ let(:session) { warden.session_serializer.session }
9
+
10
+ before do
11
+ warden.session_serializer.session[:lorem] = :ipsum
12
+ warden.session_serializer.session['devise.lorem'] = :ipsum
13
+ end
14
+
15
+ it 'expects to clear devise related data from session' do
16
+ step.call(ctx)
17
+
18
+ expect(session[:lorem]).to eql :ipsum
19
+ expect(session['devise.lorem']).to be nil
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::Auth::SignOutAllScopes do
4
+ include Warden::Test::Mock
5
+
6
+ subject(:step) { described_class.new(params) }
7
+ let(:params) { {} }
8
+
9
+ let(:user) { mock_model('User') }
10
+ let(:foo_user) { mock_model('FooUser') }
11
+ let(:admin) { mock_model('Admin') }
12
+
13
+ let(:ctx) { { warden: warden } }
14
+
15
+ before do
16
+ devise = class_double('Devise').as_stubbed_const
17
+ allow(devise).to receive_message_chain(:mappings, :keys).and_return([:user, :foo_user, :admin])
18
+
19
+ warden.set_user(foo_user, scope: :foo_user)
20
+ warden.set_user(admin, scope: :admin)
21
+ end
22
+
23
+ it 'expects to sign out all users' do
24
+ step.call(ctx)
25
+
26
+ expect(warden.authenticated?(:user)).to be false
27
+ expect(warden.authenticated?(:foo_user)).to be false
28
+ expect(warden.authenticated?(:admin)).to be false
29
+ end
30
+
31
+ context 'except param passed' do
32
+ let(:params) { { except: :admin } }
33
+
34
+ it 'expects to sign out all users except admin' do
35
+ step.call(ctx)
36
+
37
+ expect(warden.authenticated?(:user)).to be false
38
+ expect(warden.authenticated?(:foo_user)).to be false
39
+ expect(warden.authenticated?(:admin)).to be true
40
+ end
41
+ end
42
+ end
@@ -12,4 +12,12 @@ RSpec.describe Macros::Auth do
12
12
  describe '#SignOut()' do
13
13
  it { expect(described_class::SignOut()).to be_a described_class::SignOut }
14
14
  end
15
+
16
+ describe '#SignOutAllScopes()' do
17
+ it { expect(described_class::SignOutAllScopes()).to be_a described_class::SignOutAllScopes }
18
+ end
19
+
20
+ describe '#ExpireSessionData()' do
21
+ it { expect(described_class::ExpireSessionData()).to be_a described_class::ExpireSessionData }
22
+ end
15
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ff-tbl-macros
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Szwed, Claudio Perez Gamayo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-16 00:00:00.000000000 Z
11
+ date: 2019-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,8 +70,10 @@ files:
70
70
  - lib/ff-tbl-macros.rb
71
71
  - lib/macros/auth.rb
72
72
  - lib/macros/auth/authenticate.rb
73
+ - lib/macros/auth/expire_session_data.rb
73
74
  - lib/macros/auth/sign_in.rb
74
75
  - lib/macros/auth/sign_out.rb
76
+ - lib/macros/auth/sign_out_all_scopes.rb
75
77
  - lib/macros/base.rb
76
78
  - lib/macros/contract.rb
77
79
  - lib/macros/contract/extract_params.rb
@@ -95,7 +97,9 @@ files:
95
97
  - lib/macros/verify_params/date.rb
96
98
  - lib/macros/version.rb
97
99
  - spec/lib/auth/authenticate_spec.rb
100
+ - spec/lib/auth/expire_session_data_spec.rb
98
101
  - spec/lib/auth/sign_in_spec.rb
102
+ - spec/lib/auth/sign_out_all_scopes_spec.rb
99
103
  - spec/lib/auth/sign_out_spec.rb
100
104
  - spec/lib/auth_spec.rb
101
105
  - spec/lib/contract/extract_params_spec.rb
@@ -145,7 +149,9 @@ specification_version: 4
145
149
  summary: Trailblazer shared macros
146
150
  test_files:
147
151
  - spec/lib/auth/authenticate_spec.rb
152
+ - spec/lib/auth/expire_session_data_spec.rb
148
153
  - spec/lib/auth/sign_in_spec.rb
154
+ - spec/lib/auth/sign_out_all_scopes_spec.rb
149
155
  - spec/lib/auth/sign_out_spec.rb
150
156
  - spec/lib/auth_spec.rb
151
157
  - spec/lib/contract/extract_params_spec.rb