use of com.quorum.tessera.config.util.EnvironmentVariableProvider in project tessera by ConsenSys.
the class HashicorpKeyVaultServiceFactoryUtilTest method configureClientAuthenticationIfOnlyRoleIdAndSecretIdSetThenAppRoleMethod.
@Test
public void configureClientAuthenticationIfOnlyRoleIdAndSecretIdSetThenAppRoleMethod() {
KeyVaultConfig keyVaultConfig = mock(KeyVaultConfig.class);
EnvironmentVariableProvider envProvider = mock(EnvironmentVariableProvider.class);
ClientHttpRequestFactory clientHttpRequestFactory = mock(ClientHttpRequestFactory.class);
VaultEndpoint vaultEndpoint = mock(VaultEndpoint.class);
when(envProvider.getEnv(HASHICORP_ROLE_ID)).thenReturn("role-id");
when(envProvider.getEnv(HASHICORP_SECRET_ID)).thenReturn("secret-id");
when(envProvider.getEnv(HASHICORP_TOKEN)).thenReturn(null);
when(keyVaultConfig.getProperty("approlePath")).thenReturn(Optional.of("somepath"));
ClientAuthentication result = util.configureClientAuthentication(keyVaultConfig, envProvider, clientHttpRequestFactory, vaultEndpoint);
assertThat(result).isInstanceOf(AppRoleAuthentication.class);
}
use of com.quorum.tessera.config.util.EnvironmentVariableProvider in project tessera by ConsenSys.
the class HashicorpKeyVaultServiceFactoryUtilTest method configureSslUsesNoKeyStoresIfNoneProvided.
@Test
public void configureSslUsesNoKeyStoresIfNoneProvided() {
KeyVaultConfig keyVaultConfig = mock(KeyVaultConfig.class);
EnvironmentVariableProvider envProvider = mock(EnvironmentVariableProvider.class);
when(keyVaultConfig.getProperty("tlsKeyStorePath")).thenReturn(Optional.empty());
when(keyVaultConfig.getProperty("tlsTrustStorePath")).thenReturn(Optional.empty());
SslConfiguration result = util.configureSsl(keyVaultConfig, envProvider);
assertThat(result.getKeyStoreConfiguration().isPresent()).isFalse();
assertThat(result.getTrustStoreConfiguration().isPresent()).isFalse();
}
use of com.quorum.tessera.config.util.EnvironmentVariableProvider 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);
}
use of com.quorum.tessera.config.util.EnvironmentVariableProvider in project tessera by ConsenSys.
the class KeyGeneratorFactoryTest method fileKeyGeneratorWhenKeyVaultConfigNotProvided.
@Test
public void fileKeyGeneratorWhenKeyVaultConfigNotProvided() {
final EnvironmentVariableProvider envProvider = mock(EnvironmentVariableProvider.class);
EncryptorConfig encryptorConfig = mock(EncryptorConfig.class);
when(encryptorConfig.getType()).thenReturn(EncryptorType.EC);
when(encryptorConfig.getProperties()).thenReturn(Collections.EMPTY_MAP);
final KeyGenerator keyGenerator = KeyGeneratorFactory.create().create(null, encryptorConfig);
when(envProvider.getEnv(anyString())).thenReturn("env");
assertThat(keyGenerator).isNotNull();
assertThat(keyGenerator).isExactlyInstanceOf(FileKeyGenerator.class);
}
Aggregations