Skip to content

Commit

Permalink
Update JWT, fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelaossa committed Sep 5, 2024
1 parent 88051ce commit 14513b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fridge.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'gem_config'
spec.add_dependency 'jwt', '~> 1.5.6'
spec.add_dependency 'jwt', '~> 2.3.0'

spec.add_development_dependency 'aptible-tasks'
spec.add_development_dependency 'pry'
Expand Down
2 changes: 1 addition & 1 deletion lib/fridge/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Fridge
VERSION = '0.4.5'.freeze
VERSION = '1.0.0'.freeze
end
11 changes: 6 additions & 5 deletions spec/fridge/access_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,22 @@
end

it 'should be verifiable with the application public key' do
expect { JWT.decode(subject.serialize, public_key) }.not_to raise_error
expect { JWT.decode(subject.serialize, public_key, true, algorithm: 'RS512') }
.not_to raise_error
end

it 'should be tamper-resistant' do
header, _, signature = subject.serialize.split('.')
tampered_claim = JWT.base64url_encode({ foo: 'bar' }.to_json)
tampered_claim = JWT::Base64.url_encode({ foo: 'bar' }.to_json)
tampered_token = [header, tampered_claim, signature].join('.')

expect do
JWT.decode(tampered_token, public_key)
JWT.decode(tampered_token, public_key, true, algorithm: 'RS512')
end.to raise_error JWT::DecodeError
end

it 'should represent :exp in seconds since the epoch' do
hash, = JWT.decode(subject.serialize, public_key)
hash, = JWT.decode(subject.serialize, public_key, true, algorithm: 'RS512')
expect(hash['exp']).to be_a Integer
end

Expand Down Expand Up @@ -133,7 +134,7 @@
# test that, although eventually we'll want to see symbols back.
actor_s = { 'sub' => 'foo', 'username' => 'test',
'act' => { 'sub' => 'bar' } }
hash, = JWT.decode(subject.serialize, public_key)
hash, = JWT.decode(subject.serialize, public_key, true, algorithm: 'RS512')
expect(hash['act']).to eq(actor_s)

# Now, check that we properly get symbols back
Expand Down

0 comments on commit 14513b6

Please sign in to comment.