-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensured DeflateCompressionCodec could fallback to <= 0.10.6 implement…
…ation if encountering an IOException. This allows compressed JWTs created before 0.10.7 to still work. Fixes #536 (#556) (#557)
- Loading branch information
1 parent
950e6fb
commit c38f4af
Showing
3 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
impl/src/test/groovy/io/jsonwebtoken/impl/compression/DeflateCompressionCodecTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.jsonwebtoken.impl.compression | ||
|
||
import io.jsonwebtoken.CompressionException | ||
import io.jsonwebtoken.Jwts | ||
import io.jsonwebtoken.io.Decoders | ||
import org.junit.Test | ||
|
||
import static org.junit.Assert.assertNotSame | ||
|
||
/** | ||
* @since 0.10.8 | ||
*/ | ||
class DeflateCompressionCodecTest { | ||
|
||
/** | ||
* Test case for <a href="https://github.com/jwtk/jjwt/issues/536">Issue 536</a>. | ||
*/ | ||
@Test | ||
void testBackwardsCompatibility_0_10_6() { | ||
final String jwtFrom0106 = 'eyJhbGciOiJub25lIiwiemlwIjoiREVGIn0.eNqqVsosLlayUspNVdJRKi5NAjJLi1OLgJzMxBIlK0sTMzMLEwsDAx2l1IoCJSsTQwMjExOQQC0AAAD__w.' | ||
Jwts.parserBuilder().build().parseClaimsJwt(jwtFrom0106) // no exception should be thrown | ||
} | ||
|
||
/** | ||
* Test to ensure that, even if the backwards-compatibility fallback method throws an exception, that the first | ||
* one is retained/re-thrown to reflect the correct/expected implementation. | ||
*/ | ||
@Test | ||
void testBackwardsCompatibilityRetainsFirstIOException() { | ||
|
||
final String compressedFrom0_10_6 = 'eNqqVsosLlayUspNVdJRKi5NAjJLi1OLgJzMxBIlK0sTMzMLEwsDAx2l1IoCJSsTQwMjExOQQC0AAAD__w' | ||
byte[] invalid = Decoders.BASE64URL.decode(compressedFrom0_10_6) | ||
|
||
IOException unexpected = new IOException("foo") | ||
|
||
def codec = new DeflateCompressionCodec() { | ||
@Override | ||
byte[] doDecompressBackCompat(byte[] compressed) throws IOException { | ||
throw unexpected | ||
} | ||
} | ||
|
||
try { | ||
codec.decompress(invalid) | ||
} catch (CompressionException ce) { | ||
assertNotSame(unexpected, ce.getCause()) | ||
} | ||
} | ||
} |