Skip to content

Commit

Permalink
additional tests to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thepeachbeetle committed Jul 27, 2017
1 parent 3affd83 commit c1c25ba
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,59 @@ class JwtParserTest {
}
}

@Test
void testParseClaimsWithSigningKeyResolverAdapterWithNoKey() {


String subject = 'Joe'

byte[] key = randomKey()

String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact()

def signingKeyResolver = new SigningKeyResolverAdapter() {
@Override
byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) {
return null
}
}

try {
Jwts.parser().setSigningKeyResolver(signingKeyResolver).parseClaimsJws(compact)
fail()
} catch (UnsupportedJwtException ex) {
assertEquals ex.getMessage(), 'The specified SigningKeyResolver implementation does not support ' +
'Claims JWS signing key resolution. Consider overriding either the resolveSigningKey(JwsHeader, Claims) method ' +
'or, for HMAC algorithms, the resolveSigningKeyBytes(JwsHeader, Claims) method.'
}
}

@Test
void testParseClaimsWithSigningKeyResolverAdapterWithNoKeys() {

String subject = 'Joe'

byte[] key = randomKey()

String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact()

def signingKeyResolver = new SigningKeyResolverAdapter() {
@Override
Collection<byte[]> resolveSigningKeysBytes(JwsHeader header, Claims claims) {
return null
}
}

try {
Jwts.parser().setSigningKeyResolver(signingKeyResolver).parseClaimsJws(compact)
fail()
} catch (UnsupportedJwtException ex) {
assertEquals ex.getMessage(), 'The specified SigningKeyResolver implementation does not support ' +
'Claims JWS signing key resolution. Consider overriding either the resolveSigningKey(JwsHeader, Claims) method ' +
'or, for HMAC algorithms, the resolveSigningKeyBytes(JwsHeader, Claims) method.'
}
}

@Test
void testParseClaimsJwsWithNumericTypes() {
byte[] key = randomKey()
Expand Down

0 comments on commit c1c25ba

Please sign in to comment.