use of com.quorum.tessera.config.KeyVaultConfig in project tessera by ConsenSys.
the class HashicorpKeyVaultServiceFactoryUtilTest method configureClientAuthenticationIfOnlySecretIdSetThenException.
@Test
public void configureClientAuthenticationIfOnlySecretIdSetThenException() {
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(null);
when(envProvider.getEnv(HASHICORP_SECRET_ID)).thenReturn("secret-id");
when(envProvider.getEnv(HASHICORP_TOKEN)).thenReturn(null);
Throwable ex = catchThrowable(() -> util.configureClientAuthentication(keyVaultConfig, envProvider, clientHttpRequestFactory, vaultEndpoint));
assertThat(ex).isExactlyInstanceOf(HashicorpCredentialNotSetException.class);
assertThat(ex.getMessage()).isEqualTo("Both " + HASHICORP_ROLE_ID + " and " + HASHICORP_SECRET_ID + " environment variables must be set to use the AppRole authentication method");
}
use of com.quorum.tessera.config.KeyVaultConfig in project tessera by ConsenSys.
the class HashicorpKeyVaultServiceFactoryUtilTest method configureClientAuthenticationIfOnlyTokenSetThenTokenMethod.
@Test
public void configureClientAuthenticationIfOnlyTokenSetThenTokenMethod() {
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(null);
when(envProvider.getEnv(HASHICORP_SECRET_ID)).thenReturn(null);
when(envProvider.getEnv(HASHICORP_TOKEN)).thenReturn("token");
ClientAuthentication result = util.configureClientAuthentication(keyVaultConfig, envProvider, clientHttpRequestFactory, vaultEndpoint);
assertThat(result).isInstanceOf(TokenAuthentication.class);
}
use of com.quorum.tessera.config.KeyVaultConfig 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.KeyVaultConfig 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.KeyVaultConfig 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