Merge pull request #43 from dogeared/JwtParserTestFix

Jwt parser test fix
This commit is contained in:
Les Hazlewood 2015-09-09 20:18:49 -07:00
commit 335e85f6ee
1 changed files with 22 additions and 11 deletions

View File

@ -167,7 +167,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setExpiration(exp).compact(); String compact = Jwts.builder().setSubject('Joe').setExpiration(exp).compact();
try { try {
Jwts.parser().parse(compact); Jwts.parser().parse(compact)
fail()
} catch (ExpiredJwtException e) { } catch (ExpiredJwtException e) {
assertTrue e.getMessage().startsWith('JWT expired at ') assertTrue e.getMessage().startsWith('JWT expired at ')
} }
@ -181,7 +182,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setNotBefore(nbf).compact(); String compact = Jwts.builder().setSubject('Joe').setNotBefore(nbf).compact();
try { try {
Jwts.parser().parse(compact); Jwts.parser().parse(compact)
fail()
} catch (PrematureJwtException e) { } catch (PrematureJwtException e) {
assertTrue e.getMessage().startsWith('JWT must not be accepted before ') assertTrue e.getMessage().startsWith('JWT must not be accepted before ')
} }
@ -268,7 +270,8 @@ class JwtParserTest {
String compact = Jwts.builder().setPayload(payload).compact() String compact = Jwts.builder().setPayload(payload).compact()
try { try {
Jwts.parser().parseClaimsJwt(compact); Jwts.parser().parseClaimsJwt(compact)
fail()
} catch (UnsupportedJwtException e) { } catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.' assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.'
} }
@ -327,7 +330,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setNotBefore(nbf).compact(); String compact = Jwts.builder().setSubject('Joe').setNotBefore(nbf).compact();
try { try {
Jwts.parser().parseClaimsJwt(compact); Jwts.parser().parseClaimsJwt(compact)
fail()
} catch (PrematureJwtException e) { } catch (PrematureJwtException e) {
assertTrue e.getMessage().startsWith('JWT must not be accepted before ') assertTrue e.getMessage().startsWith('JWT must not be accepted before ')
} }
@ -361,7 +365,8 @@ class JwtParserTest {
String compact = Jwts.builder().setPayload(payload).compact() String compact = Jwts.builder().setPayload(payload).compact()
try { try {
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact); Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) { } catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.' assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.'
} }
@ -377,7 +382,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).compact() String compact = Jwts.builder().setSubject(subject).compact()
try { try {
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact); Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) { } catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned Claims JWTs are not supported.' assertEquals e.getMessage(), 'Unsigned Claims JWTs are not supported.'
} }
@ -393,7 +399,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact() String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact()
try { try {
Jwts.parser().setSigningKey(key).parsePlaintextJws(compact); Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) { } catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Signed Claims JWSs are not supported.' assertEquals e.getMessage(), 'Signed Claims JWSs are not supported.'
} }
@ -452,7 +459,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(sub).setNotBefore(nbf).signWith(SignatureAlgorithm.HS256, key).compact(); String compact = Jwts.builder().setSubject(sub).setNotBefore(nbf).signWith(SignatureAlgorithm.HS256, key).compact();
try { try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact); Jwts.parser().setSigningKey(key).parseClaimsJws(compact)
fail()
} catch (PrematureJwtException e) { } catch (PrematureJwtException e) {
assertTrue e.getMessage().startsWith('JWT must not be accepted before ') assertTrue e.getMessage().startsWith('JWT must not be accepted before ')
assertEquals e.getClaims().getSubject(), sub assertEquals e.getClaims().getSubject(), sub
@ -470,7 +478,8 @@ class JwtParserTest {
String compact = Jwts.builder().setPayload(payload).compact() String compact = Jwts.builder().setPayload(payload).compact()
try { try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact); Jwts.parser().setSigningKey(key).parseClaimsJws(compact)
fail()
} catch (UnsupportedJwtException e) { } catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.' assertEquals e.getMessage(), 'Unsigned plaintext JWTs are not supported.'
} }
@ -486,7 +495,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).compact() String compact = Jwts.builder().setSubject(subject).compact()
try { try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact); Jwts.parser().setSigningKey(key).parseClaimsJws(compact)
fail()
} catch (UnsupportedJwtException e) { } catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Unsigned Claims JWTs are not supported.' assertEquals e.getMessage(), 'Unsigned Claims JWTs are not supported.'
} }
@ -502,7 +512,8 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact() String compact = Jwts.builder().setSubject(subject).signWith(SignatureAlgorithm.HS256, key).compact()
try { try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compact); Jwts.parser().setSigningKey(key).parsePlaintextJws(compact)
fail()
} catch (UnsupportedJwtException e) { } catch (UnsupportedJwtException e) {
assertEquals e.getMessage(), 'Signed Claims JWSs are not supported.' assertEquals e.getMessage(), 'Signed Claims JWSs are not supported.'
} }