fridge 0.4.0 → 0.4.1

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
- SHA1:
3
- metadata.gz: f3fd8b4cdad9a0058286a10db5947702a8c62251
4
- data.tar.gz: 2dca120560756b29fb9f91ed233f0fbcb972fc9d
2
+ SHA256:
3
+ metadata.gz: 73170339e572589b38ca8c30c1bab638b80102caf10ea71572ebdb5168e28397
4
+ data.tar.gz: 89ed3cdee4f57bee03d128a155ea3ec8d9b29dfb3343d05b67fe343ac6fc12e7
5
5
  SHA512:
6
- metadata.gz: 78aecaa8eaed3d901472b445b056901b234b188b65c91b59d3a0b910398d4234bf73dce6108f92e8e85bcacdda43764200b509d23bdfef06a8bf25d3a4ca976e
7
- data.tar.gz: 7497a09cac625ab1f0184024de2cfd698f3e720c09dcfbac0725eb8ed28211142c0c72996f314c35b8041a4a4b7b5161ff344d36ed952025f1f8335da8f94905
6
+ metadata.gz: d1b78d332804fe1680c5df49b25fa83e47603281d950705f9c8775e37ad3821971f53670191bb493fc970d9d7d7cf08bbd6a54fd26f9c82402d1a545b49bc964
7
+ data.tar.gz: 9d98dead583203b74b41326d7b3b325fb7507ac3a1b2a9fbfbf5bb1120247327a4366f74544efa4f57061f8e340ba918cdd4719c61a5e98a0b992c7a144b8686
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'aptible-tasks'
27
27
  spec.add_development_dependency 'rake'
28
28
  spec.add_development_dependency 'rails'
29
- spec.add_development_dependency 'rspec', '~> 2.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
30
  spec.add_development_dependency 'rspec-rails'
31
31
  spec.add_development_dependency 'pry'
32
32
  end
@@ -124,6 +124,8 @@ module Fridge
124
124
  # mapping from Fridge to JWT and vice-versa.
125
125
 
126
126
  def encode_for_jwt(hash)
127
+ hash = hash.dup
128
+
127
129
  out = {
128
130
  id: hash.delete(:id),
129
131
  iss: hash.delete(:issuer),
@@ -145,6 +147,8 @@ module Fridge
145
147
  end
146
148
 
147
149
  def decode_from_jwt(hash)
150
+ hash = hash.dup
151
+
148
152
  out = {
149
153
  id: hash.delete('id'),
150
154
  issuer: hash.delete('iss'),
@@ -1,3 +1,3 @@
1
1
  module Fridge
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -1,7 +1,3 @@
1
- require 'active_support/all'
2
- require 'action_controller'
3
- require 'action_dispatch'
4
-
5
1
  module Rails
6
2
  class App
7
3
  def env_config
@@ -139,6 +139,17 @@ describe Fridge::AccessToken do
139
139
  new = described_class.new(subject.serialize)
140
140
  expect(new.actor).to eq(actor)
141
141
  end
142
+
143
+ it 'should be idempotent' do
144
+ subject = described_class.new(options)
145
+ expect(subject.serialize).to eq(subject.serialize)
146
+ end
147
+
148
+ it 'should be idempotent with an actor' do
149
+ actor = { subject: 'foo', username: 'test', actor: { subject: 'bar' } }
150
+ subject = described_class.new(options.merge(actor: actor))
151
+ expect(subject.serialize).to eq(subject.serialize)
152
+ end
142
153
  end
143
154
 
144
155
  describe '#expired?' do
@@ -1,218 +1,217 @@
1
1
  require 'spec_helper'
2
2
  require 'fixtures/app'
3
- require 'fixtures/controller'
4
- require 'rspec/rails'
5
3
 
6
- # http://say26.com/rspec-testing-controllers-outside-of-a-rails-application
7
- describe Controller, type: :controller do
8
- context Fridge::RailsHelpers do
9
- let(:organization_url) do
10
- "https://auth.aptible.com/users/#{SecureRandom.uuid}"
11
- end
12
- let(:private_key) { OpenSSL::PKey::RSA.new(1024) }
13
- let(:public_key) { OpenSSL::PKey::RSA.new(private_key.public_key) }
4
+ describe Fridge::RailsHelpers do
5
+ include RSpec::Rails::ControllerExampleGroup
14
6
 
15
- let(:options) do
16
- {
17
- subject: "https://auth.aptible.com/users/#{SecureRandom.uuid}",
18
- expires_at: Time.now + 3600
19
- }
20
- end
21
- let(:access_token) { Fridge::AccessToken.new(options) }
7
+ controller(ActionController::Base) { include Fridge::RailsHelpers }
22
8
 
23
- let(:cookies) { controller.send(:cookies) }
9
+ let(:organization_url) do
10
+ "https://auth.aptible.com/users/#{SecureRandom.uuid}"
11
+ end
12
+ let(:private_key) { OpenSSL::PKey::RSA.new(1024) }
13
+ let(:public_key) { OpenSSL::PKey::RSA.new(private_key.public_key) }
14
+
15
+ let(:options) do
16
+ {
17
+ subject: "https://auth.aptible.com/users/#{SecureRandom.uuid}",
18
+ expires_at: Time.now + 3600
19
+ }
20
+ end
21
+ let(:access_token) { Fridge::AccessToken.new(options) }
24
22
 
25
- before { Fridge.configuration.private_key = private_key.to_s }
26
- before { Fridge.configuration.public_key = public_key.to_s }
23
+ let(:cookies) { controller.send(:cookies) }
27
24
 
28
- describe '#bearer_token' do
29
- it 'returns the bearer token from the Authorization: header' do
30
- request.env['HTTP_AUTHORIZATION'] = 'Bearer foobar'
31
- expect(controller.bearer_token).to eq 'foobar'
32
- end
25
+ before { Fridge.configuration.private_key = private_key.to_s }
26
+ before { Fridge.configuration.public_key = public_key.to_s }
33
27
 
34
- it 'returns nil in the absence of an Authorization: header' do
35
- request.env['HTTP_AUTHORIZATION'] = nil
36
- expect(controller.bearer_token).to be_nil
37
- end
28
+ describe '#bearer_token' do
29
+ it 'returns the bearer token from the Authorization: header' do
30
+ request.env['HTTP_AUTHORIZATION'] = 'Bearer foobar'
31
+ expect(controller.bearer_token).to eq 'foobar'
38
32
  end
39
33
 
40
- describe '#token_subject' do
41
- it 'returns the subject encoded in the token' do
42
- controller.stub(:current_token) { access_token }
43
- expect(controller.token_subject).to eq access_token.subject
44
- end
34
+ it 'returns nil in the absence of an Authorization: header' do
35
+ request.env['HTTP_AUTHORIZATION'] = nil
36
+ expect(controller.bearer_token).to be_nil
37
+ end
38
+ end
45
39
 
46
- it 'returns nil if no token is present' do
47
- controller.stub(:current_token) { nil }
48
- expect(controller.token_subject).to be_nil
49
- end
40
+ describe '#token_subject' do
41
+ it 'returns the subject encoded in the token' do
42
+ controller.stub(:current_token) { access_token }
43
+ expect(controller.token_subject).to eq access_token.subject
50
44
  end
51
45
 
52
- describe '#token_scope' do
53
- it 'returns the scope encoded in the token' do
54
- controller.stub(:current_token) { access_token }
55
- expect(controller.token_scope).to eq access_token.scope
56
- end
46
+ it 'returns nil if no token is present' do
47
+ controller.stub(:current_token) { nil }
48
+ expect(controller.token_subject).to be_nil
49
+ end
50
+ end
57
51
 
58
- it 'returns nil if no token is present' do
59
- controller.stub(:current_token) { nil }
60
- expect(controller.token_scope).to be_nil
61
- end
52
+ describe '#token_scope' do
53
+ it 'returns the scope encoded in the token' do
54
+ controller.stub(:current_token) { access_token }
55
+ expect(controller.token_scope).to eq access_token.scope
62
56
  end
63
57
 
64
- describe '#current_token' do
65
- before { controller.stub(:bearer_token) { access_token.serialize } }
58
+ it 'returns nil if no token is present' do
59
+ controller.stub(:current_token) { nil }
60
+ expect(controller.token_scope).to be_nil
61
+ end
62
+ end
66
63
 
67
- it 'should raise an error if the token is not a valid JWT' do
68
- controller.stub(:bearer_token) { 'foobar' }
69
- expect { controller.current_token }.to raise_error Fridge::InvalidToken
70
- end
64
+ describe '#current_token' do
65
+ before { controller.stub(:bearer_token) { access_token.serialize } }
71
66
 
72
- it 'should raise an error if the token has expired' do
73
- access_token.expires_at = Time.now - 3600
74
- expect { controller.current_token }.to raise_error Fridge::InvalidToken
75
- end
67
+ it 'should raise an error if the token is not a valid JWT' do
68
+ controller.stub(:bearer_token) { 'foobar' }
69
+ expect { controller.current_token }.to raise_error Fridge::InvalidToken
70
+ end
76
71
 
77
- it 'should raise an error if custom validation fails' do
78
- Fridge.configuration.validator = ->(_) { false }
79
- expect { controller.current_token }.to raise_error Fridge::InvalidToken
80
- end
72
+ it 'should raise an error if the token has expired' do
73
+ access_token.expires_at = Time.now - 3600
74
+ expect { controller.current_token }.to raise_error Fridge::InvalidToken
75
+ end
81
76
 
82
- it 'should not raise an error if a valid token is passed' do
83
- expect { controller.current_token }.not_to raise_error
84
- end
77
+ it 'should raise an error if custom validation fails' do
78
+ Fridge.configuration.validator = ->(_) { false }
79
+ expect { controller.current_token }.to raise_error Fridge::InvalidToken
80
+ end
85
81
 
86
- it 'should return the token if a valid token is passed' do
87
- expect(controller.current_token.id).to eq access_token.id
88
- end
82
+ it 'should not raise an error if a valid token is passed' do
83
+ expect { controller.current_token }.not_to raise_error
89
84
  end
90
85
 
91
- describe '#session_subject' do
92
- it 'returns the subject encoded in the session' do
93
- controller.stub(:session_token) { access_token }
94
- expect(controller.session_subject).to eq access_token.subject
95
- end
86
+ it 'should return the token if a valid token is passed' do
87
+ expect(controller.current_token.id).to eq access_token.id
88
+ end
89
+ end
96
90
 
97
- it 'returns nil if no session is present' do
98
- controller.stub(:session_token) { nil }
99
- expect(controller.session_subject).to be_nil
100
- end
91
+ describe '#session_subject' do
92
+ it 'returns the subject encoded in the session' do
93
+ controller.stub(:session_token) { access_token }
94
+ expect(controller.session_subject).to eq access_token.subject
101
95
  end
102
96
 
103
- describe '#session_token' do
104
- it 'should delete all cookies on error' do
105
- cookies[:fridge_session] = 'foobar'
106
- controller.session_token
107
- expect(cookies.deleted?(:fridge_session, domain: :all)).to be true
108
- end
97
+ it 'returns nil if no session is present' do
98
+ controller.stub(:session_token) { nil }
99
+ expect(controller.session_subject).to be_nil
100
+ end
101
+ end
109
102
 
110
- it 'should return nil on error' do
111
- cookies[:fridge_session] = 'foobar'
112
- expect(controller.session_token).to be_nil
113
- end
103
+ describe '#session_token' do
104
+ it 'should delete all cookies on error' do
105
+ cookies[:fridge_session] = 'foobar'
106
+ controller.session_token
107
+ expect(cookies.deleted?(:fridge_session, domain: :all)).to be true
108
+ end
114
109
 
115
- it 'should return the token stored in :fridge_session' do
116
- cookies[:fridge_session] = access_token.serialize
117
- expect(controller.session_token.id).to eq access_token.id
118
- end
110
+ it 'should return nil on error' do
111
+ cookies[:fridge_session] = 'foobar'
112
+ expect(controller.session_token).to be_nil
113
+ end
119
114
 
120
- context 'with a non-:read scope' do
121
- before { options.merge!(scope: 'manage') }
115
+ it 'should return the token stored in :fridge_session' do
116
+ cookies[:fridge_session] = access_token.serialize
117
+ expect(controller.session_token.id).to eq access_token.id
118
+ end
122
119
 
123
- it 'should downgrade the token' do
124
- cookies[:fridge_session] = access_token.serialize
125
- expect(controller.session_token.scope).to eq 'read'
126
- end
120
+ context 'with a non-:read scope' do
121
+ before { options.merge!(scope: 'manage') }
127
122
 
128
- it 'should not change the validity of a token' do
129
- cookies[:fridge_session] = access_token.serialize
130
- expect(controller.session_token).to be_valid
131
- end
123
+ it 'should downgrade the token' do
124
+ cookies[:fridge_session] = access_token.serialize
125
+ expect(controller.session_token.scope).to eq 'read'
132
126
  end
133
- end
134
127
 
135
- describe '#validate_token' do
136
- it 'should return false if the token is invalid' do
137
- Fridge.configuration.validator = ->(_) { false }
138
- expect(controller.validate_token(access_token)).to be false
128
+ it 'should not change the validity of a token' do
129
+ cookies[:fridge_session] = access_token.serialize
130
+ expect(controller.session_token).to be_valid
139
131
  end
132
+ end
133
+ end
140
134
 
141
- it 'should return false if the token validator fails' do
142
- Fridge.configuration.validator = ->(_) { raise 'Foobar' }
143
- expect(controller.validate_token(access_token)).to be false
144
- end
135
+ describe '#validate_token' do
136
+ it 'should return false if the token is invalid' do
137
+ Fridge.configuration.validator = ->(_) { false }
138
+ expect(controller.validate_token(access_token)).to be false
139
+ end
145
140
 
146
- it 'should return the token if valid' do
147
- Fridge.configuration.validator = ->(_) { true }
148
- expect(controller.validate_token(access_token)).to eq access_token
149
- end
141
+ it 'should return false if the token validator fails' do
142
+ Fridge.configuration.validator = ->(_) { raise 'Foobar' }
143
+ expect(controller.validate_token(access_token)).to be false
150
144
  end
151
145
 
152
- describe '#validate_token' do
153
- it 'should raise an exception if the token is invalid' do
154
- Fridge.configuration.validator = ->(_) { false }
155
- expect { controller.validate_token!(access_token) }.to raise_error
156
- end
146
+ it 'should return the token if valid' do
147
+ Fridge.configuration.validator = ->(_) { true }
148
+ expect(controller.validate_token(access_token)).to eq access_token
149
+ end
150
+ end
157
151
 
158
- it 'should return the token if valid' do
159
- Fridge.configuration.validator = ->(_) { true }
160
- expect(controller.validate_token!(access_token)).to eq access_token
161
- end
152
+ describe '#validate_token' do
153
+ it 'should raise an exception if the token is invalid' do
154
+ Fridge.configuration.validator = ->(_) { false }
155
+ expect { controller.validate_token!(access_token) }.to raise_error
162
156
  end
163
157
 
164
- describe '#sessionize_token' do
165
- it 'should set a session cookie' do
166
- Rails.stub_chain(:env, :development?) { false }
167
- controller.sessionize_token(access_token)
168
- expect(cookies[:fridge_session]).to eq access_token.serialize
169
- end
158
+ it 'should return the token if valid' do
159
+ Fridge.configuration.validator = ->(_) { true }
160
+ expect(controller.validate_token!(access_token)).to eq access_token
170
161
  end
162
+ end
171
163
 
172
- describe '#fridge_cookie_name' do
173
- it 'is configurable' do
174
- Fridge.configuration.cookie_name = 'foobar'
175
- expect(controller.fridge_cookie_name).to eq 'foobar'
176
- end
164
+ describe '#sessionize_token' do
165
+ it 'should set a session cookie' do
166
+ Rails.stub_chain(:env, :development?) { false }
167
+ controller.sessionize_token(access_token)
168
+ expect(cookies[:fridge_session]).to eq access_token.serialize
177
169
  end
170
+ end
178
171
 
179
- describe '#write_shared_cookie' do
180
- before { Rails.stub_chain(:env, :development?) { false } }
172
+ describe '#fridge_cookie_name' do
173
+ it 'is configurable' do
174
+ Fridge.configuration.cookie_name = 'foobar'
175
+ expect(controller.fridge_cookie_name).to eq 'foobar'
176
+ end
177
+ end
181
178
 
182
- it 'should save cookie' do
183
- controller.write_shared_cookie(:organization_url, organization_url)
184
- expect(cookies[:organization_url]).to eq organization_url
185
- end
179
+ describe '#write_shared_cookie' do
180
+ before { Rails.stub_chain(:env, :development?) { false } }
181
+
182
+ it 'should save cookie' do
183
+ controller.write_shared_cookie(:organization_url, organization_url)
184
+ expect(cookies[:organization_url]).to eq organization_url
186
185
  end
186
+ end
187
187
 
188
- describe '#read_shared_cookie' do
189
- it 'should read cookie' do
190
- cookies[:organization_url] = { value: organization_url }
191
- expect(controller.read_shared_cookie(:organization_url)).to(
192
- eq organization_url
193
- )
194
- end
188
+ describe '#read_shared_cookie' do
189
+ it 'should read cookie' do
190
+ cookies[:organization_url] = { value: organization_url }
191
+ expect(controller.read_shared_cookie(:organization_url)).to(
192
+ eq organization_url
193
+ )
195
194
  end
195
+ end
196
196
 
197
- describe '#delete_shared_cookie' do
198
- before { Rails.stub_chain(:env, :development?) { false } }
197
+ describe '#delete_shared_cookie' do
198
+ before { Rails.stub_chain(:env, :development?) { false } }
199
199
 
200
- it 'should delete cookie' do
201
- controller.write_shared_cookie(:organization_url, organization_url)
202
- controller.delete_shared_cookie(:organization_url)
203
- expect(cookies[:organization_url]).to be_nil
204
- end
200
+ it 'should delete cookie' do
201
+ controller.write_shared_cookie(:organization_url, organization_url)
202
+ controller.delete_shared_cookie(:organization_url)
203
+ expect(cookies[:organization_url]).to be_nil
205
204
  end
205
+ end
206
206
 
207
- describe '#fridge_cookie_options' do
208
- before { Rails.stub_chain(:env, :development?) { false } }
207
+ describe '#fridge_cookie_options' do
208
+ before { Rails.stub_chain(:env, :development?) { false } }
209
209
 
210
- it 'are configurable' do
211
- Fridge.configuration.cookie_options = { foobar: true }
212
- options = controller.fridge_cookie_options
213
- expect(options[:domain]).to eq :all
214
- expect(options[:foobar]).to eq true
215
- end
210
+ it 'are configurable' do
211
+ Fridge.configuration.cookie_options = { foobar: true }
212
+ options = controller.fridge_cookie_options
213
+ expect(options[:domain]).to eq :all
214
+ expect(options[:foobar]).to eq true
216
215
  end
217
216
  end
218
217
  end
@@ -1,14 +1,22 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
 
4
+ require 'active_support/all'
5
+ require 'action_controller'
6
+ require 'action_dispatch'
7
+ require 'action_view'
8
+
9
+ require 'fridge'
10
+ require 'fridge/rails_helpers'
11
+
12
+ require 'rspec'
13
+ require 'rspec/rails'
14
+
4
15
  # Load shared spec files
5
16
  Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
6
17
  require file
7
18
  end
8
19
 
9
- # Require library up front
10
- require 'fridge'
11
-
12
20
  RSpec.configure do |config|
13
21
  config.before { Fridge.configuration.reset }
14
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '2.0'
103
+ version: '3.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '2.0'
110
+ version: '3.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec-rails
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -160,7 +160,6 @@ files:
160
160
  - lib/fridge/serialization_error.rb
161
161
  - lib/fridge/version.rb
162
162
  - spec/fixtures/app.rb
163
- - spec/fixtures/controller.rb
164
163
  - spec/fridge/access_token_spec.rb
165
164
  - spec/fridge/rails_helpers_spec.rb
166
165
  - spec/spec_helper.rb
@@ -184,13 +183,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
183
  version: '0'
185
184
  requirements: []
186
185
  rubyforge_project:
187
- rubygems_version: 2.4.5.1
186
+ rubygems_version: 2.7.6
188
187
  signing_key:
189
188
  specification_version: 4
190
189
  summary: Token validation for distributed resource servers
191
190
  test_files:
192
191
  - spec/fixtures/app.rb
193
- - spec/fixtures/controller.rb
194
192
  - spec/fridge/access_token_spec.rb
195
193
  - spec/fridge/rails_helpers_spec.rb
196
194
  - spec/spec_helper.rb
@@ -1,5 +0,0 @@
1
- require 'fridge/rails_helpers'
2
-
3
- class Controller < ActionController::Base
4
- include Fridge::RailsHelpers
5
- end