Skip to content
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 @@ -326,6 +326,19 @@ private void applyAppDefaults(ObjectNode document, Optional<ContainerAppState> e
if (!configuration.hasNonNull("activeRevisionsMode")) {
configuration.put("activeRevisionsMode", "Single");
}
removeEmptyKeyVaultReferences(configuration);
}

private static void removeEmptyKeyVaultReferences(ObjectNode configuration) {
configuration.path("secrets").forEach(secret -> {
if (secret instanceof ObjectNode object) {
for (String field : List.of("keyVaultUrl", "identity")) {
if (object.path(field).asText().isBlank()) {
object.remove(field);
}
}
}
});
}

private void validateApp(ObjectNode document) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
Expand Down Expand Up @@ -189,6 +191,42 @@ void appCreatePreservesTemplateHidesSecretsAndCreatesScaledRevision() {
.body("value[0].properties.trafficWeight", equalTo(100));
}

@Test
void plainSecretDropsEmptyKeyVaultReference() {
createEnvironment();
given().contentType("application/json")
.body(appBody(ENVIRONMENT_ID, "Single", "v1", 1, 4, 8080)
.replace("[{\"name\": \"api-key\", \"value\": \"secret-value\"}]", """
[{"name": "api-key", "value": "secret-value", "keyVaultUrl": "", "identity": ""},
{"name": "vault-key", "keyVaultUrl": "https://vault.vault.azure.net/secrets/key",
"identity": "System"}]"""))
.put(appUrl("plain-secret-app")).then().statusCode(201);

given().post(appUrl("plain-secret-app", "/listSecrets")).then()
.statusCode(200)
.body("value[0].value", equalTo("secret-value"))
.body("value[0]", not(hasKey("keyVaultUrl")))
.body("value[0]", not(hasKey("identity")))
.body("value[1].keyVaultUrl", equalTo("https://vault.vault.azure.net/secrets/key"))
.body("value[1].identity", equalTo("System"));
given().get(appUrl("plain-secret-app")).then()
.statusCode(200)
.body("properties.configuration.secrets[0]", not(hasKey("keyVaultUrl")))
.body("properties.configuration.secrets[0]", not(hasKey("identity")))
.body("properties.configuration.secrets[1].keyVaultUrl",
equalTo("https://vault.vault.azure.net/secrets/key"));

given().contentType("application/json")
.body("{\"properties\":{\"configuration\":{\"secrets\":"
+ "[{\"name\":\"api-key\",\"value\":\"rotated\",\"keyVaultUrl\":\"\",\"identity\":\"\"}]}}}")
.patch(appUrl("plain-secret-app")).then().statusCode(200);
given().post(appUrl("plain-secret-app", "/listSecrets")).then()
.statusCode(200)
.body("value", hasSize(1))
.body("value[0].value", equalTo("rotated"))
.body("value[0]", not(hasKey("keyVaultUrl")));
}

@Test
void singleAndMultipleRevisionModesFollowAzureSemantics() {
createEnvironment();
Expand Down
Loading