Search in sources :

Example 6 with CerberusJwtClaims

use of com.nike.cerberus.jwt.CerberusJwtClaims in project cerberus by Nike-Inc.

the class JwtServiceTest method test_generate_jwt_token_parse_and_validate_claim.

@Test
public void test_generate_jwt_token_parse_and_validate_claim() throws AuthTokenTooLongException {
    String token = jwtService.generateJwtToken(cerberusJwtClaims);
    assertEquals(3, token.split("\\.").length);
    Optional<CerberusJwtClaims> cerberusJwtClaimsOptional = jwtService.parseAndValidateToken(token);
    assertTrue(cerberusJwtClaimsOptional.isPresent());
    CerberusJwtClaims cerberusJwtClaims = cerberusJwtClaimsOptional.get();
    assertEquals("id", cerberusJwtClaims.getId());
    assertEquals("principal", cerberusJwtClaims.getPrincipal());
    assertEquals("groups", cerberusJwtClaims.getGroups());
    assertEquals(true, cerberusJwtClaims.getIsAdmin());
    assertEquals("type", cerberusJwtClaims.getPrincipalType());
    assertEquals(1, (long) cerberusJwtClaims.getRefreshCount());
    assertEquals(OffsetDateTime.of(2000, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC).toEpochSecond(), cerberusJwtClaims.getCreatedTs().toEpochSecond());
    assertEquals(OffsetDateTime.of(3000, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC).toEpochSecond(), cerberusJwtClaims.getExpiresTs().toEpochSecond());
}
Also used : CerberusJwtClaims(com.nike.cerberus.jwt.CerberusJwtClaims) Test(org.junit.Test)

Aggregations

CerberusJwtClaims (com.nike.cerberus.jwt.CerberusJwtClaims)6 Test (org.junit.Test)3 CerberusAuthToken (com.nike.cerberus.domain.CerberusAuthToken)2 AuthTokenInfo (com.nike.cerberus.domain.AuthTokenInfo)1 CerberusJwtKeySpec (com.nike.cerberus.jwt.CerberusJwtKeySpec)1 Claims (io.jsonwebtoken.Claims)1 JwsHeader (io.jsonwebtoken.JwsHeader)1 OffsetDateTime (java.time.OffsetDateTime)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Before (org.junit.Before)1