Skip to content

Azure Vault Config Provider: reject empty secret name #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ static void parseVaultSecretUri(

String path = urlBuilder.getPath();

if (!path.contains("/secrets"))
if (!path.contains("/secrets/"))
throw new IllegalArgumentException("The Vault Secret URI should " +
"contain \"/secrets\" following by the name of the Secret: " +
"contain \"/secrets\" followed by the name of the Secret: " +
vaultSecretUri);

String secretName = path.replace("/secrets", "");
String secretName = path.replace("/secrets/", "");
if (secretName.trim().isEmpty()){
throw new IllegalArgumentException("Missing secret name in Vault URI: " + vaultSecretUri);
}
builder.add("value", KeyVaultSecretFactory.SECRET_NAME, secretName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ public void test() {
)));
}

/**
* Verifies that calling getSecret(...) with an empty secret name
* is rejected by throwing an IllegalArgumentException whose message
* indicates a missing secret name.
*/
@Test
public void testEmptySecretNameThrows() {
IllegalArgumentException ex = Assertions.assertThrows(
IllegalArgumentException.class,
() -> PROVIDER.getSecret(
constructSecretProperties(
TestProperties.getOrAbort(AzureTestProperty.AZURE_KEY_VAULT_URL),
"", // <— empty secret path
TestProperties.getOrAbort(AzureTestProperty.AZURE_CLIENT_ID),
TestProperties.getOrAbort(AzureTestProperty.AZURE_CLIENT_SECRET),
TestProperties.getOrAbort(AzureTestProperty.AZURE_TENANT_ID)
)
),
"Expected getSecret(...) to throw when secret name is empty"
);
Assertions.assertTrue(
ex.getMessage().toLowerCase().contains("missing secret name"),
"Exception message should mention 'secret name', but was: " + ex.getMessage()
);
}

private Map<String,String> constructSecretProperties(
String vaultUrl, String secretName, String clientId, String clientSecret, String tenantId) {
Map<String,String> secretProperties = new HashMap<>();
Expand Down