Improve coverage on compact by exercising JsonProcessingException.

This commit is contained in:
Micah Silverman 2015-10-27 23:27:18 -04:00
parent 4773224c74
commit 7843179ad5
1 changed files with 21 additions and 0 deletions

View File

@ -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];