File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
965979end
You can’t perform that action at this time.
0 commit comments