Search in sources :

Example 11 with KeyVaultService

use of com.quorum.tessera.key.vault.KeyVaultService in project tessera by ConsenSys.

the class HashicorpKeyVaultServiceFactoryTest method returnedValueIsCorrectTypeUsing2ArgConstructor.

@Test
public void returnedValueIsCorrectTypeUsing2ArgConstructor() {
    when(envProvider.getEnv(HASHICORP_ROLE_ID)).thenReturn("role-id");
    when(envProvider.getEnv(HASHICORP_SECRET_ID)).thenReturn("secret-id");
    when(envProvider.getEnv(HASHICORP_TOKEN)).thenReturn("token");
    KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    when(config.getKeys()).thenReturn(keyConfiguration);
    DefaultKeyVaultConfig keyVaultConfig = mock(DefaultKeyVaultConfig.class);
    when(keyConfiguration.getKeyVaultConfig(KeyVaultType.HASHICORP)).thenReturn(Optional.of(keyVaultConfig));
    when(keyVaultConfig.getProperty("url")).thenReturn(Optional.of("http://someurl"));
    when(keyVaultConfig.getProperty("approlePath")).thenReturn(Optional.of("approle"));
    setUpUtilMocks(keyVaultConfig);
    KeyVaultService result = keyVaultServiceFactory.create(config, envProvider);
    assertThat(result).isInstanceOf(HashicorpKeyVaultService.class);
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) Test(org.junit.Test)

Example 12 with KeyVaultService

use of com.quorum.tessera.key.vault.KeyVaultService in project tessera by ConsenSys.

the class HashicorpKeyVaultServiceFactoryTest method returnedValueIsCorrectType.

@Test
public void returnedValueIsCorrectType() {
    when(envProvider.getEnv(HASHICORP_ROLE_ID)).thenReturn("role-id");
    when(envProvider.getEnv(HASHICORP_SECRET_ID)).thenReturn("secret-id");
    when(envProvider.getEnv(HASHICORP_TOKEN)).thenReturn("token");
    KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    when(config.getKeys()).thenReturn(keyConfiguration);
    DefaultKeyVaultConfig keyVaultConfig = mock(DefaultKeyVaultConfig.class);
    when(keyConfiguration.getKeyVaultConfig(KeyVaultType.HASHICORP)).thenReturn(Optional.of(keyVaultConfig));
    when(keyVaultConfig.getProperty("url")).thenReturn(Optional.of("http://someurl"));
    when(keyVaultConfig.getProperty("approlePath")).thenReturn(Optional.of("approle"));
    setUpUtilMocks(keyVaultConfig);
    KeyVaultService result = keyVaultServiceFactory.create(config, envProvider, keyVaultServiceFactoryUtil);
    assertThat(result).isInstanceOf(HashicorpKeyVaultService.class);
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) Test(org.junit.Test)

Example 13 with KeyVaultService

use of com.quorum.tessera.key.vault.KeyVaultService in project tessera by ConsenSys.

the class AWSKeyVaultServiceFactoryTest method envVarsAndKeyVaultConfigProvidedCreatesAWSKeyVaultService.

@Test
public void envVarsAndKeyVaultConfigProvidedCreatesAWSKeyVaultService() {
    when(envProvider.getEnv(anyString())).thenReturn("envVar");
    KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    DefaultKeyVaultConfig keyVaultConfig = mock(DefaultKeyVaultConfig.class);
    when(keyVaultConfig.getProperty("endpoint")).thenReturn(Optional.of("http://URL"));
    when(keyConfiguration.getKeyVaultConfig(KeyVaultType.AWS)).thenReturn(Optional.of(keyVaultConfig));
    when(config.getKeys()).thenReturn(keyConfiguration);
    KeyVaultService result = awsKeyVaultServiceFactory.create(config, envProvider);
    assertThat(result).isInstanceOf(AWSKeyVaultService.class);
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) Test(org.junit.Test)

Example 14 with KeyVaultService

use of com.quorum.tessera.key.vault.KeyVaultService in project tessera by ConsenSys.

the class AWSKeyVaultServiceFactoryTest method envVarsAndKeyVaultConfigWithNoEndpointProvidedCreatesAWSKeyVaultService.

@Test
public void envVarsAndKeyVaultConfigWithNoEndpointProvidedCreatesAWSKeyVaultService() {
    when(envProvider.getEnv(anyString())).thenReturn("envVar");
    KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    DefaultKeyVaultConfig keyVaultConfig = mock(DefaultKeyVaultConfig.class);
    when(keyConfiguration.getKeyVaultConfig(KeyVaultType.AWS)).thenReturn(Optional.of(keyVaultConfig));
    when(config.getKeys()).thenReturn(keyConfiguration);
    KeyVaultService result = awsKeyVaultServiceFactory.create(config, envProvider);
    assertThat(result).isInstanceOf(AWSKeyVaultService.class);
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) Test(org.junit.Test)

Example 15 with KeyVaultService

use of com.quorum.tessera.key.vault.KeyVaultService in project tessera by ConsenSys.

the class AzureKeyVaultServiceFactory method create.

@Override
public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) {
    Objects.requireNonNull(config);
    final KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()).flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AZURE)).orElseThrow(() -> new ConfigException(new RuntimeException("Trying to create Azure key vault connection but no Azure configuration provided")));
    final String url = keyVaultConfig.getProperty("url").orElseThrow(() -> new ConfigException(new RuntimeException("No Azure Key Vault url provided")));
    final SecretClient secretClient = new SecretClientBuilder().vaultUrl(url).httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)).credential(new DefaultAzureCredentialBuilder().build()).buildClient();
    return new AzureKeyVaultService(secretClient);
}
Also used : KeyVaultType(com.quorum.tessera.config.KeyVaultType) KeyVaultConfig(com.quorum.tessera.config.KeyVaultConfig) DefaultAzureCredentialBuilder(com.azure.identity.DefaultAzureCredentialBuilder) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions) SecretClientBuilder(com.azure.security.keyvault.secrets.SecretClientBuilder) KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyVaultServiceFactory(com.quorum.tessera.key.vault.KeyVaultServiceFactory) Objects(java.util.Objects) ConfigException(com.quorum.tessera.config.ConfigException) Optional(java.util.Optional) SecretClient(com.azure.security.keyvault.secrets.SecretClient) Config(com.quorum.tessera.config.Config) EnvironmentVariableProvider(com.quorum.tessera.config.util.EnvironmentVariableProvider) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) DefaultAzureCredentialBuilder(com.azure.identity.DefaultAzureCredentialBuilder) SecretClientBuilder(com.azure.security.keyvault.secrets.SecretClientBuilder) KeyVaultConfig(com.quorum.tessera.config.KeyVaultConfig) ConfigException(com.quorum.tessera.config.ConfigException) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions) SecretClient(com.azure.security.keyvault.secrets.SecretClient)

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