mirror of
https://github.com/jwtk/jjwt.git
synced 2025-02-13 14:04:43 +00:00
Improve coverage on compact by exercising JsonProcessingException.
This commit is contained in:
parent
4773224c74
commit
7843179ad5
@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.JsonProcessingException
|
||||
import com.fasterxml.jackson.databind.JsonMappingException
|
||||
import io.jsonwebtoken.Jwts
|
||||
import io.jsonwebtoken.SignatureAlgorithm
|
||||
import io.jsonwebtoken.impl.compression.CompressionCodecs
|
||||
import io.jsonwebtoken.impl.crypto.MacProvider
|
||||
import org.junit.Test
|
||||
|
||||
@ -187,6 +188,26 @@ class DefaultJwtBuilderTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCompactCompressionCodecJsonProcessingException() {
|
||||
def b = new DefaultJwtBuilder() {
|
||||
@Override
|
||||
protected byte[] toJson(Object o) throws JsonProcessingException {
|
||||
if (o instanceof DefaultJwsHeader) { return super.toJson(o) }
|
||||
throw new JsonProcessingException('simulate json processing exception on claims')
|
||||
}
|
||||
}
|
||||
|
||||
def c = Jwts.claims().setSubject("Joe");
|
||||
|
||||
try {
|
||||
b.setClaims(c).compressWith(CompressionCodecs.DEFLATE).compact()
|
||||
fail()
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assertEquals iae.message, 'Unable to serialize claims object to json.'
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSignWithBytesWithoutHmac() {
|
||||
def bytes = new byte[16];
|
||||
|
Loading…
x
Reference in New Issue
Block a user