Skip to content

Commit 1d2b671

Browse files
committed
Always empty warnings
1 parent 8b45cb1 commit 1d2b671

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/jwt/deprecations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module Deprecations
66
class << self
77
def context
88
yield.tap { emit_warnings }
9+
ensure
10+
Thread.current[:jwt_warning_store] = nil
911
end
1012

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

3234
Thread.current[:jwt_warning_store].each { |warning| warn(warning) }
33-
34-
Thread.current[:jwt_warning_store] = nil
3535
end
3636

3737
private

spec/jwt/jwt_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,23 @@ def valid_alg?(alg)
957957
end
958958
end
959959

960-
context 'when valid token is invalid strict base64' do
960+
context 'when valid token is invalid strict base64 and decoded with the correct key' do
961961
it 'does outputs deprecation warning' do
962-
expect { JWT.decode("#{JWT.encode('a', 'b')} ", 'b') }.to output(/DEPRECATION/).to_stderr
962+
expect { JWT.decode("#{JWT.encode('payload', 'key')} ", 'key') }.to output(/DEPRECATION/).to_stderr
963+
end
964+
end
965+
966+
context 'when valid token is invalid strict base64 and decoded with the incorrect key' do
967+
it 'does not output deprecation warning, even when decoded with the correct key' do
968+
token = JWT.encode('payload', 'key')
969+
expect {
970+
begin
971+
JWT.decode("#{token} ", 'incorrect')
972+
rescue JWT::VerificationError
973+
nil
974+
end
975+
JWT.decode(token, 'key')
976+
}.not_to output(/DEPRECATION/).to_stderr
963977
end
964978
end
965979
end

0 commit comments

Comments
 (0)