spec/jwt/verify_spec.rb in jwt-1.5.4 vs spec/jwt/verify_spec.rb in jwt-1.5.5
- old
+ new
@@ -1,12 +1,13 @@
+# frozen_string_literal: true
require 'spec_helper'
require 'jwt/verify'
module JWT
RSpec.describe Verify do
let(:base_payload) { { 'user_id' => 'some@user.tld' } }
- let(:options) { { leeway: 0} }
+ let(:options) { { leeway: 0 } }
context '.verify_aud(payload, options)' do
let(:scalar_aud) { 'ruby-jwt-audience' }
let(:array_aud) { %w(ruby-jwt-aud test-aud ruby-ruby-ruby) }
let(:scalar_payload) { base_payload.merge('aud' => scalar_aud) }
@@ -58,10 +59,18 @@
end
it 'must allow some leeway in the expiration when configured' do
Verify.verify_expiration(payload, options.merge(leeway: 10))
end
+
+ it 'must be expired if the exp claim equals the current time' do
+ payload['exp'] = Time.now.to_i
+
+ expect do
+ Verify.verify_expiration(payload, options)
+ end.to raise_error JWT::ExpiredSignature
+ end
end
context '.verify_iat(payload, options)' do
let(:iat) { Time.now.to_f }
let(:payload) { base_payload.merge('iat' => iat) }
@@ -133,15 +142,15 @@
end.to raise_error JWT::InvalidJtiError, /missing/i
end
it 'must raise JWT::InvalidJtiError when verify_jti proc returns false' do
expect do
- Verify.verify_jti(payload, options.merge(verify_jti: ->(jti) { false }))
+ Verify.verify_jti(payload, options.merge(verify_jti: ->(_jti) { false }))
end.to raise_error JWT::InvalidJtiError, /invalid/i
end
it 'true proc should not raise JWT::InvalidJtiError' do
- Verify.verify_jti(payload, options.merge(verify_jti: ->(jti) { true }))
+ Verify.verify_jti(payload, options.merge(verify_jti: ->(_jti) { true }))
end
end
context '.verify_not_before(payload, options)' do
let(:payload) { base_payload.merge('nbf' => (Time.now.to_i + 5)) }