From e00620d3851853eb846d1578564ec72897b847b3 Mon Sep 17 00:00:00 2001 From: Nitin Vavdiya Date: Thu, 23 May 2024 16:34:40 +0530 Subject: [PATCH] fix: formatting --- .../dto/CredentialVerificationRequest.java | 33 +++++++++---------- .../dto/CredentialsResponse.java | 4 +-- .../dto/IssueMembershipCredentialRequest.java | 22 ++++++------- .../service/CommonService.java | 1 - .../service/HoldersCredentialService.java | 4 +-- .../service/IssuersCredentialService.java | 12 +++---- .../service/PresentationService.java | 7 ++-- .../service/WalletKeyService.java | 8 ++--- .../utils/CommonUtils.java | 16 ++++----- .../service/IssuersCredentialServiceTest.java | 27 +++++++-------- .../utils/MockUtil.java | 30 +++++++++-------- .../vc/HoldersCredentialTest.java | 12 +++---- .../vc/IssuersCredentialTest.java | 26 ++++++++++----- .../vc/MembershipHoldersCredentialTest.java | 10 ++++-- .../vc/PresentationValidationTest.java | 2 +- .../vp/PresentationTest.java | 19 +++++++---- .../wallet/WalletTest.java | 4 +-- 17 files changed, 125 insertions(+), 112 deletions(-) diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialVerificationRequest.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialVerificationRequest.java index 7e6ba71ab..c4f9dd4a2 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialVerificationRequest.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialVerificationRequest.java @@ -19,22 +19,21 @@ * ****************************************************************************** */ - package org.eclipse.tractusx.managedidentitywallets.dto; +package org.eclipse.tractusx.managedidentitywallets.dto; - import org.eclipse.tractusx.managedidentitywallets.constant.StringPool; - - import java.util.LinkedHashMap; - import java.util.Map; - - public class CredentialVerificationRequest extends LinkedHashMap { - - - public void setJwt(String jwt) { - put(StringPool.VC_JWT_KEY, jwt); - } +import org.eclipse.tractusx.managedidentitywallets.constant.StringPool; + +import java.util.LinkedHashMap; +import java.util.Map; - public void setVc(Map vc) { - putAll(vc); - } - } - \ No newline at end of file +public class CredentialVerificationRequest extends LinkedHashMap { + + + public void setJwt(String jwt) { + put(StringPool.VC_JWT_KEY, jwt); + } + + public void setVc(Map vc) { + putAll(vc); + } +} diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialsResponse.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialsResponse.java index 28041606a..d90d7e445 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialsResponse.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/CredentialsResponse.java @@ -32,8 +32,8 @@ public void setJwt(String jwt) { put(StringPool.VC_JWT_KEY, jwt); } - public void setVc(Map vc) { + public void setVc(Map vc) { putAll(vc); } - + } diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/IssueMembershipCredentialRequest.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/IssueMembershipCredentialRequest.java index 9badf4774..59fc852a3 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/IssueMembershipCredentialRequest.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/dto/IssueMembershipCredentialRequest.java @@ -19,7 +19,7 @@ * ****************************************************************************** */ - package org.eclipse.tractusx.managedidentitywallets.dto; +package org.eclipse.tractusx.managedidentitywallets.dto; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.constraints.NotBlank; @@ -34,18 +34,18 @@ /** * The type Issue membership credential request. */ - @Getter - @Setter - @NoArgsConstructor - @Builder - @AllArgsConstructor - public class IssueMembershipCredentialRequest { +@Getter +@Setter +@NoArgsConstructor +@Builder +@AllArgsConstructor +public class IssueMembershipCredentialRequest { - @NotBlank(message = "Please provide BPN") - @Pattern(regexp = StringPool.BPN_NUMBER_REGEX, message = "Please provide valid BPN") - private String bpn; + @NotBlank(message = "Please provide BPN") + @Pattern(regexp = StringPool.BPN_NUMBER_REGEX, message = "Please provide valid BPN") + private String bpn; @JsonProperty("asJwt") private boolean asJwt; - } +} diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CommonService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CommonService.java index 9feacdca7..178736ac2 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CommonService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/CommonService.java @@ -29,7 +29,6 @@ import org.eclipse.tractusx.managedidentitywallets.exception.WalletNotFoundProblem; import org.eclipse.tractusx.managedidentitywallets.utils.CommonUtils; import org.eclipse.tractusx.managedidentitywallets.utils.Validate; -import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java index 4e6ade139..5c7fad88e 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/HoldersCredentialService.java @@ -130,7 +130,7 @@ public PageImpl getCredentials(GetCredentialsCommand comman for (HoldersCredential credential : filter.getContent()) { CredentialsResponse cr = new CredentialsResponse(); if (command.isAsJwt()) { - cr.setJwt(CommonUtils.vcAsJwt(command.getIdentifier() != null ? commonService.getWalletByIdentifier(command.getIdentifier()) : holderWallet , holderWallet, credential.getData(), walletKeyService)); + cr.setJwt(CommonUtils.vcAsJwt(command.getIdentifier() != null ? commonService.getWalletByIdentifier(command.getIdentifier()) : holderWallet, holderWallet, credential.getData(), walletKeyService)); } else { cr.setVc(credential.getData()); } @@ -176,7 +176,7 @@ public CredentialsResponse issueCredential(Map data, String call // Return VC if (asJwt) { - cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, commonService.getWalletByIdentifier(callerBpn), credential.getData() , walletKeyService)); + cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, commonService.getWalletByIdentifier(callerBpn), credential.getData(), walletKeyService)); } else { cr.setVc(credential.getData()); } diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java index d8b335eb6..83a58e147 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java @@ -260,7 +260,7 @@ public CredentialsResponse issueFrameworkCredential(IssueFrameworkCredentialRequ // Return VC if (asJwt) { - cr.setJwt(CommonUtils.vcAsJwt(baseWallet, holderWallet, issuersCredential.getData() , walletKeyService)); + cr.setJwt(CommonUtils.vcAsJwt(baseWallet, holderWallet, issuersCredential.getData(), walletKeyService)); } else { cr.setVc(issuersCredential.getData()); } @@ -279,7 +279,7 @@ public CredentialsResponse issueFrameworkCredential(IssueFrameworkCredentialRequ * @return the verifiable credential */ @Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED) - public CredentialsResponse issueDismantlerCredential(IssueDismantlerCredentialRequest request, boolean asJwt, String callerBPN) { + public CredentialsResponse issueDismantlerCredential(IssueDismantlerCredentialRequest request, boolean asJwt, String callerBPN) { //Fetch Holder Wallet Wallet holderWallet = commonService.getWalletByIdentifier(request.getBpn()); @@ -320,7 +320,7 @@ public CredentialsResponse issueDismantlerCredential(IssueDismantlerCredentialRe // Return VC if (asJwt) { - cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData() , walletKeyService)); + cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData(), walletKeyService)); } else { cr.setVc(issuersCredential.getData()); } @@ -383,7 +383,7 @@ public CredentialsResponse issueMembershipCredential(IssueMembershipCredentialRe // Return VC if (asJwt) { - cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData() , walletKeyService)); + cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData(), walletKeyService)); } else { cr.setVc(issuersCredential.getData()); } @@ -441,7 +441,7 @@ public CredentialsResponse issueCredentialUsingBaseWallet(String holderDid, Map< // Return VC if (asJwt) { - cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData() , walletKeyService)); + cr.setJwt(CommonUtils.vcAsJwt(issuerWallet, holderWallet, issuersCredential.getData(), walletKeyService)); } else { cr.setVc(issuersCredential.getData()); } @@ -518,7 +518,7 @@ public Map credentialsValidation(CredentialVerificationRequest v * @return the map */ @SneakyThrows - public Map credentialsValidation(CredentialVerificationRequest verificationRequest, boolean withCredentialsValidation , boolean withCredentialExpiryDate) { + public Map credentialsValidation(CredentialVerificationRequest verificationRequest, boolean withCredentialsValidation, boolean withCredentialExpiryDate) { HttpClient httpClient = HttpClient.newBuilder() .followRedirects(HttpClient.Redirect.ALWAYS) .build(); diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java index 86dcd4d11..0a1b783e8 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java @@ -145,8 +145,7 @@ public Map createPresentation(Map data, boolean return buildVP(asJwt, audience, callerBpn, callerWallet, verifiableCredentials, SupportedAlgorithms.ED25519); } - private Map buildVP(boolean asJwt, String audience, String callerBpn, Wallet callerWallet, - List verifiableCredentials, SupportedAlgorithms algorithm){ + private Map buildVP(boolean asJwt, String audience, String callerBpn, Wallet callerWallet, List verifiableCredentials, SupportedAlgorithms algorithm) { Map response = new HashMap<>(); if (asJwt && algorithm.equals(SupportedAlgorithms.ES256K)) { buildVPJwtES256K(audience, callerBpn, callerWallet, verifiableCredentials, algorithm, response); @@ -172,7 +171,7 @@ private void buildVPJsonLd(String callerBpn, List verifiab response.put(StringPool.VP, verifiablePresentation); } - @SneakyThrows({ InvalidPrivateKeyFormatException.class}) + @SneakyThrows({ InvalidPrivateKeyFormatException.class }) private void buildVPJwtEdDSA(String audience, String callerBpn, Wallet callerWallet, List verifiableCredentials, SupportedAlgorithms algorithm, Map response) { Pair result = getPrivateKey(callerWallet, algorithm, audience, callerBpn); String keyId = walletKeyService.getWalletKeyIdByWalletId(callerWallet.getId()); @@ -182,7 +181,7 @@ private void buildVPJwtEdDSA(String audience, String callerBpn, Wallet callerWal X25519PrivateKey ed25519Key = (X25519PrivateKey) result.getRight(); X25519PrivateKey privateKey = new X25519PrivateKey(ed25519Key.asByte()); - SignedJWT presentation = presentationFactory.createPresentation(result.getLeft(), verifiableCredentials, audience, privateKey , keyId); + SignedJWT presentation = presentationFactory.createPresentation(result.getLeft(), verifiableCredentials, audience, privateKey, keyId); response.put(StringPool.VP, presentation.serialize()); } diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java index 8bc7234e4..b077677ec 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletKeyService.java @@ -68,7 +68,7 @@ protected SpecificationUtil getSpecificationUtil() { /** * Get private key by wallet identifier as bytes byte [ ]. * - * @param walletId the wallet id + * @param walletId the wallet id * @param algorithm the algorithm * @return the byte [ ] */ @@ -85,7 +85,7 @@ public byte[] getPrivateKeyByWalletIdAsBytes(long walletId, String algorithm) { /** * Gets private key by wallet identifier. * - * @param walletId the wallet id + * @param walletId the wallet id * @param algorithm the algorithm * @return the private key by wallet identifier */ @@ -104,8 +104,8 @@ public Object getPrivateKeyByWalletIdAndAlgorithm(long walletId, SupportedAlgori } } - /** - * Gets wallet key by wallet id. + /** + * Gets wallet key by wallet id. * * @param walletId the wallet id * @return the wallet key by wallet identifier diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java index cf91fafe4..0f0842f78 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java @@ -99,9 +99,7 @@ public static String getIdentifierType(String identifier) { * @param holderDid the holder did * @return the credential */ - public static HoldersCredential getHoldersCredential(VerifiableCredentialSubject subject, List types, - DidDocument issuerDoc, - byte[] privateKeyBytes, String holderDid, List contexts, Date expiryDate, boolean selfIssued) { + public static HoldersCredential getHoldersCredential(VerifiableCredentialSubject subject, List types, DidDocument issuerDoc, byte[] privateKeyBytes, String holderDid, List contexts, Date expiryDate, boolean selfIssued) { List cloneTypes = new ArrayList<>(types); // Create VC @@ -121,11 +119,8 @@ public static HoldersCredential getHoldersCredential(VerifiableCredentialSubject .build(); } - @SneakyThrows({UnsupportedSignatureTypeException.class , InvalidPrivateKeyFormatException.class , SignatureGenerateFailedException.class , TransformJsonLdException.class}) - private static VerifiableCredential createVerifiableCredential(DidDocument issuerDoc, - List verifiableCredentialType, - VerifiableCredentialSubject verifiableCredentialSubject, - byte[] privateKey, List contexts, Date expiryDate) { + @SneakyThrows({ UnsupportedSignatureTypeException.class, InvalidPrivateKeyFormatException.class, SignatureGenerateFailedException.class, TransformJsonLdException.class }) + private static VerifiableCredential createVerifiableCredential(DidDocument issuerDoc, List verifiableCredentialType, VerifiableCredentialSubject verifiableCredentialSubject, byte[] privateKey, List contexts, Date expiryDate) { // VC Builder // if the credential does not contain the JWS proof-context add it @@ -180,8 +175,9 @@ public static SecureTokenRequest getSecureTokenRequest(MultiValueMap singleValueMap = map.toSingleValueMap(); return objectMapper.convertValue(singleValueMap, SecureTokenRequest.class); } - @SneakyThrows({DidParseException.class}) - public static String vcAsJwt(Wallet issuerWallet, Wallet holderWallet, VerifiableCredential vc , WalletKeyService walletKeyService){ + + @SneakyThrows({ DidParseException.class }) + public static String vcAsJwt(Wallet issuerWallet, Wallet holderWallet, VerifiableCredential vc, WalletKeyService walletKeyService) { Did issuerDid = DidParser.parse(issuerWallet.getDid()); Did holderDid = DidParser.parse(holderWallet.getDid()); diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java index 298839d26..5d682abfd 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java @@ -135,8 +135,7 @@ public static void beforeAll() throws SQLException { walletKeyService, holdersCredentialRepository, commonService, - objectMapper - ); + objectMapper); } @BeforeEach @@ -174,10 +173,10 @@ void shouldIssueCredentialAsJwt() when(walletKey.getKeyId()).thenReturn(KEY_ID); when(walletKey.getId()).thenReturn(42L); when(baseWallet.getAlgorithm()).thenReturn("ED25519"); - when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) + when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) .thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true)); when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId); - when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey() + when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey() .asByte()); CredentialsResponse credentialsResponse = assertDoesNotThrow( () -> issuersCredentialService.issueMembershipCredential( @@ -225,9 +224,9 @@ void shouldIssueCredentialAsJwt() when(walletKey.getKeyId()).thenReturn(KEY_ID); when(walletKey.getId()).thenReturn(42L); when(baseWallet.getAlgorithm()).thenReturn("ED25519"); - when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey() + when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey() .asByte()); - when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) + when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) .thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true)); when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId); @@ -266,10 +265,9 @@ void shouldIssueCredentialAsJwt() throws IOException, InvalidPrivateKeyFormatExc when(walletKey.getKeyId()).thenReturn(KEY_ID); when(walletKey.getId()).thenReturn(42L); when(baseWallet.getAlgorithm()).thenReturn("ED25519"); - when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) + when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) .thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true)); - when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey() - .asByte()); + when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey().asByte()); when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId); CredentialsResponse credentialsResponse = assertDoesNotThrow( @@ -301,7 +299,7 @@ void shouldIssueCredentialAsJwt() throws IOException, ParseException, InvalidPri MockUtil.generateDid("basewallet")).build(); MockUtil.makeCreateWorkForIssuer(issuersCredentialRepository); - when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey() + when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), "ED25519")).thenReturn(keyPair.getPrivateKey() .asByte()); when(commonService.getWalletByIdentifier(holderWalletBpn)).thenReturn(holderWallet); when(commonService.getWalletByIdentifier(verifiableCredential.getIssuer() @@ -321,7 +319,7 @@ public HoldersCredential answer(InvocationOnMock invocation) throws Throwable { when(walletKey.getKeyId()).thenReturn(KEY_ID); when(baseWallet.getAlgorithm()).thenReturn("ED25519"); when(walletKey.getId()).thenReturn(42L); - when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) + when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId(), SupportedAlgorithms.valueOf(baseWallet.getAlgorithm()))) .thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true)); when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId); @@ -343,9 +341,8 @@ class jwtValidationTest { @RegisterExtension static WireMockExtension issuer = WireMockExtension.newInstance() - .options(wireMockConfig() - .dynamicPort() - // .notifier(new ConsoleNotifier(true)) + .options(wireMockConfig().dynamicPort() + // .notifier(new ConsoleNotifier(true)) ) .build(); @@ -435,7 +432,7 @@ private void mockCommon( when(miwSettings.authorityWalletBpn()).thenReturn(baseWalletBpn); when(commonService.getWalletByIdentifier(baseWalletBpn)).thenReturn(baseWallet); when(commonService.getWalletByIdentifier(holderWalletBpn)).thenReturn(holderWallet); - when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() ,baseWallet.getAlgorithm())) + when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId(), baseWallet.getAlgorithm())) .thenReturn(keyPair.getPrivateKey().asByte()); when(miwSettings.supportedFrameworkVCTypes()).thenReturn(Set.of("SustainabilityCredential")); when(holdersCredentialRepository.save(any(HoldersCredential.class))) diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/MockUtil.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/MockUtil.java index 45928a7a4..7743c10b6 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/MockUtil.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/MockUtil.java @@ -18,12 +18,10 @@ * SPDX-License-Identifier: Apache-2.0 * ****************************************************************************** */ - package org.eclipse.tractusx.managedidentitywallets.utils; +package org.eclipse.tractusx.managedidentitywallets.utils; import com.nimbusds.jose.util.JSONObjectUtils; - import lombok.SneakyThrows; - import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential; import org.eclipse.tractusx.managedidentitywallets.dao.entity.IssuersCredential; import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet; @@ -37,7 +35,14 @@ import org.eclipse.tractusx.ssi.lib.exception.proof.UnsupportedSignatureTypeException; import org.eclipse.tractusx.ssi.lib.model.MultibaseString; import org.eclipse.tractusx.ssi.lib.model.base.MultibaseFactory; -import org.eclipse.tractusx.ssi.lib.model.did.*; +import org.eclipse.tractusx.ssi.lib.model.did.Did; +import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; +import org.eclipse.tractusx.ssi.lib.model.did.DidDocumentBuilder; +import org.eclipse.tractusx.ssi.lib.model.did.DidMethod; +import org.eclipse.tractusx.ssi.lib.model.did.DidMethodIdentifier; +import org.eclipse.tractusx.ssi.lib.model.did.Ed25519VerificationMethod; +import org.eclipse.tractusx.ssi.lib.model.did.Ed25519VerificationMethodBuilder; +import org.eclipse.tractusx.ssi.lib.model.did.VerificationMethod; import org.eclipse.tractusx.ssi.lib.model.proof.Proof; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialBuilder; @@ -59,7 +64,11 @@ import java.text.ParseException; import java.time.Duration; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Random; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -165,14 +174,9 @@ public static DidDocument buildDidDocument(Did did, KeyPair keyPair) { // Building Verification Methods: List verificationMethods = new ArrayList<>(); - Ed25519VerificationMethodBuilder builder = new Ed25519VerificationMethodBuilder(); - Ed25519VerificationMethod key = - builder - .id(URI.create(did.toUri() + "#key-" + 1)) - .controller(did.toUri()) - .publicKeyMultiBase(publicKeyBase) - .build(); - verificationMethods.add(key); + Ed25519VerificationMethodBuilder builder = new Ed25519VerificationMethodBuilder(); + Ed25519VerificationMethod key = builder.id(URI.create(did.toUri() + "#key-" + 1)).controller(did.toUri()).publicKeyMultiBase(publicKeyBase).build(); + verificationMethods.add(key); DidDocumentBuilder didDocumentBuilder = new DidDocumentBuilder(); didDocumentBuilder.id(did.toUri()); didDocumentBuilder.verificationMethods(verificationMethods); diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java index e71fc9407..7698ffcf7 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java @@ -84,8 +84,8 @@ import static org.eclipse.tractusx.managedidentitywallets.constant.StringPool.COLON_SEPARATOR; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = {ManagedIdentityWalletsApplication.class}) -@ContextConfiguration(initializers = {TestContextInitializer.class}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { ManagedIdentityWalletsApplication.class }) +@ContextConfiguration(initializers = { TestContextInitializer.class }) @ExtendWith(MockitoExtension.class) class HoldersCredentialTest { @@ -251,7 +251,7 @@ void getCredentialsAsJWT200() throws com.fasterxml.jackson.core.JsonProcessingEx jsonObject.get(StringPool.TYPE).toString()); HttpEntity entity = new HttpEntity<>(request, AuthenticationUtils.getValidUserHttpHeaders(miwSettings.authorityWalletBpn())); // ony base wallet - // can issue VC + // can issue VC ResponseEntity exchange = restTemplate.exchange(RestURI.API_CREDENTIALS_ISSUER_FRAMEWORK, HttpMethod.POST, entity, String.class); Assertions.assertEquals(exchange.getStatusCode().value(), HttpStatus.CREATED.value()); @@ -263,10 +263,10 @@ void getCredentialsAsJWT200() throws com.fasterxml.jackson.core.JsonProcessingEx HttpMethod.GET, entity, String.class, baseDID); Assertions.assertEquals(HttpStatus.OK.value(), response.getStatusCode().value()); - Map responseMap = SerializeUtil.fromJson(response.getBody()); - List> vcsAsJwt = (ArrayList>) responseMap.get("content"); + Map responseMap = SerializeUtil.fromJson(response.getBody()); + List> vcsAsJwt = (ArrayList>) responseMap.get("content"); // 5 framework + 1 BPN + 1 Summary - Assertions.assertEquals(7 , vcsAsJwt.size()); + Assertions.assertEquals(7, vcsAsJwt.size()); vcsAsJwt.forEach(vc -> { Assertions.assertNotNull(vc.get(StringPool.VC_JWT_KEY)); }); diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java index ffde1a3ba..956719b34 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java @@ -19,7 +19,7 @@ * ****************************************************************************** */ - + package org.eclipse.tractusx.managedidentitywallets.vc; import com.fasterxml.jackson.core.JsonProcessingException; @@ -54,17 +54,25 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.ContextConfiguration; import java.net.URI; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; import static org.eclipse.tractusx.managedidentitywallets.constant.StringPool.COLON_SEPARATOR; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = {ManagedIdentityWalletsApplication.class}) -@ContextConfiguration(initializers = {TestContextInitializer.class}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { ManagedIdentityWalletsApplication.class }) +@ContextConfiguration(initializers = { TestContextInitializer.class }) class IssuersCredentialTest { @Autowired @@ -152,7 +160,7 @@ void getCredentials200() throws com.fasterxml.jackson.core.JsonProcessingExcepti } } - @Test + @Test @DisplayName("Get Credentials as JWT") void getCredentialsAsJWT200() throws com.fasterxml.jackson.core.JsonProcessingException, JSONException { String baseBPN = miwSettings.authorityWalletBpn(); @@ -184,9 +192,9 @@ void getCredentialsAsJWT200() throws com.fasterxml.jackson.core.JsonProcessingEx , HttpMethod.GET, entity, String.class, holderDID); Assertions.assertEquals(HttpStatus.OK.value(), response.getStatusCode().value()); - Map responseMap = SerializeUtil.fromJson(response.getBody()); - List> vcsAsJwt = (ArrayList>) responseMap.get("content"); - //5 framework CV + 1 membership + 6 Summary VC + Map responseMap = SerializeUtil.fromJson(response.getBody()); + List> vcsAsJwt = (ArrayList>) responseMap.get("content"); + //5 framework CV + 1 membership + 6 Summary VC Assertions.assertEquals(12, vcsAsJwt.size()); vcsAsJwt.forEach(vc -> { Assertions.assertNotNull(vc.get(StringPool.VC_JWT_KEY)); diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/MembershipHoldersCredentialTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/MembershipHoldersCredentialTest.java index e640c8116..8af4d419c 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/MembershipHoldersCredentialTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/MembershipHoldersCredentialTest.java @@ -48,7 +48,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.ContextConfiguration; import java.util.List; @@ -57,8 +61,8 @@ import static org.eclipse.tractusx.managedidentitywallets.constant.StringPool.COLON_SEPARATOR; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = {ManagedIdentityWalletsApplication.class}) -@ContextConfiguration(initializers = {TestContextInitializer.class}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { ManagedIdentityWalletsApplication.class }) +@ContextConfiguration(initializers = { TestContextInitializer.class }) class MembershipHoldersCredentialTest { @Autowired private HoldersCredentialRepository holdersCredentialRepository; diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/PresentationValidationTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/PresentationValidationTest.java index 894519321..3ba4bf6fc 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/PresentationValidationTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/PresentationValidationTest.java @@ -72,7 +72,7 @@ import static org.eclipse.tractusx.managedidentitywallets.constant.StringPool.COLON_SEPARATOR; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { ManagedIdentityWalletsApplication.class }) -@ContextConfiguration(initializers = {TestContextInitializer.class}) +@ContextConfiguration(initializers = { TestContextInitializer.class }) class PresentationValidationTest { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java index d201cefc2..ea8578d2d 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java @@ -25,9 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.SignedJWT; - import lombok.SneakyThrows; - import org.eclipse.tractusx.managedidentitywallets.ManagedIdentityWalletsApplication; import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings; import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer; @@ -58,19 +56,28 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.security.oauth2.jwt.JwtException; import org.springframework.test.context.ContextConfiguration; import java.net.URI; import java.text.ParseException; import java.time.Instant; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; import static org.eclipse.tractusx.managedidentitywallets.constant.StringPool.COLON_SEPARATOR; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = {ManagedIdentityWalletsApplication.class}) -@ContextConfiguration(initializers = {TestContextInitializer.class}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { ManagedIdentityWalletsApplication.class }) +@ContextConfiguration(initializers = { TestContextInitializer.class }) class PresentationTest { @Autowired diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java index 92062d791..3413af26b 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java @@ -68,8 +68,8 @@ import static org.eclipse.tractusx.managedidentitywallets.constant.StringPool.COLON_SEPARATOR; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = {ManagedIdentityWalletsApplication.class}) -@ContextConfiguration(initializers = {TestContextInitializer.class}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { ManagedIdentityWalletsApplication.class }) +@ContextConfiguration(initializers = { TestContextInitializer.class }) class WalletTest { @Autowired