Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(sfn): enforce the alias and published version quotas per state machine (#3580)

Matheus Oliveira4707d4d3a870
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java
index 8d7a83a223..2c7b2e1189 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java
@@ -555,6 +555,13 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
throw new AwsException(
"ConflictException", "State machine alias already exists: " + aliasArn, 409);
}
+ if (stateMachineAliasStore.scan(key -> key.startsWith(stateMachineArn + ":")).size()
+ >= MAX_ALIASES_PER_STATE_MACHINE) {
+ throw new AwsException("ServiceQuotaExceededException",
+ "The state machine already has the maximum of " + MAX_ALIASES_PER_STATE_MACHINE
+ + " aliases.",
+ 402);
+ }
StateMachineAlias alias = new StateMachineAlias();
alias.setStateMachineAliasArn(aliasArn);
@@ -1307,6 +1314,12 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
}
private StateMachineVersion addVersion(StateMachine stateMachine, String description) {
+ if (stateMachine.getVersions().size() >= MAX_VERSIONS_PER_STATE_MACHINE) {
+ throw new AwsException("ServiceQuotaExceededException",
+ "The state machine already has the maximum of " + MAX_VERSIONS_PER_STATE_MACHINE
+ + " published versions.",
+ 402);
+ }
int next = stateMachine.getVersionCounter() + 1;
stateMachine.setVersionCounter(next);
StateMachineVersion version = new StateMachineVersion(
@@ -1641,6 +1654,8 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
private static final int MAX_DEFINITION_LENGTH = 1_048_576;
private static final int MAX_ARN_LENGTH = 256;
private static final int MAX_VERSION_DESCRIPTION_LENGTH = 256;
+ private static final int MAX_VERSIONS_PER_STATE_MACHINE = 1000;
+ private static final int MAX_ALIASES_PER_STATE_MACHINE = 100;
private static final String INVALID_STATE_MACHINE_NAME_CHARACTERS =
"<>[]{}?*\"#%\\^|~`$&,;:/";
private static final Set<String> STATE_TYPES = Set.of(
diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAliasesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAliasesIntegrationTest.java
index 3b201b603a..ed71cdcd20 100644
--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAliasesIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAliasesIntegrationTest.java
@@ -190,4 +190,38 @@ class StepFunctionsAliasesIntegrationTest {
""".formatted(stateMachineArn))
.then().statusCode(400).body(containsString("ValidationException"));
}
+
+ @Test
+ void createAliasEnforcesTheQuotaOfOneHundredAliasesPerStateMachine() {
+ String name = "alias-quota-" + System.currentTimeMillis();
+ Response created = call("CreateStateMachine", """
+ {"name":"%s","definition":"%s",
+ "roleArn":"arn:aws:iam::000000000000:role/r","publish":true}
+ """.formatted(name, DEF));
+ String stateMachineArn = created.then().statusCode(200)
+ .extract().jsonPath().getString("stateMachineArn");
+ String versionArn = created.jsonPath().getString("stateMachineVersionArn");
+ String createAliasRequest = """
+ {"name":"%s","routingConfiguration":[
+ {"stateMachineVersionArn":"%s","weight":100}]}
+ """;
+
+ for (int i = 1; i <= 100; i++) {
+ call("CreateStateMachineAlias", createAliasRequest.formatted("Q-" + i, versionArn))
+ .then().statusCode(200);
+ }
+
+ call("CreateStateMachineAlias", createAliasRequest.formatted("Q-101", versionArn))
+ .then().statusCode(402)
+ .body(containsString("ServiceQuotaExceededException"));
+ call("CreateStateMachineAlias", createAliasRequest.formatted("Q-1", versionArn))
+ .then().statusCode(200)
+ .body("stateMachineAliasArn", is(stateMachineArn + ":Q-1"));
+
+ call("DeleteStateMachineAlias",
+ "{\"stateMachineAliasArn\":\"" + stateMachineArn + ":Q-1\"}")
+ .then().statusCode(200);
+ call("CreateStateMachineAlias", createAliasRequest.formatted("Q-101", versionArn))
+ .then().statusCode(200);
+ }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsVersionsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsVersionsIntegrationTest.java
index d4218f19cb..7e44bea458 100644
--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsVersionsIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsVersionsIntegrationTest.java
@@ -213,6 +213,44 @@ class StepFunctionsVersionsIntegrationTest {
.body(containsString("ConflictException"));
}
+ @Test
+ void publishEnforcesTheQuotaOfOneThousandVersionsPerStateMachine() {
+ String name = "ver-quota-" + System.currentTimeMillis();
+ String arn = call("CreateStateMachine",
+ "{\"name\":\"" + name + "\",\"definition\":\"" + DEF
+ + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r0\",\"publish\":true}")
+ .then().statusCode(200)
+ .extract().jsonPath().getString("stateMachineArn");
+ for (int i = 2; i <= 1000; i++) {
+ call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
+ + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r" + i + "\",\"publish\":true}")
+ .then().statusCode(200);
+ }
+
+ call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
+ .then().statusCode(200)
+ .body("stateMachineVersionArn", is(arn + ":1000"));
+ call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
+ + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/over\",\"publish\":true}")
+ .then().statusCode(402)
+ .body(containsString("ServiceQuotaExceededException"));
+ call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
+ .then().statusCode(200)
+ .body("roleArn", is("arn:aws:iam::000000000000:role/r1000"));
+ call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
+ + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/unpublished\"}")
+ .then().statusCode(200);
+ call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
+ .then().statusCode(402)
+ .body(containsString("ServiceQuotaExceededException"));
+
+ call("DeleteStateMachineVersion", "{\"stateMachineVersionArn\":\"" + arn + ":1\"}")
+ .then().statusCode(200);
+ call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
+ .then().statusCode(200)
+ .body("stateMachineVersionArn", is(arn + ":1001"));
+ }
+
@Test
void invalidCreatePublishOptionsAndNamesAreRejectedBeforeStorage() {
String name = "ver-invalid-publish-" + System.currentTimeMillis();