use of uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.Name in project di-ipv-cri-uk-passport-back by alphagov.
the class JwtHelperTest method shouldCreateValidSignedJWT.
@Test
void shouldCreateValidSignedJWT() throws JOSEException, ParseException, InvalidKeySpecException, NoSuchAlgorithmException, JsonProcessingException {
ECDSASigner ecSigner = new ECDSASigner(getPrivateKey());
VerifiableCredential verifiableCredential = new VerifiableCredential(new CredentialSubject(new Name(List.of(new NameParts(GIVEN_NAME, NamePartType.GIVEN_NAME.getName(), VALID_FROM, VALID_UNTIL))), PASSPORT_NUMBER, new BirthDate(BIRTH_DATE), LocalDate.parse(EXPIRY_DATE).toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new DcsResponse()), Collections.singletonList(new Evidence()));
JWTClaimsSet testClaimsSet = new JWTClaimsSet.Builder().claim("sub", "test-subject").claim("iss", "test-issuer").claim("nbf", Instant.now().getEpochSecond()).claim("vc", verifiableCredential).claim("exp", Instant.now().plusSeconds(100000).getEpochSecond()).build();
SignedJWT signedJWT = JwtHelper.createSignedJwtFromClaimSet(testClaimsSet, ecSigner);
JWTClaimsSet generatedClaims = signedJWT.getJWTClaimsSet();
assertTrue(signedJWT.verify(new ECDSAVerifier(ECKey.parse(EC_PUBLIC_JWK_1))));
JsonNode claimsSet = objectMapper.readTree(generatedClaims.toString());
JsonNode vcNode = claimsSet.get("vc");
JsonNode credentialSubjectNode = vcNode.get("credentialSubject");
JsonNode nameNode = credentialSubjectNode.get("name");
assertEquals(GIVEN_NAME, nameNode.get("nameParts").get(0).get("value").asText());
assertEquals(NamePartType.GIVEN_NAME.getName(), nameNode.get("nameParts").get(0).get("type").asText());
assertEquals(VALID_FROM, nameNode.get("nameParts").get(0).get("validFrom").asText());
assertEquals(VALID_UNTIL, nameNode.get("nameParts").get(0).get("validUntil").asText());
assertEquals(BIRTH_DATE, credentialSubjectNode.get("birthDate").get("value").asText());
assertEquals(EXPIRY_DATE, credentialSubjectNode.get("expiryDate").asText());
}
Aggregations