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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations