Skip to content

Commit

Permalink
fix: part of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasalfiti authored and nitin-vavdiya committed May 14, 2024
1 parent ef961a5 commit 7f01263
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -207,7 +209,8 @@ void getCredentials200() throws com.fasterxml.jackson.core.JsonProcessingExcepti
@Test
void validateCredentialsWithInvalidVC() throws com.fasterxml.jackson.core.JsonProcessingException {
//data setup
Map<String, Object> map = issueVC();
CredentialVerificationRequest request = new CredentialVerificationRequest();
request.setVc(issueVC());

//service call
try (MockedStatic<LinkedDataProofValidation> utils = Mockito.mockStatic(LinkedDataProofValidation.class)) {
Expand All @@ -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<String, Object> stringObjectMap = credentialController.credentialsValidation(map, false).getBody();
Map<String, Object> stringObjectMap = credentialController.credentialsValidation(request, false).getBody();
Assertions.assertFalse(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString()));
}
}
Expand All @@ -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<String, Object> map = issueVC();
CredentialVerificationRequest request = new CredentialVerificationRequest();
request.setVc(issueVC());

//service call
try (MockedStatic<LinkedDataProofValidation> utils = Mockito.mockStatic(LinkedDataProofValidation.class)) {
Expand All @@ -242,7 +244,7 @@ void validateCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackson.core.
}).thenReturn(mock);
Mockito.when(mock.verify(Mockito.any(VerifiableCredential.class))).thenReturn(true);

Map<String, Object> stringObjectMap = credentialController.credentialsValidation(map, true).getBody();
Map<String, Object> 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()));
}
Expand All @@ -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<String, Object> map = issueVC();
//modify expiry date
Instant instant = Instant.now().minusSeconds(60);
map.put("expirationDate", instant.toString());
request.put("expirationDate", instant.toString());


//service call
Expand All @@ -269,7 +271,7 @@ void validateCredentialsWithExpiryCheckFalse() throws com.fasterxml.jackson.core
}).thenReturn(mock);
Mockito.when(mock.verify(Mockito.any(VerifiableCredential.class))).thenReturn(true);

Map<String, Object> stringObjectMap = credentialController.credentialsValidation(map, false).getBody();
Map<String, Object> stringObjectMap = credentialController.credentialsValidation(request, false).getBody();
Assertions.assertTrue(Boolean.parseBoolean(stringObjectMap.get(StringPool.VALID).toString()));
}
}
Expand All @@ -280,10 +282,12 @@ void validateCredentialsWithExpiryCheckFalse() throws com.fasterxml.jackson.core
void validateExpiredCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackson.core.JsonProcessingException {

//data setup
Map<String, Object> 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<LinkedDataProofValidation> utils = Mockito.mockStatic(LinkedDataProofValidation.class)) {
Expand All @@ -295,7 +299,7 @@ void validateExpiredCredentialsWithExpiryCheckTrue() throws com.fasterxml.jackso
}).thenReturn(mock);
Mockito.when(mock.verify(Mockito.any(VerifiableCredential.class))).thenReturn(true);

Map<String, Object> stringObjectMap = credentialController.credentialsValidation(map, true).getBody();
Map<String, Object> 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()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 7f01263

Please sign in to comment.