@Test public void getSecretThrowsExceptionIfKeyNotFoundInVault() { when(azureKeyVaultClientDelegate.getSecret(anyString(), anyString())).thenReturn(null); AzureKeyVaultService azureKeyVaultService = new AzureKeyVaultService(keyVaultConfig, azureKeyVaultClientDelegate); String secretName = "secret"; AzureGetSecretData getSecretData = mock(AzureGetSecretData.class); when(getSecretData.getSecretName()).thenReturn(secretName); Throwable throwable = catchThrowable(() -> azureKeyVaultService.getSecret(getSecretData)); assertThat(throwable).isInstanceOf(VaultSecretNotFoundException.class); assertThat(throwable).hasMessageContaining("Azure Key Vault secret " + secretName + " was not found in vault " + vaultUrl); }
@Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } AzureKeyVaultService(KeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate);   AzureKeyVaultService(String vaultUrl, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate); }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } AzureKeyVaultService(KeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate);   AzureKeyVaultService(String vaultUrl, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate); @Override String getSecret(AzureGetSecretData azureGetSecretData); @Override Object setSecret(AzureSetSecretData azureSetSecretData); }
AzureKeyVaultService implements KeyVaultService<AzureSetSecretData, AzureGetSecretData> { @Override public String getSecret(AzureGetSecretData azureGetSecretData) { SecretBundle secretBundle; if (azureGetSecretData.getSecretVersion() != null) { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName(), azureGetSecretData.getSecretVersion()); } else { secretBundle = azureKeyVaultClientDelegate.getSecret(vaultUrl, azureGetSecretData.getSecretName()); } if (secretBundle == null) { throw new VaultSecretNotFoundException("Azure Key Vault secret " + azureGetSecretData.getSecretName() + " was not found in vault " + vaultUrl); } return secretBundle.value(); } AzureKeyVaultService(KeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate);   AzureKeyVaultService(String vaultUrl, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate); @Override String getSecret(AzureGetSecretData azureGetSecretData); @Override Object setSecret(AzureSetSecretData azureSetSecretData);  }