Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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