fix(appconfig): return feature flags in retrieval format (#3890)

Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
XuJianandxujiantop-crypto authored and GitHub committed 2026-09-19 07:15:28 -04:00
1 parent 11d04276a3
commit 1370dc02fa
5 files changed
+317 -2

No files matched your search

@@ -0,0 +1,89 @@
package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class AppConfigDataServiceTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
@Test
void transformFeatureFlagsProducesRetrievalTimeValues() throws Exception {
byte[] deploymentContent = """
{
"flags": {
"enabled": {"name": "enabled"},
"disabled": {"name": "disabled"}
},
"values": {
"enabled": {
"enabled": true,
"number": 0,
"beta": false,
"empty": "",
"choices": [],
"details": {"tier": "gold"},
"_createdAt": "created",
"_updatedAt": "updated"
},
"disabled": {"enabled": false, "secret": "must-not-leak"}
},
"version": "1"
}
""".getBytes(StandardCharsets.UTF_8);
byte[] retrievalContent = AppConfigDataService.transformFeatureFlags(deploymentContent, MAPPER);
assertEquals(MAPPER.readTree("""
{
"enabled": {
"enabled": true,
"number": 0,
"beta": false,
"empty": "",
"choices": [],
"details": {"tier": "gold"}
},
"disabled": {"enabled": false}
}
"""), MAPPER.readTree(retrievalContent));
}
@Test
void transformFeatureFlagsPreservesWholeMultiVariantDocument() {
byte[] content = """
{"values":{"basic":{"enabled":true},"variant":{"enabled":true,"_variants":[]}}}
""".getBytes(StandardCharsets.UTF_8);
assertArrayEquals(content, AppConfigDataService.transformFeatureFlags(content, MAPPER));
}
@Test
void transformFeatureFlagsPreservesInvalidDocuments() {
List<String> documents = List.of(
"{not-json",
"[]",
"{}",
"{\"values\":[]}",
"{\"values\":{\"flag\":true}}",
"{\"values\":{\"flag\":{}}}",
"{\"values\":{\"flag\":{\"enabled\":\"true\"}}}");
for (String document : documents) {
byte[] content = document.getBytes(StandardCharsets.UTF_8);
assertArrayEquals(content, AppConfigDataService.transformFeatureFlags(content, MAPPER));
}
}
@Test
void transformFeatureFlagsPreservesNullAndEmptyContent() {
assertNull(AppConfigDataService.transformFeatureFlags(null, MAPPER));
assertArrayEquals(new byte[0], AppConfigDataService.transformFeatureFlags(new byte[0], MAPPER));
}
}
@@ -10,6 +10,8 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.nio.charset.StandardCharsets;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@@ -746,4 +748,87 @@ class AppConfigIntegrationTest {
.then()
.statusCode(200);
}
@Test @Order(43)
void getLatestConfigurationReturnsFeatureFlagsRetrievalFormat() {
String featureFlagsAppId = given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"feature-flags-app\"}")
.when().post("/applications")
.then().statusCode(201)
.extract().path("Id");
String featureFlagsEnvId = given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"test\"}")
.when().post("/applications/" + featureFlagsAppId + "/environments")
.then().statusCode(201)
.extract().path("Id");
String featureFlagsProfileId = given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"flags\",\"LocationUri\":\"hosted\","
+ "\"Type\":\"AWS.AppConfig.FeatureFlags\"}")
.when().post("/applications/" + featureFlagsAppId + "/configurationprofiles")
.then().statusCode(201)
.extract().path("Id");
String content = "{\"flags\":{\"enabled\":{\"name\":\"enabled\"},"
+ "\"disabled\":{\"name\":\"disabled\"}},\"values\":{"
+ "\"enabled\":{\"enabled\":true,\"number\":0,\"beta\":false,"
+ "\"_createdAt\":\"created\",\"_updatedAt\":\"updated\"},"
+ "\"disabled\":{\"enabled\":false,\"secret\":\"must-not-leak\"}},"
+ "\"version\":\"1\"}";
given()
.header("Content-Type", "application/json")
.body(content.getBytes(StandardCharsets.UTF_8))
.when().post("/applications/" + featureFlagsAppId + "/configurationprofiles/"
+ featureFlagsProfileId + "/hostedconfigurationversions")
.then().statusCode(201).header("Version-Number", equalTo("1"));
given()
.when().get("/applications/" + featureFlagsAppId + "/configurationprofiles/"
+ featureFlagsProfileId + "/hostedconfigurationversions/1")
.then().statusCode(200)
.body("flags.enabled.name", equalTo("enabled"))
.body("values.enabled.enabled", equalTo(true))
.body("version", equalTo("1"));
given()
.contentType(ContentType.JSON)
.body("{\"ConfigurationProfileId\":\"" + featureFlagsProfileId + "\","
+ "\"ConfigurationVersion\":\"1\","
+ "\"DeploymentStrategyId\":\"AppConfig.AllAtOnce\"}")
.when().post("/applications/" + featureFlagsAppId + "/environments/"
+ featureFlagsEnvId + "/deployments")
.then().statusCode(201);
String featureFlagsToken = given()
.contentType(ContentType.JSON)
.body("{\"ApplicationIdentifier\":\"" + featureFlagsAppId + "\","
+ "\"EnvironmentIdentifier\":\"" + featureFlagsEnvId + "\","
+ "\"ConfigurationProfileIdentifier\":\"" + featureFlagsProfileId + "\"}")
.when().post("/configurationsessions")
.then().statusCode(201)
.extract().path("InitialConfigurationToken");
given()
.queryParam("configuration_token", featureFlagsToken)
.when().get("/configuration")
.then().statusCode(200)
.header("Content-Type", startsWith("application/json"))
.header("Version-Label", equalTo("1"))
.header("Next-Poll-Configuration-Token", notNullValue())
.body("flags", nullValue())
.body("values", nullValue())
.body("version", nullValue())
.body("enabled.enabled", equalTo(true))
.body("enabled.number", equalTo(0))
.body("enabled.beta", equalTo(false))
.body("enabled._createdAt", nullValue())
.body("enabled._updatedAt", nullValue())
.body("disabled.enabled", equalTo(false))
.body("disabled.secret", nullValue());
}
}