From 7f012635c338cb517231a87c8b91af563a035964 Mon Sep 17 00:00:00 2001 From: Mustafa Alsalfiti Date: Tue, 5 Mar 2024 14:36:44 +0100 Subject: [PATCH] fix: part of tests --- .../vc/HoldersCredentialTest.java | 32 +++++++++++-------- .../vp/PresentationTest.java | 7 +++- 2 files changed, 24 insertions(+), 15 deletions(-) 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 7dab61e06..9cf5f37e5 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java @@ -34,6 +34,7 @@ import org.eclipse.tractusx.managedidentitywallets.dao.repository.HoldersCredentialRepository; import org.eclipse.tractusx.managedidentitywallets.dao.repository.WalletRepository; import org.eclipse.tractusx.managedidentitywallets.dto.CreateWalletRequest; +import org.eclipse.tractusx.managedidentitywallets.dto.CredentialVerificationRequest; import org.eclipse.tractusx.managedidentitywallets.dto.IssueFrameworkCredentialRequest; import org.eclipse.tractusx.managedidentitywallets.utils.AuthenticationUtils; import org.eclipse.tractusx.managedidentitywallets.utils.TestUtils; @@ -45,6 +46,7 @@ import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialType; import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofValidation; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -134,7 +136,7 @@ void getCredentialsTest403() { } @Test - void getCredentials200() throws com.fasterxml.jackson.core.JsonProcessingException { + void getCredentials200() throws com.fasterxml.jackson.core.JsonProcessingException, JSONException { String baseDID = miwSettings.authorityWalletDid(); @@ -207,7 +209,8 @@ void getCredentials200() throws com.fasterxml.jackson.core.JsonProcessingExcepti @Test void validateCredentialsWithInvalidVC() throws com.fasterxml.jackson.core.JsonProcessingException { //data setup - Map map = issueVC(); + CredentialVerificationRequest request = new CredentialVerificationRequest(); + request.setVc(issueVC()); //service call try (MockedStatic utils = Mockito.mockStatic(LinkedDataProofValidation.class)) { @@ -219,7 +222,7 @@ void validateCredentialsWithInvalidVC() throws com.fasterxml.jackson.core.JsonPr }).thenReturn(mock); Mockito.when(mock.verify(Mockito.any(VerifiableCredential.class))).thenReturn(false); - Map stringObjectMap = credentialController.credentialsValidation(map, false).getBody(); + Map stringObjectMap = credentialController.credentialsValidation(request, false).getBody(); Assertions.assertFalse(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); } } @@ -228,9 +231,8 @@ void validateCredentialsWithInvalidVC() throws com.fasterxml.jackson.core.JsonPr @Test @DisplayName("validate VC with date check true, it should return true") void validateCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackson.core.JsonProcessingException { - - //data setup - Map map = issueVC(); + CredentialVerificationRequest request = new CredentialVerificationRequest(); + request.setVc(issueVC()); //service call try (MockedStatic utils = Mockito.mockStatic(LinkedDataProofValidation.class)) { @@ -242,7 +244,7 @@ void validateCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackson.core. }).thenReturn(mock); Mockito.when(mock.verify(Mockito.any(VerifiableCredential.class))).thenReturn(true); - Map stringObjectMap = credentialController.credentialsValidation(map, true).getBody(); + Map stringObjectMap = credentialController.credentialsValidation(request, true).getBody(); Assertions.assertTrue(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); Assertions.assertTrue(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALIDATE_EXPIRY_DATE).toString())); } @@ -251,12 +253,12 @@ void validateCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackson.core. @Test @DisplayName("validate expired VC with date check false, it should return true") void validateCredentialsWithExpiryCheckFalse() throws com.fasterxml.jackson.core.JsonProcessingException { + CredentialVerificationRequest request = new CredentialVerificationRequest(); + request.setVc(issueVC()); - //data setup - Map map = issueVC(); //modify expiry date Instant instant = Instant.now().minusSeconds(60); - map.put("expirationDate", instant.toString()); + request.put("expirationDate", instant.toString()); //service call @@ -269,7 +271,7 @@ void validateCredentialsWithExpiryCheckFalse() throws com.fasterxml.jackson.core }).thenReturn(mock); Mockito.when(mock.verify(Mockito.any(VerifiableCredential.class))).thenReturn(true); - Map stringObjectMap = credentialController.credentialsValidation(map, false).getBody(); + Map stringObjectMap = credentialController.credentialsValidation(request, false).getBody(); Assertions.assertTrue(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); } } @@ -280,10 +282,12 @@ void validateCredentialsWithExpiryCheckFalse() throws com.fasterxml.jackson.core void validateExpiredCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackson.core.JsonProcessingException { //data setup - Map map = issueVC(); + CredentialVerificationRequest request = new CredentialVerificationRequest(); + request.setVc(issueVC()); + //modify expiry date Instant instant = Instant.now().minusSeconds(60); - map.put("expirationDate", instant.toString()); + request.put("expirationDate", instant.toString()); //service call try (MockedStatic utils = Mockito.mockStatic(LinkedDataProofValidation.class)) { @@ -295,7 +299,7 @@ void validateExpiredCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackso }).thenReturn(mock); Mockito.when(mock.verify(Mockito.any(VerifiableCredential.class))).thenReturn(true); - Map stringObjectMap = credentialController.credentialsValidation(map, true).getBody(); + Map stringObjectMap = credentialController.credentialsValidation(request, true).getBody(); Assertions.assertFalse(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString())); Assertions.assertFalse(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALIDATE_EXPIRY_DATE).toString())); 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 a7768e89a..b809dac81 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java @@ -25,6 +25,9 @@ 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; @@ -55,6 +58,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.*; +import org.springframework.security.oauth2.jwt.JwtException; import org.springframework.test.context.ContextConfiguration; import java.net.URI; @@ -125,7 +129,8 @@ void validateVPAsJwt() throws JsonProcessingException { } @Test - void validateVPAsJwtWithInvalidSignatureAndInValidAudienceAndExpiryDateValidation() throws JsonProcessingException, DidDocumentResolverNotRegisteredException, JwtException, InterruptedException { + @SneakyThrows + void validateVPAsJwtWithInvalidSignatureAndInValidAudienceAndExpiryDateValidation() { //create VP String bpn = TestUtils.getRandomBpmNumber(); String audience = "companyA";