Search in sources :

Example 1 with Name

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());
}
Also used : DcsResponse(uk.gov.di.ipv.cri.passport.library.domain.DcsResponse) CredentialSubject(uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.CredentialSubject) ECDSASigner(com.nimbusds.jose.crypto.ECDSASigner) JsonNode(com.fasterxml.jackson.databind.JsonNode) SignedJWT(com.nimbusds.jwt.SignedJWT) Name(uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.Name) VerifiableCredential(uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.VerifiableCredential) ECDSAVerifier(com.nimbusds.jose.crypto.ECDSAVerifier) NameParts(uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.NameParts) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) Evidence(uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.Evidence) BirthDate(uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.BirthDate) Test(org.junit.jupiter.api.Test)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ECDSASigner (com.nimbusds.jose.crypto.ECDSASigner)1 ECDSAVerifier (com.nimbusds.jose.crypto.ECDSAVerifier)1 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)1 SignedJWT (com.nimbusds.jwt.SignedJWT)1 Test (org.junit.jupiter.api.Test)1 DcsResponse (uk.gov.di.ipv.cri.passport.library.domain.DcsResponse)1 BirthDate (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.BirthDate)1 CredentialSubject (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.CredentialSubject)1 Evidence (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.Evidence)1 Name (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.Name)1 NameParts (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.NameParts)1 VerifiableCredential (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.VerifiableCredential)1