Skip to content

Commit

Permalink
Use a default leeway of 0. Fixes #206
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Hunter committed Sep 1, 2017
1 parent 20e40a4 commit a993b40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/jwt/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
module JWT
# JWT verify methods
class Verify
DEFAULTS = {
leeway: 0
}.freeze

class << self
%w(verify_aud verify_expiration verify_iat verify_iss verify_jti verify_not_before verify_sub).each do |method_name|
define_method method_name do |payload, options|
Expand All @@ -21,7 +25,7 @@ def verify_claims(payload, options)

def initialize(payload, options)
@payload = payload
@options = options
@options = DEFAULTS.merge(options)
end

def verify_aud
Expand Down
11 changes: 10 additions & 1 deletion spec/jwt/verify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module JWT
end

context '.verify_expiration(payload, options)' do
let(:leeway) { 10 }
let(:payload) { base_payload.merge('exp' => (Time.now.to_i - 5)) }

it 'must raise JWT::ExpiredSignature when the token has expired' do
Expand All @@ -67,6 +66,16 @@ module JWT
Verify.verify_expiration(payload, options)
end.to raise_error JWT::ExpiredSignature
end

context 'when leeway is not specified' do
let(:options) { {} }

it 'used a default leeway of 0' do
expect do
Verify.verify_expiration(payload, options)
end.to raise_error JWT::ExpiredSignature
end
end
end

context '.verify_iat(payload, options)' do
Expand Down

0 comments on commit a993b40

Please sign in to comment.