Skip to content

Commit

Permalink
fix: test for jwt
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 531d3f7 commit 8b5180a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential;
import org.eclipse.tractusx.managedidentitywallets.dto.SecureTokenRequest;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.WalletKey;
import org.eclipse.tractusx.managedidentitywallets.exception.BadDataException;
import org.eclipse.tractusx.managedidentitywallets.service.WalletKeyService;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;
Expand Down Expand Up @@ -64,7 +63,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -158,8 +156,8 @@ private static VerifiableCredential createVerifiableCredential(DidDocument issue
LinkedDataProofGenerator generator = LinkedDataProofGenerator.newInstance(SignatureType.JWS);
URI verificationMethod = issuerDoc.getVerificationMethods().get(0).getId();

JWSSignature2020 proof = (JWSSignature2020) generator.createProof(builder.build(), verificationMethod,
new x25519PrivateKey(privateKey));
JWSSignature2020 proof = new JWSSignature2020(generator.createProof(builder.build(), verificationMethod,
new x25519PrivateKey(privateKey)));

// Adding Proof to VC
builder.proof(proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ void shouldIssueCredentialAsJwt()
WalletKey walletKey = mock(WalletKey.class);
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())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);

when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
.asByte());
CredentialsResponse credentialsResponse = assertDoesNotThrow(
() -> issuersCredentialService.issueMembershipCredential(
issueMembershipCredentialRequest,
Expand Down Expand Up @@ -225,7 +226,9 @@ void shouldIssueCredentialAsJwt()
WalletKey walletKey = mock(WalletKey.class);
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()
.asByte());
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);
Expand Down Expand Up @@ -264,9 +267,11 @@ void shouldIssueCredentialAsJwt() throws IOException, InvalidPrivateKeyFormatExc
WalletKey walletKey = mock(WalletKey.class);
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())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
.asByte());
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);

CredentialsResponse credentialsResponse = assertDoesNotThrow(
Expand All @@ -286,7 +291,6 @@ void shouldIssueCredentialAsJwt() throws IOException, ParseException, InvalidPri
Map<String, Object> wallets = mockBaseAndHolderWallet();
Wallet baseWallet = (Wallet) wallets.get("base");
String baseWalletBpn = baseWallet.getBpn();
String baseWalletDid = baseWallet.getDid();
Wallet holderWallet = (Wallet) wallets.get("holder");
String holderWalletBpn = holderWallet.getBpn();
String walletKeyId = "key-1";
Expand All @@ -299,7 +303,7 @@ void shouldIssueCredentialAsJwt() throws IOException, ParseException, InvalidPri
MockUtil.generateDid("basewallet")).build();

MockUtil.makeCreateWorkForIssuer(issuersCredentialRepository);
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(any(Long.class) , SupportedAlgorithms.ED25519.toString())).thenReturn(keyPair.getPrivateKey()
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
.asByte());
when(commonService.getWalletByIdentifier(holderWalletBpn)).thenReturn(holderWallet);
when(commonService.getWalletByIdentifier(verifiableCredential.getIssuer()
Expand All @@ -317,6 +321,7 @@ public HoldersCredential answer(InvocationOnMock invocation) throws Throwable {

WalletKey walletKey = mock(WalletKey.class);
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())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
Expand Down

0 comments on commit 8b5180a

Please sign in to comment.