Skip to content

Commit 6951436

Browse files
GobinathALanakinj
authored andcommitted
[spec] rspec to test that strings containing exp/nbf/iat are not
validated
1 parent dbcb028 commit 6951436

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

spec/jwt/verify_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
RSpec.describe ::JWT::Verify do
44
let(:base_payload) { { 'user_id' => 'some@user.tld' } }
5+
let(:string_payload) { 'beautyexperts_nbf_iat' }
56
let(:options) { { leeway: 0 } }
67

78
context '.verify_aud(payload, options)' do
@@ -64,6 +65,10 @@
6465
end.to raise_error JWT::ExpiredSignature
6566
end
6667

68+
it 'must not consider string containing exp as expired' do
69+
expect(described_class.verify_expiration(string_payload, options)).to eq(nil)
70+
end
71+
6772
context 'when leeway is not specified' do
6873
let(:options) { {} }
6974

@@ -103,6 +108,10 @@
103108
described_class.verify_iat(payload.merge('iat' => (iat + 120)), options)
104109
end.to raise_error JWT::InvalidIatError
105110
end
111+
112+
it 'must not validate if the payload is a string containing iat' do
113+
expect(described_class.verify_iat(string_payload, options)).to eq(nil)
114+
end
106115
end
107116

108117
context '.verify_iss(payload, options)' do
@@ -265,6 +274,10 @@ def issuer_start_with_ruby?(issuer)
265274
it 'must allow some leeway in the token age when nbf_leeway is configured' do
266275
described_class.verify_not_before(payload, options.merge(nbf_leeway: 10))
267276
end
277+
278+
it 'must not validate if the payload is a string containing iat' do
279+
expect(described_class.verify_not_before(string_payload, options)).to eq(nil)
280+
end
268281
end
269282

270283
context '.verify_sub(payload, options)' do

0 commit comments

Comments
 (0)