Skip to content

Commit

Permalink
More advanced test
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Oct 2, 2024
1 parent 2ac5e61 commit 5144e6a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/jwt/claims_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@
end
end
end

context 'various types of params' do
context 'when payload is missing most of the claims' do
it 'raises an error' do
expect do
described_class.verify_payload!(payload,
:nbf,
iss: ['www.host.com', 'https://other.host.com'].freeze,
aud: 'aud',
exp: { leeway: 10 })
end.to raise_error(JWT::InvalidIssuerError)
end
end

context 'when payload has everything that is expected of it' do
let(:payload) { { 'iss' => 'www.host.com', 'aud' => 'audience', 'exp' => Time.now.to_i - 10, 'pay' => 'load' } }

it 'does not raise' do
expect do
described_class.verify_payload!(payload,
:nbf,
iss: ['www.host.com', 'https://other.host.com'].freeze,
aud: 'audience',
exp: { leeway: 11 })
end.not_to raise_error
end
end
end
end

describe '.payload_errors' do
Expand All @@ -72,5 +100,22 @@
end
end
end

context 'various types of params' do
let(:payload) { { 'exp' => Time.now.to_i - 10, 'pay' => 'load' } }

context 'when payload is most of the claims' do
it 'raises an error' do
messages = described_class.payload_errors(payload,
:nbf,
iss: ['www.host.com', 'https://other.host.com'].freeze,
aud: 'aud',
exp: { leeway: 10 }).map(&:message)
expect(messages).to eq(['Invalid issuer. Expected ["www.host.com", "https://other.host.com"], received <none>',
'Invalid audience. Expected aud, received <none>',
'Signature has expired'])
end
end
end
end
end

0 comments on commit 5144e6a

Please sign in to comment.