Skip to content

Commit

Permalink
Always empty warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Jun 17, 2024
1 parent 8b45cb1 commit 1d2b671
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/jwt/deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Deprecations
class << self
def context
yield.tap { emit_warnings }
ensure
Thread.current[:jwt_warning_store] = nil
end

def warning(message, only_if_valid: false)
Expand All @@ -30,8 +32,6 @@ def emit_warnings
return if Thread.current[:jwt_warning_store].nil?

Thread.current[:jwt_warning_store].each { |warning| warn(warning) }

Thread.current[:jwt_warning_store] = nil
end

private
Expand Down
18 changes: 16 additions & 2 deletions spec/jwt/jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,23 @@ def valid_alg?(alg)
end
end

context 'when valid token is invalid strict base64' do
context 'when valid token is invalid strict base64 and decoded with the correct key' do
it 'does outputs deprecation warning' do
expect { JWT.decode("#{JWT.encode('a', 'b')} ", 'b') }.to output(/DEPRECATION/).to_stderr
expect { JWT.decode("#{JWT.encode('payload', 'key')} ", 'key') }.to output(/DEPRECATION/).to_stderr
end
end

context 'when valid token is invalid strict base64 and decoded with the incorrect key' do
it 'does not output deprecation warning, even when decoded with the correct key' do
token = JWT.encode('payload', 'key')
expect {
begin
JWT.decode("#{token} ", 'incorrect')
rescue JWT::VerificationError
nil
end
JWT.decode(token, 'key')
}.not_to output(/DEPRECATION/).to_stderr
end
end
end

0 comments on commit 1d2b671

Please sign in to comment.