Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(appconfigdata): honor requested poll interval (#3092)

Niels Kootstra8686651de12a
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java
index 3de8626a3a..62893ad001 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java
@@ -204,8 +204,8 @@ class AppConfigTest {
@Test
@Order(12)
- @DisplayName("Poll interval: requested 60s but emulator returns 15s (known deviation from AWS)")
- void requiredMinimumPollIntervalIsAcceptedButNotEnforced() {
+ @DisplayName("Poll interval: requested minimum is returned to the client")
+ void requiredMinimumPollIntervalIsReturned() {
var sessionResponse = appConfigData.startConfigurationSession(StartConfigurationSessionRequest.builder()
.applicationIdentifier(applicationId)
.environmentIdentifier(environmentId)
@@ -218,16 +218,14 @@ class AppConfigTest {
.configurationToken(intervalSessionToken)
.build());
- // Emulator always returns 15s regardless of the requested interval.
- // AWS would return the requested 60s. Pinning current emulator behavior.
- assertThat(firstResponse.nextPollIntervalInSeconds()).isEqualTo(15);
+ assertThat(firstResponse.nextPollIntervalInSeconds()).isEqualTo(60);
assertThat(firstResponse.nextPollConfigurationToken()).isNotNull();
GetLatestConfigurationResponse secondResponse = appConfigData.getLatestConfiguration(GetLatestConfigurationRequest.builder()
.configurationToken(firstResponse.nextPollConfigurationToken())
.build());
- assertThat(secondResponse.nextPollIntervalInSeconds()).isEqualTo(15);
+ assertThat(secondResponse.nextPollIntervalInSeconds()).isEqualTo(60);
assertThat(secondResponse.nextPollConfigurationToken()).isNotNull();
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataController.java b/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataController.java
index d2e216357a..f534ccd3e8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataController.java
@@ -48,7 +48,7 @@ public class AppConfigDataController {
.header("Content-Type", data.contentType())
.header("Version-Label", data.configurationVersion())
.header("Next-Poll-Configuration-Token", data.nextPollConfigurationToken())
- .header("Next-Poll-Interval-In-Seconds", 15)
+ .header("Next-Poll-Interval-In-Seconds", data.nextPollIntervalInSeconds())
.build();
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataService.java b/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataService.java
index f8244d6ed4..4c105e0845 100644
--- a/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigDataService.java
@@ -10,6 +10,7 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
+import java.math.BigDecimal;
import java.util.Map;
import java.util.UUID;
@@ -40,7 +41,8 @@ public class AppConfigDataService {
session.setApplicationId(appId);
session.setEnvironmentId(envId);
session.setConfigurationProfileId(profileId);
- session.setRequiredMinimumPollIntervalInSeconds((Integer) request.getOrDefault("RequiredMinimumPollIntervalInSeconds", 15));
+ int pollInterval = parsePollInterval(request.getOrDefault("RequiredMinimumPollIntervalInSeconds", 15));
+ session.setRequiredMinimumPollIntervalInSeconds(pollInterval);
session.setCurrentToken(UUID.randomUUID().toString());
sessionStore.put(session.getCurrentToken(), session);
@@ -48,10 +50,33 @@ public class AppConfigDataService {
return session.getCurrentToken();
}
+ private static int parsePollInterval(Object value) {
+ if (!(value instanceof Number)) {
+ throw invalidPollInterval();
+ }
+ try {
+ long interval = new BigDecimal(value.toString()).longValueExact();
+ if (interval < 15 || interval > 86400) {
+ throw invalidPollInterval();
+ }
+ return (int) interval;
+ } catch (NumberFormatException | ArithmeticException e) {
+ throw invalidPollInterval();
+ }
+ }
+
+ private static AwsException invalidPollInterval() {
+ return new AwsException("BadRequestException",
+ "RequiredMinimumPollIntervalInSeconds must be an integer between 15 and 86400", 400);
+ }
+
public ConfigurationData getLatestConfiguration(String token) {
ConfigurationSession session = sessionStore.get(token)
.orElseThrow(() -> new AwsException("BadRequestException", "Invalid configuration token", 400));
+ int pollInterval = normalizePollInterval(session.getRequiredMinimumPollIntervalInSeconds());
+ session.setRequiredMinimumPollIntervalInSeconds(pollInterval);
+
String activeVersion = appConfigService.getActiveVersion(session.getEnvironmentId(), session.getConfigurationProfileId());
HostedConfigurationVersion version = null;
@@ -73,8 +98,14 @@ public class AppConfigDataService {
String contentType = (version != null) ? version.getContentType() : "application/octet-stream";
String versionLabel = (version != null) ? String.valueOf(version.getVersionNumber()) : "";
- return new ConfigurationData(content, contentType, versionLabel, nextToken);
+ return new ConfigurationData(content, contentType, versionLabel, nextToken,
+ pollInterval);
+ }
+
+ static int normalizePollInterval(int interval) {
+ return interval >= 15 && interval <= 86400 ? interval : 15;
}
- public record ConfigurationData(byte[] content, String contentType, String configurationVersion, String nextPollConfigurationToken) {}
+ public record ConfigurationData(byte[] content, String contentType, String configurationVersion,
+ String nextPollConfigurationToken, int nextPollIntervalInSeconds) {}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/appconfig/model/ConfigurationSession.java b/src/main/java/io/github/hectorvent/floci/services/appconfig/model/ConfigurationSession.java
index 0dd601a69a..2d7845be45 100644
--- a/src/main/java/io/github/hectorvent/floci/services/appconfig/model/ConfigurationSession.java
+++ b/src/main/java/io/github/hectorvent/floci/services/appconfig/model/ConfigurationSession.java
@@ -10,7 +10,7 @@ public class ConfigurationSession {
private String applicationId;
private String environmentId;
private String configurationProfileId;
- private int requiredMinimumPollIntervalInSeconds;
+ private int requiredMinimumPollIntervalInSeconds = 15;
private String currentToken;
private String lastConfigurationVersion;
diff --git a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigIntegrationTest.java
index f4189724a2..6c08c38f72 100644
--- a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigIntegrationTest.java
@@ -182,8 +182,8 @@ class AppConfigIntegrationTest {
}
@Test @Order(12)
- @DisplayName("Poll interval: requested 60s but emulator returns 15s (known deviation from AWS)")
- void requiredMinimumPollIntervalIsStoredButNotEnforced() {
+ @DisplayName("Poll interval: requested minimum is returned to the client")
+ void requiredMinimumPollIntervalIsReturned() {
intervalToken = given()
.contentType(ContentType.JSON)
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 60}")
@@ -199,7 +199,7 @@ class AppConfigIntegrationTest {
.then()
.statusCode(200)
.header("Next-Poll-Configuration-Token", notNullValue())
- .header("Next-Poll-Interval-In-Seconds", equalTo("15"))
+ .header("Next-Poll-Interval-In-Seconds", equalTo("60"))
.extract().header("Next-Poll-Configuration-Token");
given()
@@ -210,6 +210,72 @@ class AppConfigIntegrationTest {
.header("Next-Poll-Configuration-Token", notNullValue());
}
+ @Test @Order(32)
+ void requiredMinimumPollIntervalMustBeWithinAwsLimits() {
+ given()
+ .contentType(ContentType.JSON)
+ .body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 14}")
+ .when().post("/configurationsessions")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("BadRequestException"));
+ }
+
+ @Test @Order(33)
+ void requiredMinimumPollIntervalAcceptsAwsUpperBoundary() {
+ String token = startSessionWithInterval(86400);
+
+ given()
+ .queryParam("configuration_token", token)
+ .when().get("/configuration")
+ .then()
+ .statusCode(200)
+ .header("Next-Poll-Interval-In-Seconds", equalTo("86400"));
+ }
+
+ @Test @Order(34)
+ void requiredMinimumPollIntervalRejectsValuesAboveAwsMaximum() {
+ given()
+ .contentType(ContentType.JSON)
+ .body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 86401}")
+ .when().post("/configurationsessions")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("BadRequestException"));
+ }
+
+ @Test @Order(35)
+ void requiredMinimumPollIntervalRejectsFractionalValues() {
+ given()
+ .contentType(ContentType.JSON)
+ .body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 60.5}")
+ .when().post("/configurationsessions")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("BadRequestException"));
+ }
+
+ @Test @Order(36)
+ void requiredMinimumPollIntervalRejectsOversizedValues() {
+ given()
+ .contentType(ContentType.JSON)
+ .body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 4294967296}")
+ .when().post("/configurationsessions")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("BadRequestException"));
+ }
+
+ private String startSessionWithInterval(int interval) {
+ return given()
+ .contentType(ContentType.JSON)
+ .body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": " + interval + "}")
+ .when().post("/configurationsessions")
+ .then()
+ .statusCode(201)
+ .extract().path("InitialConfigurationToken");
+ }
+
// ──────────────────────────── Hosted Configuration Version list ────────────────────────────
@Test @Order(13)
diff --git a/src/test/java/io/github/hectorvent/floci/services/appconfig/ConfigurationSessionTest.java b/src/test/java/io/github/hectorvent/floci/services/appconfig/ConfigurationSessionTest.java
new file mode 100644
index 0000000000..21c5bc054b
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/appconfig/ConfigurationSessionTest.java
@@ -0,0 +1,24 @@
+package io.github.hectorvent.floci.services.appconfig;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.services.appconfig.model.ConfigurationSession;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ConfigurationSessionTest {
+ @Test
+ void legacySessionWithoutPollIntervalUsesAwsDefault() throws Exception {
+ ConfigurationSession session = new ObjectMapper().readValue(
+ "{\"id\":\"legacy\",\"applicationId\":\"app\",\"environmentId\":\"env\",\"configurationProfileId\":\"profile\"}",
+ ConfigurationSession.class);
+
+ assertEquals(15, session.getRequiredMinimumPollIntervalInSeconds());
+ }
+
+ @Test
+ void invalidPersistedPollIntervalUsesAwsDefault() {
+ assertEquals(15, AppConfigDataService.normalizePollInterval(0));
+ assertEquals(15, AppConfigDataService.normalizePollInterval(86401));
+ }
+}