Search in sources :

Example 16 with KeyVaultService

use of com.quorum.tessera.key.vault.KeyVaultService 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);
    }
}
Also used : EnvironmentVariableProvider(com.quorum.tessera.config.util.EnvironmentVariableProvider) KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyPair(com.quorum.tessera.encryption.KeyPair) Config(com.quorum.tessera.config.Config) KeyVaultServiceFactory(com.quorum.tessera.key.vault.KeyVaultServiceFactory) Test(org.junit.Test)

Aggregations

KeyVaultService (com.quorum.tessera.key.vault.KeyVaultService)16 Test (org.junit.Test)9 KeyVaultServiceFactory (com.quorum.tessera.key.vault.KeyVaultServiceFactory)8 KeyPair (com.quorum.tessera.encryption.KeyPair)7 EnvironmentVariableProvider (com.quorum.tessera.config.util.EnvironmentVariableProvider)6 Config (com.quorum.tessera.config.Config)4 Encryptor (com.quorum.tessera.encryption.Encryptor)4 Before (org.junit.Before)3 AWSKeyPair (com.quorum.tessera.config.keypairs.AWSKeyPair)2 AzureVaultKeyPair (com.quorum.tessera.config.keypairs.AzureVaultKeyPair)2 HashicorpVaultKeyPair (com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 HttpLogDetailLevel (com.azure.core.http.policy.HttpLogDetailLevel)1 HttpLogOptions (com.azure.core.http.policy.HttpLogOptions)1 DefaultAzureCredentialBuilder (com.azure.identity.DefaultAzureCredentialBuilder)1 SecretClient (com.azure.security.keyvault.secrets.SecretClient)1 SecretClientBuilder (com.azure.security.keyvault.secrets.SecretClientBuilder)1 com.quorum.tessera.config (com.quorum.tessera.config)1 ConfigException (com.quorum.tessera.config.ConfigException)1