mirror of https://github.com/jwtk/jjwt.git
Renamed all the expect methods to require.
This commit is contained in:
parent
72acd649c7
commit
ddda2f92d3
|
@ -33,7 +33,7 @@ public interface JwtParser {
|
||||||
* @param id
|
* @param id
|
||||||
* @return the parser for method chaining.
|
* @return the parser for method chaining.
|
||||||
*/
|
*/
|
||||||
JwtParser expectId(String id);
|
JwtParser requireId(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an expected value for the subject claim.
|
* Sets an expected value for the subject claim.
|
||||||
|
@ -41,7 +41,7 @@ public interface JwtParser {
|
||||||
* @param subject
|
* @param subject
|
||||||
* @return the parser for method chaining.
|
* @return the parser for method chaining.
|
||||||
*/
|
*/
|
||||||
JwtParser expectSubject(String subject);
|
JwtParser requireSubject(String subject);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an expected value for the audience claim.
|
* Sets an expected value for the audience claim.
|
||||||
|
@ -49,7 +49,7 @@ public interface JwtParser {
|
||||||
* @param audience
|
* @param audience
|
||||||
* @return the parser for method chaining.
|
* @return the parser for method chaining.
|
||||||
*/
|
*/
|
||||||
JwtParser expectAudience(String audience);
|
JwtParser requireAudience(String audience);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an expected value for the issuer claim.
|
* Sets an expected value for the issuer claim.
|
||||||
|
@ -57,7 +57,7 @@ public interface JwtParser {
|
||||||
* @param issuer
|
* @param issuer
|
||||||
* @return the parser for method chaining.
|
* @return the parser for method chaining.
|
||||||
*/
|
*/
|
||||||
JwtParser expectIssuer(String issuer);
|
JwtParser requireIssuer(String issuer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an expected value for the issuedAt claim.
|
* Sets an expected value for the issuedAt claim.
|
||||||
|
@ -65,7 +65,7 @@ public interface JwtParser {
|
||||||
* @param issuedAt
|
* @param issuedAt
|
||||||
* @return the parser for method chaining.
|
* @return the parser for method chaining.
|
||||||
*/
|
*/
|
||||||
JwtParser expectIssuedAt(Date issuedAt);
|
JwtParser requireIssuedAt(Date issuedAt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an expected value for any given claim name.
|
* Sets an expected value for any given claim name.
|
||||||
|
@ -82,7 +82,7 @@ public interface JwtParser {
|
||||||
* @param value
|
* @param value
|
||||||
* @return the parser for method chaining.
|
* @return the parser for method chaining.
|
||||||
*/
|
*/
|
||||||
JwtParser expect(String claimName, Object value);
|
JwtParser require(String claimName, Object value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the signing key used to verify any discovered JWS digital signature. If the specified JWT string is not
|
* Sets the signing key used to verify any discovered JWS digital signature. If the specified JWT string is not
|
||||||
|
|
|
@ -65,42 +65,42 @@ public class DefaultJwtParser implements JwtParser {
|
||||||
Claims expectedClaims = new DefaultClaims();
|
Claims expectedClaims = new DefaultClaims();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtParser expectIssuedAt(Date issuedAt) {
|
public JwtParser requireIssuedAt(Date issuedAt) {
|
||||||
expectedClaims.setIssuedAt(issuedAt);
|
expectedClaims.setIssuedAt(issuedAt);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtParser expectIssuer(String issuer) {
|
public JwtParser requireIssuer(String issuer) {
|
||||||
expectedClaims.setIssuer(issuer);
|
expectedClaims.setIssuer(issuer);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtParser expectAudience(String audience) {
|
public JwtParser requireAudience(String audience) {
|
||||||
expectedClaims.setAudience(audience);
|
expectedClaims.setAudience(audience);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtParser expectSubject(String subject) {
|
public JwtParser requireSubject(String subject) {
|
||||||
expectedClaims.setSubject(subject);
|
expectedClaims.setSubject(subject);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtParser expectId(String id) {
|
public JwtParser requireId(String id) {
|
||||||
expectedClaims.setId(id);
|
expectedClaims.setId(id);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtParser expect(String claimName, Object value) {
|
public JwtParser require(String claimName, Object value) {
|
||||||
Assert.hasText(claimName, "claim name cannot be null or empty.");
|
Assert.hasText(claimName, "claim name cannot be null or empty.");
|
||||||
Assert.notNull(value, "The value cannot be null for claim name: " + claimName);
|
Assert.notNull(value, "The value cannot be null for claim name: " + claimName);
|
||||||
expectedClaims.put(claimName, value);
|
expectedClaims.put(claimName, value);
|
||||||
|
|
|
@ -727,7 +727,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectDontAllowNullClaimName() {
|
void testParseRequireDontAllowNullClaimName() {
|
||||||
def expectedClaimValue = 'A Most Awesome Claim Value'
|
def expectedClaimValue = 'A Most Awesome Claim Value'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -740,7 +740,7 @@ class JwtParserTest {
|
||||||
try {
|
try {
|
||||||
// expecting null claim name, but with value
|
// expecting null claim name, but with value
|
||||||
Jwt<Header, Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header, Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expect(null, expectedClaimValue).
|
require(null, expectedClaimValue).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -752,7 +752,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectDontAllowEmptyClaimName() {
|
void testParseRequireDontAllowEmptyClaimName() {
|
||||||
def expectedClaimValue = 'A Most Awesome Claim Value'
|
def expectedClaimValue = 'A Most Awesome Claim Value'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -765,7 +765,7 @@ class JwtParserTest {
|
||||||
try {
|
try {
|
||||||
// expecting null claim name, but with value
|
// expecting null claim name, but with value
|
||||||
Jwt<Header, Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header, Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expect("", expectedClaimValue).
|
require("", expectedClaimValue).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -777,7 +777,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectDontAllowNullClaimValue() {
|
void testParseRequireDontAllowNullClaimValue() {
|
||||||
def expectedClaimName = 'A Most Awesome Claim Name'
|
def expectedClaimName = 'A Most Awesome Claim Name'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -790,7 +790,7 @@ class JwtParserTest {
|
||||||
try {
|
try {
|
||||||
// expecting claim name, but with null value
|
// expecting claim name, but with null value
|
||||||
Jwt<Header, Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header, Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expect(expectedClaimName, null).
|
require(expectedClaimName, null).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -802,7 +802,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectGeneric_Success() {
|
void testParseRequireGeneric_Success() {
|
||||||
def expectedClaimName = 'A Most Awesome Claim Name'
|
def expectedClaimName = 'A Most Awesome Claim Name'
|
||||||
def expectedClaimValue = 'A Most Awesome Claim Value'
|
def expectedClaimValue = 'A Most Awesome Claim Value'
|
||||||
|
|
||||||
|
@ -813,14 +813,14 @@ class JwtParserTest {
|
||||||
compact()
|
compact()
|
||||||
|
|
||||||
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expect(expectedClaimName, expectedClaimValue).
|
require(expectedClaimName, expectedClaimValue).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
|
|
||||||
assertEquals jwt.getBody().get(expectedClaimName), expectedClaimValue
|
assertEquals jwt.getBody().get(expectedClaimName), expectedClaimValue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectGeneric_Incorrect_Fail() {
|
void testParseRequireGeneric_Incorrect_Fail() {
|
||||||
def goodClaimName = 'A Most Awesome Claim Name'
|
def goodClaimName = 'A Most Awesome Claim Name'
|
||||||
def goodClaimValue = 'A Most Awesome Claim Value'
|
def goodClaimValue = 'A Most Awesome Claim Value'
|
||||||
|
|
||||||
|
@ -834,7 +834,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expect(goodClaimName, goodClaimValue).
|
require(goodClaimName, goodClaimValue).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch (IncorrectClaimException e) {
|
} catch (IncorrectClaimException e) {
|
||||||
|
@ -846,7 +846,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectedGeneric_Missing_Fail() {
|
void testParseRequireedGeneric_Missing_Fail() {
|
||||||
def claimName = 'A Most Awesome Claim Name'
|
def claimName = 'A Most Awesome Claim Name'
|
||||||
def claimValue = 'A Most Awesome Claim Value'
|
def claimValue = 'A Most Awesome Claim Value'
|
||||||
|
|
||||||
|
@ -858,7 +858,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expect(claimName, claimValue).
|
require(claimName, claimValue).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch (MissingClaimException e) {
|
} catch (MissingClaimException e) {
|
||||||
|
@ -870,7 +870,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectIssuedAt_Success() {
|
void testParseRequireIssuedAt_Success() {
|
||||||
def issuedAt = new Date(System.currentTimeMillis())
|
def issuedAt = new Date(System.currentTimeMillis())
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -880,7 +880,7 @@ class JwtParserTest {
|
||||||
compact()
|
compact()
|
||||||
|
|
||||||
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expectIssuedAt(issuedAt).
|
requireIssuedAt(issuedAt).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
|
|
||||||
// system converts to seconds (lopping off millis precision), then returns millis
|
// system converts to seconds (lopping off millis precision), then returns millis
|
||||||
|
@ -890,7 +890,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectIssuedAt_Incorrect_Fail() {
|
void testParseRequireIssuedAt_Incorrect_Fail() {
|
||||||
def goodIssuedAt = new Date(System.currentTimeMillis())
|
def goodIssuedAt = new Date(System.currentTimeMillis())
|
||||||
def badIssuedAt = new Date(System.currentTimeMillis() - 10000)
|
def badIssuedAt = new Date(System.currentTimeMillis() - 10000)
|
||||||
|
|
||||||
|
@ -902,7 +902,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectIssuedAt(goodIssuedAt).
|
requireIssuedAt(goodIssuedAt).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(IncorrectClaimException e) {
|
} catch(IncorrectClaimException e) {
|
||||||
|
@ -914,7 +914,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectIssuedAt_Missing_Fail() {
|
void testParseRequireIssuedAt_Missing_Fail() {
|
||||||
def issuedAt = new Date(System.currentTimeMillis() - 10000)
|
def issuedAt = new Date(System.currentTimeMillis() - 10000)
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -925,7 +925,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectIssuedAt(issuedAt).
|
requireIssuedAt(issuedAt).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(MissingClaimException e) {
|
} catch(MissingClaimException e) {
|
||||||
|
@ -937,7 +937,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectIssuer_Success() {
|
void testParseRequireIssuer_Success() {
|
||||||
def issuer = 'A Most Awesome Issuer'
|
def issuer = 'A Most Awesome Issuer'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -947,14 +947,14 @@ class JwtParserTest {
|
||||||
compact()
|
compact()
|
||||||
|
|
||||||
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expectIssuer(issuer).
|
requireIssuer(issuer).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
|
|
||||||
assertEquals jwt.getBody().getIssuer(), issuer
|
assertEquals jwt.getBody().getIssuer(), issuer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectIssuer_Incorrect_Fail() {
|
void testParseRequireIssuer_Incorrect_Fail() {
|
||||||
def goodIssuer = 'A Most Awesome Issuer'
|
def goodIssuer = 'A Most Awesome Issuer'
|
||||||
def badIssuer = 'A Most Bogus Issuer'
|
def badIssuer = 'A Most Bogus Issuer'
|
||||||
|
|
||||||
|
@ -966,7 +966,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectIssuer(goodIssuer).
|
requireIssuer(goodIssuer).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(IncorrectClaimException e) {
|
} catch(IncorrectClaimException e) {
|
||||||
|
@ -978,7 +978,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectIssuer_Missing_Fail() {
|
void testParseRequireIssuer_Missing_Fail() {
|
||||||
def issuer = 'A Most Awesome Issuer'
|
def issuer = 'A Most Awesome Issuer'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -989,7 +989,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectIssuer(issuer).
|
requireIssuer(issuer).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(MissingClaimException e) {
|
} catch(MissingClaimException e) {
|
||||||
|
@ -1001,7 +1001,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectAudience_Success() {
|
void testParseRequireAudience_Success() {
|
||||||
def audience = 'A Most Awesome Audience'
|
def audience = 'A Most Awesome Audience'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -1011,14 +1011,14 @@ class JwtParserTest {
|
||||||
compact()
|
compact()
|
||||||
|
|
||||||
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expectAudience(audience).
|
requireAudience(audience).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
|
|
||||||
assertEquals jwt.getBody().getAudience(), audience
|
assertEquals jwt.getBody().getAudience(), audience
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectAudience_Incorrect_Fail() {
|
void testParseRequireAudience_Incorrect_Fail() {
|
||||||
def goodAudience = 'A Most Awesome Audience'
|
def goodAudience = 'A Most Awesome Audience'
|
||||||
def badAudience = 'A Most Bogus Audience'
|
def badAudience = 'A Most Bogus Audience'
|
||||||
|
|
||||||
|
@ -1030,7 +1030,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectAudience(goodAudience).
|
requireAudience(goodAudience).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(IncorrectClaimException e) {
|
} catch(IncorrectClaimException e) {
|
||||||
|
@ -1042,7 +1042,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectAudience_Missing_Fail() {
|
void testParseRequireAudience_Missing_Fail() {
|
||||||
def audience = 'A Most Awesome audience'
|
def audience = 'A Most Awesome audience'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -1053,7 +1053,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectAudience(audience).
|
requireAudience(audience).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(MissingClaimException e) {
|
} catch(MissingClaimException e) {
|
||||||
|
@ -1065,7 +1065,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectSubject_Success() {
|
void testParseRequireSubject_Success() {
|
||||||
def subject = 'A Most Awesome Subject'
|
def subject = 'A Most Awesome Subject'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -1075,14 +1075,14 @@ class JwtParserTest {
|
||||||
compact()
|
compact()
|
||||||
|
|
||||||
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expectSubject(subject).
|
requireSubject(subject).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
|
|
||||||
assertEquals jwt.getBody().getSubject(), subject
|
assertEquals jwt.getBody().getSubject(), subject
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectSubject_Incorrect_Fail() {
|
void testParseRequireSubject_Incorrect_Fail() {
|
||||||
def goodSubject = 'A Most Awesome Subject'
|
def goodSubject = 'A Most Awesome Subject'
|
||||||
def badSubject = 'A Most Bogus Subject'
|
def badSubject = 'A Most Bogus Subject'
|
||||||
|
|
||||||
|
@ -1094,7 +1094,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectSubject(goodSubject).
|
requireSubject(goodSubject).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(IncorrectClaimException e) {
|
} catch(IncorrectClaimException e) {
|
||||||
|
@ -1106,7 +1106,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectSubject_Missing_Fail() {
|
void testParseRequireSubject_Missing_Fail() {
|
||||||
def subject = 'A Most Awesome Subject'
|
def subject = 'A Most Awesome Subject'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -1117,7 +1117,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectSubject(subject).
|
requireSubject(subject).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(MissingClaimException e) {
|
} catch(MissingClaimException e) {
|
||||||
|
@ -1129,7 +1129,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectId_Success() {
|
void testParseRequireId_Success() {
|
||||||
def id = 'A Most Awesome id'
|
def id = 'A Most Awesome id'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -1139,14 +1139,14 @@ class JwtParserTest {
|
||||||
compact()
|
compact()
|
||||||
|
|
||||||
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
Jwt<Header,Claims> jwt = Jwts.parser().setSigningKey(key).
|
||||||
expectId(id).
|
requireId(id).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
|
|
||||||
assertEquals jwt.getBody().getId(), id
|
assertEquals jwt.getBody().getId(), id
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectId_Incorrect_Fail() {
|
void testParseRequireId_Incorrect_Fail() {
|
||||||
def goodId = 'A Most Awesome Id'
|
def goodId = 'A Most Awesome Id'
|
||||||
def badId = 'A Most Bogus Id'
|
def badId = 'A Most Bogus Id'
|
||||||
|
|
||||||
|
@ -1158,7 +1158,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectId(goodId).
|
requireId(goodId).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(IncorrectClaimException e) {
|
} catch(IncorrectClaimException e) {
|
||||||
|
@ -1170,7 +1170,7 @@ class JwtParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParseExpectId_Missing_Fail() {
|
void testParseRequireId_Missing_Fail() {
|
||||||
def id = 'A Most Awesome Id'
|
def id = 'A Most Awesome Id'
|
||||||
|
|
||||||
byte[] key = randomKey()
|
byte[] key = randomKey()
|
||||||
|
@ -1181,7 +1181,7 @@ class JwtParserTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Jwts.parser().setSigningKey(key).
|
Jwts.parser().setSigningKey(key).
|
||||||
expectId(id).
|
requireId(id).
|
||||||
parseClaimsJws(compact)
|
parseClaimsJws(compact)
|
||||||
fail()
|
fail()
|
||||||
} catch(MissingClaimException e) {
|
} catch(MissingClaimException e) {
|
||||||
|
|
Loading…
Reference in New Issue