Skip to content

Commit

Permalink
Merge pull request jwtk#43 from dogeared/JwtParserTestFix
Browse files Browse the repository at this point in the history
Jwt parser test fix
  • Loading branch information
lhazlewood committed Sep 10, 2015
2 parents 53f588f + 59993cf commit 335e85f
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setExpiration(exp).compact();

try {
Jwts.parser().parse(compact);
Jwts.parser().parse(compact)
fail()
} catch (ExpiredJwtException e) {
assertTrue e.getMessage().startsWith('JWT expired at ')
}
Expand All @@ -181,7 +182,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setNotBefore(nbf).compact();

try {
Jwts.parser().parse(compact);
Jwts.parser().parse(compact)
fail()
} catch (PrematureJwtException e) {
assertTrue e.getMessage().startsWith('JWT must not be accepted before ')
}
Expand Down Expand Up @@ -268,7 +270,8 @@ class JwtParserTest {
String compact = Jwts.builder().setPayload(payload).compact()

try {
Jwts.parser().parseClaimsJwt(compact);
Jwts.parser().parseClaimsJwt(compact)
fail()
} catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.'
}
Expand Down Expand Up @@ -327,7 +330,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setNotBefore(nbf).compact();

try {
Jwts.parser().parseClaimsJwt(compact);
Jwts.parser().parseClaimsJwt(compact)
fail()
} catch (PrematureJwtException e) {
assertTrue e.getMessage().startsWith('JWT must not be accepted before ')
}
Expand Down Expand Up @@ -361,7 +365,8 @@ class JwtParserTest {
String compact = Jwts.builder().setPayload(payload).compact()

try {
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact);
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.'
}
Expand All @@ -377,7 +382,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).compact()

try {
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact);
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned Claims JWTs are not supported.'
}
Expand All @@ -393,7 +399,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact()

try {
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact);
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Signed Claims JWSs are not supported.'
}
Expand Down Expand Up @@ -452,7 +459,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(sub).setNotBefore(nbf).signWith(SignatureAlgorithm.HS256, key).compact();

try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact);
Jwts.parser().setSigningKey(key).parseClaimsJws(compact)
fail()
} catch (PrematureJwtException e) {
assertTrue e.getMessage().startsWith('JWT must not be accepted before ')
assertEquals e.getClaims().getSubject(), sub
Expand All @@ -470,7 +478,8 @@ class JwtParserTest {
String compact = Jwts.builder().setPayload(payload).compact()

try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact);
Jwts.parser().setSigningKey(key).parseClaimsJws(compact)
fail()
} catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.'
}
Expand All @@ -486,7 +495,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).compact()

try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact);
Jwts.parser().setSigningKey(key).parseClaimsJws(compact)
fail()
} catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned Claims JWTs are not supported.'
}
Expand All @@ -502,7 +512,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact()

try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact);
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Signed Claims JWSs are not supported.'
}
Expand Down

0 comments on commit 335e85f

Please sign in to comment.