fridge 0.2.2 → 0.2.3

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: 7275014e65a32b3064b12515b594310ed2c6a962
4
- data.tar.gz: 22215a24080e1058259fb74e3f5bfe6d172fa569
3
+ metadata.gz: 291594eb2a2800f68ef6c4184f5b97ef14edd242
4
+ data.tar.gz: 8f0c835ff0b772d81730c95e7b6c6c9bf21eb365
5
5
  SHA512:
6
- metadata.gz: 553d392ec6ec4921c0c4490031db29ef35a5d30aebca1de718b6d0564543ace7af8265739a3fa1c85d16b22ed8108f2e1d242bc391395df3d551be81c12fdb03
7
- data.tar.gz: d35ff3e6965b56dba57ab5ed6349512837ed89d93953f673d07713dbe65f68b6b870975cfb29369879f1ac4b065fa13dcdc71a9a2a4fc86412a2dd0b04613a7c
6
+ metadata.gz: 9314a498972e9c96182072df02c09a66d23e57bd9edcebb8ee3bc9f30fc1d5dba6f888935ae5772a7a860e354851263e405b82808e72aaf4213c1f8703d56a40
7
+ data.tar.gz: a69f2d3255c868d2582e6b41d7a7b9a3c7ab38c987934f65234c9799222cd412e09cf5be9106e601aff2e822fe84f99c5e9a8a6462765419848d8e112e3ec2a2
data/fridge.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.version = Fridge::VERSION
11
11
  spec.authors = ['Frank Macreery']
12
12
  spec.email = ['frank@macreery.com']
13
- spec.description = %q{Token validation for distributed resource servers}
14
- spec.summary = %q{Token validation for distributed resource servers}
13
+ spec.description = 'Token validation for distributed resource servers'
14
+ spec.summary = 'Token validation for distributed resource servers'
15
15
  spec.homepage = 'https://github.com/aptible/fridge'
16
16
  spec.license = 'MIT'
17
17
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.add_dependency 'gem_config'
23
- spec.add_dependency 'jwt'
23
+ spec.add_dependency 'jwt', '~> 0.1.13'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.5'
26
26
  spec.add_development_dependency 'aptible-tasks'
@@ -18,7 +18,7 @@ module Fridge
18
18
  [:id, :issuer, :subject, :scope, :expires_at].each do |key|
19
19
  send "#{key}=", options.delete(key)
20
20
  end
21
- self.attributes = options.reject { |k, v| v.nil? }
21
+ self.attributes = options.reject { |_, v| v.nil? }
22
22
  self.attributes = Hash[attributes.map { |k, v| [k.to_sym, v] }]
23
23
  end
24
24
  # rubocop:enable MethodLength
@@ -107,9 +107,8 @@ module Fridge
107
107
 
108
108
  def validate_parameters!
109
109
  [:subject, :expires_at].each do |attribute|
110
- unless send(attribute)
111
- fail SerializationError, "Missing attribute: #{attribute}"
112
- end
110
+ next if send(attribute)
111
+ fail SerializationError, "Missing attribute: #{attribute}"
113
112
  end
114
113
  end
115
114
 
@@ -1,5 +1,12 @@
1
1
  module Fridge
2
2
  module RailsHelpers
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ helper_method :write_shared_cookie, :fetch_shared_cookie,
7
+ :read_shared_cookie
8
+ end
9
+
3
10
  def token_scope
4
11
  current_token.scope if current_token
5
12
  end
@@ -75,6 +82,24 @@ module Fridge
75
82
  nil
76
83
  end
77
84
 
85
+ def write_shared_cookie(name, value)
86
+ fail 'Can only write string cookie values' unless value.is_a?(String)
87
+
88
+ cookies[name] = {
89
+ value: value,
90
+ expires: 1.year.from_now
91
+ }.merge(fridge_cookie_options)
92
+ end
93
+
94
+ def read_shared_cookie(name)
95
+ cookies[name]
96
+ end
97
+
98
+ def fetch_shared_cookie(name, &block)
99
+ return read_shared_cookie(name) if read_shared_cookie(name)
100
+ write_shared_cookie(block.call)
101
+ end
102
+
78
103
  def fridge_cookie_name
79
104
  Fridge.configuration.cookie_name
80
105
  end
@@ -1,3 +1,3 @@
1
1
  module Fridge
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -47,13 +47,14 @@ describe Fridge::AccessToken do
47
47
  subject { described_class.new(options) }
48
48
 
49
49
  it 'should return a JWT comprised of token attributes' do
50
- expect(subject.serialize).to eq JWT.encode({
50
+ hash = {
51
51
  id: subject.id,
52
52
  iss: subject.issuer,
53
53
  sub: subject.subject,
54
54
  scope: subject.scope,
55
55
  exp: subject.expires_at.to_i
56
- }, private_key, 'RS512')
56
+ }
57
+ expect(subject.serialize).to eq JWT.encode(hash, private_key, 'RS512')
57
58
  end
58
59
 
59
60
  it 'should be verifiable with the application public key' do
@@ -72,7 +72,7 @@ describe Controller, type: :controller do
72
72
  end
73
73
 
74
74
  it 'should raise an error if custom validation fails' do
75
- Fridge.configuration.validator = ->(token) { false }
75
+ Fridge.configuration.validator = ->(_) { false }
76
76
  expect { controller.current_token }.to raise_error Fridge::InvalidToken
77
77
  end
78
78
 
@@ -117,29 +117,29 @@ describe Controller, type: :controller do
117
117
 
118
118
  describe '#validate_token' do
119
119
  it 'should return false if the token is invalid' do
120
- Fridge.configuration.validator = ->(token) { false }
120
+ Fridge.configuration.validator = ->(_) { false }
121
121
  expect(controller.validate_token(access_token)).to be_false
122
122
  end
123
123
 
124
124
  it 'should return false if the token validator fails' do
125
- Fridge.configuration.validator = ->(token) { fail 'Foobar' }
125
+ Fridge.configuration.validator = ->(_) { fail 'Foobar' }
126
126
  expect(controller.validate_token(access_token)).to be_false
127
127
  end
128
128
 
129
129
  it 'should return the token if valid' do
130
- Fridge.configuration.validator = ->(token) { true }
130
+ Fridge.configuration.validator = ->(_) { true }
131
131
  expect(controller.validate_token(access_token)).to eq access_token
132
132
  end
133
133
  end
134
134
 
135
135
  describe '#validate_token' do
136
136
  it 'should raise an exception if the token is invalid' do
137
- Fridge.configuration.validator = ->(token) { false }
137
+ Fridge.configuration.validator = ->(_) { false }
138
138
  expect { controller.validate_token!(access_token) }.to raise_error
139
139
  end
140
140
 
141
141
  it 'should return the token if valid' do
142
- Fridge.configuration.validator = ->(token) { true }
142
+ Fridge.configuration.validator = ->(_) { true }
143
143
  expect(controller.validate_token!(access_token)).to eq access_token
144
144
  end
145
145
  end
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-02 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jwt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.1.13
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.1.13
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: aptible-tasks
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '2.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
110
  version: '2.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec-rails
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pry
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: Token validation for distributed resource servers
@@ -143,9 +143,9 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - .gitignore
147
- - .rspec
148
- - .travis.yml
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
149
  - Gemfile
150
150
  - LICENSE.md
151
151
  - README.md
@@ -173,17 +173,17 @@ require_paths:
173
173
  - lib
174
174
  required_ruby_version: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - '>='
176
+ - - ">="
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  requirements:
181
- - - '>='
181
+ - - ">="
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.2.1
186
+ rubygems_version: 2.2.2
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: Token validation for distributed resource servers