Skip to content

Commit

Permalink
Bring back a few specs
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Oct 1, 2024
1 parent 3d0a573 commit 97a5474
Show file tree
Hide file tree
Showing 2 changed files with 415 additions and 0 deletions.
79 changes: 79 additions & 0 deletions spec/jwt/claims_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

RSpec.describe JWT::ClaimsValidator do
let(:validator) { described_class.new(claims) }

describe '#validate!' do
subject { validator.validate! }

shared_examples_for 'a NumericDate claim' do |claim|
context "when #{claim} payload is an integer" do
let(:claims) { { claim => 12_345 } }

it 'does not raise error' do
expect { subject }.not_to raise_error
end

context 'and key is a string' do
let(:claims) { { claim.to_s => 43.32 } }

it 'does not raise error' do
expect { subject }.not_to raise_error
end
end
end

context "when #{claim} payload is a float" do
let(:claims) { { claim => 43.32 } }

it 'does not raise error' do
expect { subject }.not_to raise_error
end
end

context "when #{claim} payload is a string" do
let(:claims) { { claim => '1' } }

it 'raises error' do
expect { subject }.to raise_error JWT::InvalidPayload
end

context 'and key is a string' do
let(:claims) { { claim.to_s => '1' } }

it 'raises error' do
expect { subject }.to raise_error JWT::InvalidPayload
end
end
end

context "when #{claim} payload is a Time object" do
let(:claims) { { claim => Time.now } }

it 'raises error' do
expect { subject }.to raise_error JWT::InvalidPayload
end
end

context "when #{claim} payload is a string" do
let(:claims) { { claim => '1' } }

it 'raises error' do
expect { subject }.to raise_error JWT::InvalidPayload
end
end
end

context 'exp claim' do
it_should_behave_like 'a NumericDate claim', :exp
end

context 'iat claim' do
it_should_behave_like 'a NumericDate claim', :iat
end

context 'nbf claim' do
it_should_behave_like 'a NumericDate claim', :nbf
end
end
end
Loading

0 comments on commit 97a5474

Please sign in to comment.