use of com.quorum.tessera.key.vault.KeyVaultServiceFactory in project tessera by ConsenSys.
the class DefaultKeyGeneratorFactoryTest method createKeyGeneratorsFromTypes.
@Test
public void createKeyGeneratorsFromTypes() throws Exception {
for (KeyVaultType keyVaultType : KeyVaultType.values()) {
DefaultKeyVaultConfig keyVaultConfig = mock(DefaultKeyVaultConfig.class);
when(keyVaultConfig.getKeyVaultType()).thenReturn(keyVaultType);
EncryptorConfig encryptorConfig = mock(EncryptorConfig.class);
when(encryptorConfig.getType()).thenReturn(EncryptorType.NACL);
DefaultKeyGeneratorFactory defaultKeyGeneratorFactory = new DefaultKeyGeneratorFactory();
try (MockedStatic<KeyVaultServiceFactory> mockedKeyVaultServiceFactory = mockStatic(KeyVaultServiceFactory.class)) {
KeyVaultServiceFactory keyVaultServiceFactory = mock(KeyVaultServiceFactory.class);
when(keyVaultServiceFactory.create(any(), any())).thenReturn(mock(KeyVaultService.class));
mockedKeyVaultServiceFactory.when(() -> KeyVaultServiceFactory.getInstance(keyVaultType)).thenReturn(keyVaultServiceFactory);
final KeyGenerator keyGenerator = defaultKeyGeneratorFactory.create(keyVaultConfig, encryptorConfig);
assertThat(keyGenerator).isNotNull();
assertThat(keyGenerator).isExactlyInstanceOf(resultsLookup.get(keyVaultType));
}
}
}
use of com.quorum.tessera.key.vault.KeyVaultServiceFactory in project tessera by ConsenSys.
the class DefaultKeyGeneratorFactoryTest method awsRequiresThatKeyConfigIsOfTypeDefaultKeyVaultConfig.
@Test
public void awsRequiresThatKeyConfigIsOfTypeDefaultKeyVaultConfig() {
KeyVaultConfig keyVaultConfig = mock(KeyVaultConfig.class);
when(keyVaultConfig.getKeyVaultType()).thenReturn(KeyVaultType.AWS);
EncryptorConfig encryptorConfig = mock(EncryptorConfig.class);
when(encryptorConfig.getType()).thenReturn(EncryptorType.NACL);
DefaultKeyGeneratorFactory defaultKeyGeneratorFactory = new DefaultKeyGeneratorFactory();
try (MockedStatic<KeyVaultServiceFactory> mockedKeyVaultServiceFactory = mockStatic(KeyVaultServiceFactory.class)) {
KeyVaultServiceFactory keyVaultServiceFactory = mock(KeyVaultServiceFactory.class);
mockedKeyVaultServiceFactory.when(() -> KeyVaultServiceFactory.getInstance(KeyVaultType.AWS)).thenReturn(keyVaultServiceFactory);
try {
defaultKeyGeneratorFactory.create(keyVaultConfig, encryptorConfig);
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException ex) {
assertThat(ex).hasMessage("AWS key vault config not instance of DefaultKeyVaultConfig");
}
}
}
use of com.quorum.tessera.key.vault.KeyVaultServiceFactory 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);
}
}
Aggregations