|
552 | 552 | end |
553 | 553 |
|
554 | 554 | context 'a token with invalid Base64 segments' do |
555 | | - it 'raises JWT::DecodeError' do |
556 | | - expect { JWT.decode('hello.there.world') }.to raise_error(JWT::DecodeError, 'Invalid segment encoding') |
| 555 | + it 'raises JWT::Base64DecodeError' do |
| 556 | + expect { JWT.decode('hello.there.world') }.to raise_error(JWT::Base64DecodeError, 'Invalid base64 encoding') |
557 | 557 | end |
558 | 558 | end |
559 | 559 |
|
560 | 560 | context 'a token with two segments but does not require verifying' do |
561 | 561 | it 'raises something else than "Not enough or too many segments"' do |
562 | | - expect { JWT.decode('ThisIsNotAValidJWTToken.second', nil, false) }.to raise_error(JWT::DecodeError, 'Invalid segment encoding') |
| 562 | + expect { JWT.decode('ThisIsNotAValidJWTToken.second', nil, false) }.to raise_error(JWT::Base64DecodeError, 'Invalid base64 encoding') |
563 | 563 | end |
564 | 564 | end |
565 | 565 |
|
|
736 | 736 |
|
737 | 737 | context 'when token ends with a newline char' do |
738 | 738 | let(:token) { "#{JWT.encode(payload, 'secret', 'HS256')}\n" } |
739 | | - it 'ignores the newline and decodes the token' do |
740 | | - expect(JWT.decode(token, 'secret', true, algorithm: 'HS256')).to include(payload) |
| 739 | + it 'raises an error' do |
| 740 | + expect { JWT.decode(token, 'secret', true, algorithm: 'HS256') }.to raise_error(JWT::Base64DecodeError, 'Invalid base64 encoding') |
741 | 741 | end |
742 | 742 | end |
743 | 743 |
|
@@ -949,34 +949,4 @@ def verify(*) |
949 | 949 | end |
950 | 950 | end |
951 | 951 | end |
952 | | - |
953 | | - context 'when invalid token is valid loose base64' do |
954 | | - it 'does not output deprecations warnings' do |
955 | | - expect do |
956 | | - JWT.decode("#{JWT.encode('a', 'b')} 9", 'b') |
957 | | - rescue JWT::VerificationError |
958 | | - nil |
959 | | - end.not_to output(/DEPRECATION/).to_stderr |
960 | | - end |
961 | | - end |
962 | | - |
963 | | - context 'when valid token is invalid strict base64 and decoded with the correct key' do |
964 | | - it 'does outputs deprecation warning' do |
965 | | - expect { JWT.decode("#{JWT.encode('payload', 'key')} ", 'key') }.to output(/DEPRECATION/).to_stderr |
966 | | - end |
967 | | - end |
968 | | - |
969 | | - context 'when valid token is invalid strict base64 and decoded with the incorrect key' do |
970 | | - it 'does not output deprecation warning, even when decoded with the correct key' do |
971 | | - token = JWT.encode('payload', 'key') |
972 | | - expect do |
973 | | - begin |
974 | | - JWT.decode("#{token} ", 'incorrect') |
975 | | - rescue JWT::VerificationError |
976 | | - nil |
977 | | - end |
978 | | - JWT.decode(token, 'key') |
979 | | - end.not_to output(/DEPRECATION/).to_stderr |
980 | | - end |
981 | | - end |
982 | 952 | end |
0 commit comments