Skip to content

Commit

Permalink
fix: failing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-vavdiya committed Sep 5, 2024
1 parent 02ccd31 commit e91b6a0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
import java.net.URI;

@ConfigurationProperties(prefix = "miw.revocation")
public record RevocationSettings(URI url) {
public record RevocationSettings(URI url, URI bitStringStatusListContext) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.tractusx.managedidentitywallets.commons.exception.ForbiddenException;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.Validate;
import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings;
import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.IssuersCredential;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet;
Expand Down Expand Up @@ -77,6 +78,7 @@
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.text.ParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -115,6 +117,8 @@ public class IssuersCredentialService extends BaseService<IssuersCredential, Lon

private final RevocationService revocationService;

private final RevocationSettings revocationSettings;


@Override
protected BaseRepository<IssuersCredential, Long> getRepository() {
Expand Down Expand Up @@ -239,6 +243,14 @@ public CredentialsResponse issueCredentialUsingBaseWallet(String holderDid, Map<
//get credential status in case of revocation
VerifiableCredentialStatusList2021Entry statusListEntry = revocationService.getStatusListEntry(issuerWallet.getBpn(), token);
builder.verifiableCredentialStatus(statusListEntry);

//add revocation context if missing
List<URI> uris = miwSettings.vcContexts();
if (!uris.contains(revocationSettings.bitStringStatusListContext())) {
uris.add(revocationSettings.bitStringStatusListContext());
builder.contexts(uris);
}

}

CredentialCreationConfig holdersCredentialCreationConfig = builder.build();
Expand Down
1 change: 1 addition & 0 deletions miw/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ miw:
refresh-token-url: ${miw.security.token-url}
revocation:
url: ${REVOCATION_SERVICE_URL:http://localhost:8081}
bitStringStatusListContext: ${BITSTRING_STATUS_LIST_CONTEXT_URL:https://w3c.github.io/vc-bitstring-status-list/contexts/v1.jsonld}


sts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static void beforeAll() throws SQLException {
issuersCredentialRepository,
miwSettings,
new SpecificationUtil<IssuersCredential>(),
holdersCredentialRepository, commonService, objectMapper, revocationService);
holdersCredentialRepository, commonService, objectMapper, revocationService, revocationSettings);
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.commons.exception.ForbiddenException;
import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings;
import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet;
import org.eclipse.tractusx.managedidentitywallets.dao.repository.WalletRepository;
Expand Down Expand Up @@ -129,14 +130,14 @@ public static Wallet createWallet(String bpn, String did, WalletRepository walle
return walletRepository.save(wallet);
}

public static void checkVC(VerifiableCredential verifiableCredential, MIWSettings miwSettings) {
//text context URL
Assertions.assertEquals(verifiableCredential.getContext().size(), miwSettings.vcContexts().size() + 1);

public static void checkVC(VerifiableCredential verifiableCredential, MIWSettings miwSettings, RevocationSettings revocationSettings) {
for (URI link : miwSettings.vcContexts()) {
Assertions.assertTrue(verifiableCredential.getContext().contains(link));
}

if (verifiableCredential.getVerifiableCredentialStatus() != null) {
Assertions.assertTrue(verifiableCredential.getContext().contains(revocationSettings.bitStringStatusListContext()));
}
//check expiry date
Assertions.assertEquals(0, verifiableCredential.getExpirationDate().compareTo(miwSettings.vcExpiryDate().toInstant()));
}
Expand Down Expand Up @@ -261,7 +262,6 @@ public static Map<String, Object> getCredentialAsMap(String holderBpn, String ho
//VC Subject
VerifiableCredentialSubject verifiableCredentialSubject =
new VerifiableCredentialSubject(subjectData);

//Using Builder
VerifiableCredential credentialWithoutProof =
verifiableCredentialBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.tractusx.managedidentitywallets.commons.constant.CredentialStatus;
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings;
import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings;
import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.controller.IssuersCredentialController;
Expand Down Expand Up @@ -101,6 +102,9 @@ class HoldersCredentialTest {
@Autowired
private TestRestTemplate restTemplate;

@Autowired
private RevocationSettings revocationSettings;

@MockInBean(RevocationService.class)
private RevocationClient revocationClient;

Expand Down Expand Up @@ -149,7 +153,7 @@ void issueCredentialTest200() throws JsonProcessingException {

List<HoldersCredential> credentials = holdersCredentialRepository.getByHolderDidAndType(did, type);
Assertions.assertFalse(credentials.isEmpty());
TestUtils.checkVC(credentials.get(0).getData(), miwSettings);
TestUtils.checkVC(credentials.get(0).getData(), miwSettings, revocationSettings);
Assertions.assertTrue(credentials.get(0).isSelfIssued());
Assertions.assertFalse(credentials.get(0).isStored());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.commons.exception.ForbiddenException;
import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings;
import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings;
import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential;
Expand Down Expand Up @@ -89,6 +90,9 @@ class IssuersCredentialTest {
@Autowired
private IssuersCredentialRepository issuersCredentialRepository;

@Autowired
private RevocationSettings revocationSettings;


@MockInBean(RevocationService.class)
private RevocationClient revocationClient;
Expand Down Expand Up @@ -259,7 +263,7 @@ void issueCredentials200() throws com.fasterxml.jackson.core.JsonProcessingExcep

List<HoldersCredential> credentials = holdersCredentialRepository.getByHolderDidAndType(did, type);
Assertions.assertFalse(credentials.isEmpty());
TestUtils.checkVC(credentials.get(0).getData(), miwSettings);
TestUtils.checkVC(credentials.get(0).getData(), miwSettings, revocationSettings);
Assertions.assertFalse(credentials.get(0).isStored()); //stored must be false
Assertions.assertFalse(credentials.get(0).isSelfIssued()); //stored must be false

Expand Down

0 comments on commit e91b6a0

Please sign in to comment.