use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class KeyPairConverterTest method convertMultipleKeyPairs.
@Test
public void convertMultipleKeyPairs() {
final String pubA = "publicA";
final String privA = "privateA";
final String pubB = "publicB";
final String privB = "privateB";
final DirectKeyPair keyPairA = new DirectKeyPair(pubA, privA);
final DirectKeyPair keyPairB = new DirectKeyPair(pubB, privB);
final Collection<KeyPair> result = converter.convert(Arrays.asList(keyPairA, keyPairB));
assertThat(result).hasSize(2);
final KeyPair expectedA = new KeyPair(PublicKey.from(decodeBase64(pubA)), PrivateKey.from(decodeBase64(privA)));
final KeyPair expectedB = new KeyPair(PublicKey.from(decodeBase64(pubB)), PrivateKey.from(decodeBase64(privB)));
final Iterator<KeyPair> it = result.iterator();
final KeyPair resultA = it.next();
assertThat(resultA).isEqualToComparingFieldByField(expectedA);
final KeyPair resultB = it.next();
assertThat(resultB).isEqualToComparingFieldByField(expectedB);
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class KeyPairConverterTest method convertSingleAzureVaultKeyPair.
@Test
public void convertSingleAzureVaultKeyPair() {
try (var staticKeyVaultServiceFactory = mockStatic(KeyVaultServiceFactory.class)) {
KeyVaultServiceFactory keyVaultServiceFactory = mock(KeyVaultServiceFactory.class);
KeyVaultService keyVaultService = mock(KeyVaultService.class);
when(keyVaultService.getSecret(any(Map.class))).thenReturn("publicSecret").thenReturn("privSecret");
when(keyVaultServiceFactory.create(any(Config.class), any(EnvironmentVariableProvider.class))).thenReturn(keyVaultService);
staticKeyVaultServiceFactory.when(() -> KeyVaultServiceFactory.getInstance(KeyVaultType.AZURE)).thenReturn(keyVaultServiceFactory);
final AzureVaultKeyPair keyPair = new AzureVaultKeyPair("pub", "priv", null, null);
Collection<KeyPair> result = converter.convert(List.of(keyPair));
assertThat(result).hasSize(1);
KeyPair resultKeyPair = result.iterator().next();
KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("publicSecret")), PrivateKey.from(decodeBase64("privSecret")));
assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
verify(keyVaultService, times(2)).getSecret(any(Map.class));
verify(keyVaultServiceFactory).create(any(Config.class), any(EnvironmentVariableProvider.class));
staticKeyVaultServiceFactory.verify(() -> KeyVaultServiceFactory.getInstance(KeyVaultType.AZURE));
staticKeyVaultServiceFactory.verifyNoMoreInteractions();
verifyNoMoreInteractions(keyVaultService);
verifyNoMoreInteractions(keyVaultServiceFactory);
}
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class KeyPairConverterTest method convertSingleFilesystemKeyPair.
@Test
public void convertSingleFilesystemKeyPair() {
final FilesystemKeyPair keyPair = mock(FilesystemKeyPair.class);
when(keyPair.getPublicKey()).thenReturn("public");
when(keyPair.getPrivateKey()).thenReturn("private");
Collection<KeyPair> result = converter.convert(Collections.singletonList(keyPair));
assertThat(result).hasSize(1);
KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("public")), PrivateKey.from(decodeBase64("private")));
KeyPair resultKeyPair = result.iterator().next();
assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class KeyPairConverterTest method convertSingleDirectKeyPair.
@Test
public void convertSingleDirectKeyPair() {
final DirectKeyPair keyPair = new DirectKeyPair("public", "private");
Collection<KeyPair> result = converter.convert(Collections.singletonList(keyPair));
assertThat(result).hasSize(1);
KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("public")), PrivateKey.from(decodeBase64("private")));
KeyPair resultKeyPair = result.iterator().next();
assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class KeyPairConverterTest method convertSingleInlineKeyPair.
@Test
public void convertSingleInlineKeyPair() {
final InlineKeypair keyPair = mock(InlineKeypair.class);
when(keyPair.getPublicKey()).thenReturn("public");
when(keyPair.getPrivateKey()).thenReturn("private");
Collection<KeyPair> result = converter.convert(Collections.singletonList(keyPair));
assertThat(result).hasSize(1);
KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("public")), PrivateKey.from(decodeBase64("private")));
KeyPair resultKeyPair = result.iterator().next();
assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
}
Aggregations