fix(appconfig): resolve AppConfigData identifiers by name as well as ID (#4661)

* fix(appconfig): resolve AppConfigData identifiers by name as well as ID

StartConfigurationSession looked the application, environment and profile
up by ID only. AWS accepts either, and the AppConfig agent and Lambda
extension are normally given names, so they got ResourceNotFoundException
against Floci. Resolve each identifier by ID first, then by name.

* fix(appconfig): prefer an exact ID over a name and skip nameless resources

Resolve each AppConfigData identifier with a direct ID lookup first (kept
within the parent application), so an ID is never shadowed by another
resource's name and legacy unprefixed keys stay reachable; only a miss
scans by name, and the name match is null-safe.

* fix(appconfig): answer a missing session identifier with ResourceNotFoundException

An omitted or null Application, Environment or ConfigurationProfile
identifier reached the name fallback and threw a NullPointerException.
It now returns ResourceNotFoundException, as the direct lookups did.

* style(appconfig): brace the null-identifier guards

* fix(appconfig): reject a missing session identifier with BadRequestException
This commit is contained in:
Goooooooooody authored and GitHub committed 2026-09-29 16:49:27 -04:00
1 parent e6d22e8bcf
commit 90c55114f9
3 files changed
+153 -3

No files matched your search

@@ -831,4 +831,114 @@ class AppConfigIntegrationTest {
.body("disabled.enabled", equalTo(false))
.body("disabled.secret", nullValue());
}
@Test @Order(44)
void startConfigurationSessionAcceptsResourceNames() {
String token = given()
.contentType(ContentType.JSON)
.body("{\"ApplicationIdentifier\": \"test-app\", \"EnvironmentIdentifier\": \"test-env\", "
+ "\"ConfigurationProfileIdentifier\": \"test-profile\"}")
.when().post("/configurationsessions")
.then()
.statusCode(201)
.extract().path("InitialConfigurationToken");
given()
.queryParam("configuration_token", token)
.when().get("/configuration")
.then()
.statusCode(200)
.body("foo", notNullValue());
}
@Test @Order(45)
void startConfigurationSessionRejectsUnknownEnvironmentName() {
given()
.contentType(ContentType.JSON)
.body("{\"ApplicationIdentifier\": \"test-app\", \"EnvironmentIdentifier\": \"no-such-env\", "
+ "\"ConfigurationProfileIdentifier\": \"test-profile\"}")
.when().post("/configurationsessions")
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test @Order(46)
void startConfigurationSessionPrefersIdOverAnotherResourcesName() {
// A second environment and profile named after the first ones' IDs: the ID must still select the original.
given()
.contentType(ContentType.JSON)
.body("{\"Name\": \"" + envId + "\"}")
.when().post("/applications/" + appId + "/environments")
.then().statusCode(201);
given()
.contentType(ContentType.JSON)
.body("{\"Name\": \"" + profileId + "\", \"LocationUri\": \"hosted\", \"Type\": \"AWS.Freeform\"}")
.when().post("/applications/" + appId + "/configurationprofiles")
.then().statusCode(201);
String token = given()
.contentType(ContentType.JSON)
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId
+ "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\"}")
.when().post("/configurationsessions")
.then().statusCode(201)
.extract().path("InitialConfigurationToken");
given()
.queryParam("configuration_token", token)
.when().get("/configuration")
.then()
.statusCode(200)
.body("foo", notNullValue());
}
@Test @Order(47)
void startConfigurationSessionSkipsResourcesWithoutAName() {
given()
.contentType(ContentType.JSON)
.body("{}")
.when().post("/applications/" + appId + "/environments")
.then().statusCode(201);
given()
.contentType(ContentType.JSON)
.body("{\"LocationUri\": \"hosted\", \"Type\": \"AWS.Freeform\"}")
.when().post("/applications/" + appId + "/configurationprofiles")
.then().statusCode(201);
given()
.contentType(ContentType.JSON)
.body("{}")
.when().post("/applications")
.then().statusCode(201);
given()
.contentType(ContentType.JSON)
.body("{\"ApplicationIdentifier\": \"test-app\", \"EnvironmentIdentifier\": \"test-env\", "
+ "\"ConfigurationProfileIdentifier\": \"test-profile\"}")
.when().post("/configurationsessions")
.then().statusCode(201);
given()
.contentType(ContentType.JSON)
.body("{\"ApplicationIdentifier\": \"test-app\", \"EnvironmentIdentifier\": \"no-such-env\", "
+ "\"ConfigurationProfileIdentifier\": \"test-profile\"}")
.when().post("/configurationsessions")
.then().statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test @Order(48)
void startConfigurationSessionWithoutAnIdentifierIsABadRequest() {
for (String missing : new String[] {"ApplicationIdentifier", "EnvironmentIdentifier", "ConfigurationProfileIdentifier"}) {
String body = "{\"ApplicationIdentifier\": \"test-app\", \"EnvironmentIdentifier\": \"test-env\", "
+ "\"ConfigurationProfileIdentifier\": \"test-profile\"}";
body = body.replaceFirst("\"" + missing + "\": \"[^\"]*\"(, )?", "").replaceFirst(", }$", "}");
given()
.contentType(ContentType.JSON)
.body(body)
.when().post("/configurationsessions")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
}
}