mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(appconfig): accept a quoted Ion type parameter in Accept (#5687)
GetLatestConfiguration and the legacy GetConfiguration compared the type parameter of an Accept media range verbatim, quotes included. So application/ion with type="AWS.AppConfig.FeatureFlags" did not match, and a feature flag profile with variants came back as the stored JSON instead of Ion. RFC 9110 section 5.6.6 makes a quoted-string parameter value the same value as its token form. The type value is now read as a token, or as a quoted-string without its DQUOTEs and with each quoted-pair standing for the character after its backslash (section 5.6.4). A quoted-string that is not closed, or that has text after its closing DQUOTE, does not match. The media range and the q weight are read as before. Closes #5673 Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
This commit is contained in:
1 parent
503899df05
commit
190ed52249
4 files changed
+152
-4
No files matched your search
+28
-1
@@ -225,7 +225,7 @@ public class AppConfigDataService {
|
||||
String name = parameter[0].trim();
|
||||
String value = parameter[1].trim();
|
||||
if (name.equalsIgnoreCase("type")) {
|
||||
featureFlags = "AWS.AppConfig.FeatureFlags".equalsIgnoreCase(value);
|
||||
featureFlags = "AWS.AppConfig.FeatureFlags".equalsIgnoreCase(parameterValue(value));
|
||||
} else if (name.equalsIgnoreCase("q")) {
|
||||
acceptable = !value.matches("0(\\.0+)?");
|
||||
}
|
||||
@@ -237,6 +237,33 @@ public class AppConfigDataService {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A media-type parameter value as RFC 9110 section 5.6.6 defines it: a token as is, or a quoted-string without its
|
||||
* DQUOTEs and with each quoted-pair read as the character after its backslash (section 5.6.4). {@code null} for a
|
||||
* quoted-string with no closing DQUOTE or with anything after it.
|
||||
*/
|
||||
private static String parameterValue(String value) {
|
||||
if (!value.startsWith("\"")) {
|
||||
return value;
|
||||
}
|
||||
StringBuilder unquoted = new StringBuilder();
|
||||
boolean escaped = false;
|
||||
for (int i = 1; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
if (escaped) {
|
||||
unquoted.append(c);
|
||||
escaped = false;
|
||||
} else if (c == '\\') {
|
||||
escaped = true;
|
||||
} else if (c == '"') {
|
||||
return i == value.length() - 1 ? unquoted.toString() : null;
|
||||
} else {
|
||||
unquoted.append(c);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static byte[] transformFeatureFlags(byte[] content, ObjectMapper objectMapper) {
|
||||
if (content == null || content.length == 0) {
|
||||
return content;
|
||||
|
||||
+91
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.appconfig;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
@@ -34,6 +35,7 @@ class AppConfigIntegrationTest {
|
||||
private static String emptyProfileId;
|
||||
private static String deploymentNextToken;
|
||||
private static String secondDeploymentNextToken;
|
||||
private static String variantFlagsSessionBody;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
@@ -1121,4 +1123,93 @@ class AppConfigIntegrationTest {
|
||||
.when().get("/configuration")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(52)
|
||||
void getLatestConfigurationServesIonForAQuotedFeatureFlagsType() {
|
||||
getLatestVariantFlagsAccepting("application/ion; type=\"AWS.AppConfig.FeatureFlags\", */*;q=0.1")
|
||||
.header("Content-Type", startsWith("application/ion"))
|
||||
.header("Content-Type", containsString("type=AWS.AppConfig.FeatureFlags"));
|
||||
}
|
||||
|
||||
@Test @Order(53)
|
||||
void getLatestConfigurationServesIonForAnUnquotedFeatureFlagsType() {
|
||||
getLatestVariantFlagsAccepting("application/ion; type=AWS.AppConfig.FeatureFlags, */*;q=0.1")
|
||||
.header("Content-Type", startsWith("application/ion"))
|
||||
.header("Content-Type", containsString("type=AWS.AppConfig.FeatureFlags"));
|
||||
}
|
||||
|
||||
@Test @Order(54)
|
||||
void getLatestConfigurationServesIonForAQuotedFeatureFlagsTypeWithAQuotedPair() {
|
||||
getLatestVariantFlagsAccepting("application/ion; type=\"AWS.AppConfig.Feature\\Flags\", */*;q=0.1")
|
||||
.header("Content-Type", startsWith("application/ion"))
|
||||
.header("Content-Type", containsString("type=AWS.AppConfig.FeatureFlags"));
|
||||
}
|
||||
|
||||
@Test @Order(55)
|
||||
void getLatestConfigurationServesStoredJsonForAQuotedOtherType() {
|
||||
getLatestVariantFlagsAccepting("application/ion; type=\"AWS.AppConfig.Other\", */*;q=0.1")
|
||||
.header("Content-Type", startsWith("application/json"))
|
||||
.body("values.promo._variants[0].name", equalTo("uk"));
|
||||
}
|
||||
|
||||
/** Polls a new session on a feature flag profile with variants, deployed on first use. */
|
||||
private static ValidatableResponse getLatestVariantFlagsAccepting(String accept) {
|
||||
if (variantFlagsSessionBody == null) {
|
||||
variantFlagsSessionBody = deployVariantFlags();
|
||||
}
|
||||
String token = given()
|
||||
.contentType(ContentType.JSON).body(variantFlagsSessionBody)
|
||||
.when().post("/configurationsessions")
|
||||
.then().statusCode(201)
|
||||
.extract().path("InitialConfigurationToken");
|
||||
|
||||
return given()
|
||||
.header("Accept", accept)
|
||||
.queryParam("configuration_token", token)
|
||||
.when().get("/configuration")
|
||||
.then().statusCode(200)
|
||||
.header("Version-Label", equalTo("1"));
|
||||
}
|
||||
|
||||
/** Deploys a feature flag profile whose one flag has variants; returns the StartConfigurationSession body. */
|
||||
private static String deployVariantFlags() {
|
||||
String app = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"Name\":\"quoted-ion-type-app\"}")
|
||||
.when().post("/applications")
|
||||
.then().statusCode(201)
|
||||
.extract().path("Id");
|
||||
String env = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"Name\":\"test\"}")
|
||||
.when().post("/applications/" + app + "/environments")
|
||||
.then().statusCode(201)
|
||||
.extract().path("Id");
|
||||
String profile = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"Name\":\"flags\",\"LocationUri\":\"hosted\",\"Type\":\"AWS.AppConfig.FeatureFlags\"}")
|
||||
.when().post("/applications/" + app + "/configurationprofiles")
|
||||
.then().statusCode(201)
|
||||
.extract().path("Id");
|
||||
|
||||
String content = "{\"flags\":{},\"version\":\"1\",\"values\":{\"promo\":{\"_variants\":["
|
||||
+ "{\"attributeValues\":{\"storeId\":\"uk\"},\"enabled\":true,\"name\":\"uk\","
|
||||
+ "\"rule\":\"(eq $storeId \\\"uk\\\")\"},"
|
||||
+ "{\"enabled\":false,\"name\":\"default\"}]}}}";
|
||||
given()
|
||||
.header("Content-Type", "application/json")
|
||||
.body(content.getBytes(StandardCharsets.UTF_8))
|
||||
.when().post("/applications/" + app + "/configurationprofiles/" + profile
|
||||
+ "/hostedconfigurationversions")
|
||||
.then().statusCode(201);
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"ConfigurationProfileId\":\"" + profile + "\",\"ConfigurationVersion\":\"1\","
|
||||
+ "\"DeploymentStrategyId\":\"AppConfig.AllAtOnce\"}")
|
||||
.when().post("/applications/" + app + "/environments/" + env + "/deployments")
|
||||
.then().statusCode(201);
|
||||
|
||||
return "{\"ApplicationIdentifier\":\"" + app + "\",\"EnvironmentIdentifier\":\"" + env + "\","
|
||||
+ "\"ConfigurationProfileIdentifier\":\"" + profile + "\"}";
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -6,6 +6,8 @@ import io.restassured.http.ContentType;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
@@ -228,8 +230,10 @@ class AppConfigLegacyIntegrationTest {
|
||||
.body("values", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void variantFeatureFlagsAreIonForACallerThatAcceptsOnlyIon() {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"application/ion; type=AWS.AppConfig.FeatureFlags",
|
||||
"application/ion; type=\"AWS.AppConfig.FeatureFlags\""})
|
||||
void variantFeatureFlagsAreIonForACallerThatAcceptsOnlyIon(String accept) {
|
||||
String flags = createProfile(Map.of("Name", "variant-flags", "LocationUri", "hosted",
|
||||
"Type", "AWS.AppConfig.FeatureFlags"));
|
||||
createHostedVersion(flags, "{\"flags\":{},\"version\":\"1\",\"values\":{\"promo\":{\"_variants\":["
|
||||
@@ -237,7 +241,7 @@ class AppConfigLegacyIntegrationTest {
|
||||
+ "\"rule\":\"(eq $storeId \\\"uk\\\")\"},{\"enabled\":false,\"name\":\"default\"}]}}}");
|
||||
deploy(environment, flags, "1");
|
||||
|
||||
byte[] ion = given().accept("application/ion; type=AWS.AppConfig.FeatureFlags")
|
||||
byte[] ion = given().accept(accept)
|
||||
.queryParam("client_id", "reader").get(path(environment, flags))
|
||||
.then().statusCode(200)
|
||||
.header("Configuration-Version", "1")
|
||||
|
||||
+26
@@ -126,4 +126,30 @@ class FeatureFlagIonEncoderTest {
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon("*/*"));
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon(null));
|
||||
}
|
||||
|
||||
/** RFC 9110 section 5.6.6: a parameter value is a token or a quoted-string, and both forms are the same value. */
|
||||
@Test
|
||||
void readsAQuotedTypeAsTheSameValueAsAToken() {
|
||||
assertTrue(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=AWS.AppConfig.FeatureFlags, */*;q=0.1"));
|
||||
assertTrue(AppConfigDataService.acceptsFeatureFlagIon(
|
||||
"application/ion; type=\"AWS.AppConfig.FeatureFlags\", */*;q=0.1"));
|
||||
assertTrue(AppConfigDataService.acceptsFeatureFlagIon("Application/ION;TYPE=\"aws.appconfig.featureflags\";q=1.0"));
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\"AWS.AppConfig.FeatureFlags\";q=0"));
|
||||
}
|
||||
|
||||
/** RFC 9110 section 5.6.4: a quoted-pair stands for the character after its backslash. */
|
||||
@Test
|
||||
void readsAQuotedPairInATypeAsTheCharacterItEscapes() {
|
||||
assertTrue(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\"AWS.AppConfig.Feature\\Flags\""));
|
||||
assertTrue(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\"AWS\\.AppConfig\\.FeatureFlags\""));
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\"AWS.AppConfig.FeatureFlags\\\"\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsAQuotedTypeThatIsMalformedOrDifferent() {
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\"AWS.AppConfig.Other\""));
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\" AWS.AppConfig.FeatureFlags\""));
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\"AWS.AppConfig.FeatureFlags"));
|
||||
assertFalse(AppConfigDataService.acceptsFeatureFlagIon("application/ion; type=\"AWS.AppConfig.FeatureFlags\"x"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user