mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): reject invalid configuration numbers before mutation (#4726)
* fix(lambda): reject invalid configuration numbers before mutation * fix(lambda): validate configuration ARN types and memory limit
This commit is contained in:
1 parent
45b00779b7
commit
894f20bb81
4 files changed
+170
-5
No files matched your search
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -212,6 +213,77 @@ class LambdaIntegrationTest {
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void invalidMemoryUpdateDoesNotChangeConfiguration() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{"FunctionName":"invalid-memory-update","Runtime":"nodejs20.x",
|
||||
"Role":"arn:aws:iam::000000000000:role/lambda-role","Handler":"index.handler"}
|
||||
""")
|
||||
.when()
|
||||
.post(BASE_PATH + "/functions")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{"Description":"half-applied","MemorySize":"abc"}
|
||||
""")
|
||||
.when()
|
||||
.put(BASE_PATH + "/functions/invalid-memory-update/configuration")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("InvalidParameterValueException"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get(BASE_PATH + "/functions/invalid-memory-update/configuration")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Description", anyOf(nullValue(), equalTo("")))
|
||||
.body("MemorySize", equalTo(128));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void invalidArnTypesDoNotChangeConfiguration() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{"FunctionName":"invalid-arn-update","Runtime":"nodejs20.x",
|
||||
"Role":"arn:aws:iam::000000000000:role/lambda-role","Handler":"index.handler"}
|
||||
""")
|
||||
.when()
|
||||
.post(BASE_PATH + "/functions")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
for (String request : List.of(
|
||||
"{\"Description\":\"half-applied\",\"KMSKeyArn\":123}",
|
||||
"{\"Description\":\"half-applied\",\"DeadLetterConfig\":{\"TargetArn\":123}}")) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(request)
|
||||
.when()
|
||||
.put(BASE_PATH + "/functions/invalid-arn-update/configuration")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("InvalidParameterValueException"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get(BASE_PATH + "/functions/invalid-arn-update/configuration")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Description", anyOf(nullValue(), equalTo("")))
|
||||
.body("KMSKeyArn", anyOf(nullValue(), equalTo("")))
|
||||
.body("DeadLetterConfig.TargetArn", anyOf(nullValue(), equalTo("")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void deleteFunction() {
|
||||
|
||||
@@ -1599,6 +1599,72 @@ class LambdaServiceTest {
|
||||
assertNull(service.getFunction(REGION, "update-desc-fn").getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfigurationRejectsInvalidMemoryBeforeMutation() {
|
||||
LambdaFunction original = service.createFunction(REGION, baseRequest("invalid-memory-update"));
|
||||
String revisionId = original.getRevisionId();
|
||||
|
||||
for (Object invalid : List.of("abc", 127, 10241, 32769, 256.5)) {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionConfiguration(REGION, "invalid-memory-update",
|
||||
Map.of("Description", "half-applied", "MemorySize", invalid)));
|
||||
assertEquals("InvalidParameterValueException", error.getErrorCode());
|
||||
LambdaFunction stored = service.getFunction(REGION, "invalid-memory-update");
|
||||
assertNull(stored.getDescription());
|
||||
assertEquals(256, stored.getMemorySize());
|
||||
assertEquals(revisionId, stored.getRevisionId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfigurationAcceptsMaximumMemorySize() {
|
||||
service.createFunction(REGION, baseRequest("maximum-memory-update"));
|
||||
|
||||
LambdaFunction updated = service.updateFunctionConfiguration(REGION, "maximum-memory-update",
|
||||
Map.of("MemorySize", 10240));
|
||||
|
||||
assertEquals(10240, updated.getMemorySize());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfigurationRejectsNonStringArnsBeforeMutation() {
|
||||
LambdaFunction original = service.createFunction(REGION, baseRequest("invalid-arn-update"));
|
||||
String revisionId = original.getRevisionId();
|
||||
|
||||
for (Map<String, Object> invalid : List.of(
|
||||
Map.<String, Object>of("KMSKeyArn", 123),
|
||||
Map.<String, Object>of("DeadLetterConfig", Map.of("TargetArn", 123)))) {
|
||||
Map<String, Object> request = new HashMap<>(invalid);
|
||||
request.put("Description", "half-applied");
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionConfiguration(REGION, "invalid-arn-update", request));
|
||||
|
||||
assertEquals("InvalidParameterValueException", error.getErrorCode());
|
||||
LambdaFunction stored = service.getFunction(REGION, "invalid-arn-update");
|
||||
assertNull(stored.getDescription());
|
||||
assertNull(stored.getKmsKeyArn());
|
||||
assertNull(stored.getDeadLetterTargetArn());
|
||||
assertEquals(revisionId, stored.getRevisionId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfigurationRejectsInvalidTimeoutBeforeMutation() {
|
||||
LambdaFunction original = service.createFunction(REGION, baseRequest("invalid-timeout-update"));
|
||||
String revisionId = original.getRevisionId();
|
||||
|
||||
for (Object invalid : List.of("abc", 0, 901, 1.5)) {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionConfiguration(REGION, "invalid-timeout-update",
|
||||
Map.of("Description", "half-applied", "Timeout", invalid)));
|
||||
assertEquals("InvalidParameterValueException", error.getErrorCode());
|
||||
LambdaFunction stored = service.getFunction(REGION, "invalid-timeout-update");
|
||||
assertNull(stored.getDescription());
|
||||
assertEquals(10, stored.getTimeout());
|
||||
assertEquals(revisionId, stored.getRevisionId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunction_bareStringLayers_isRejectedAsSerializationError() {
|
||||
// Catches: a non-list Layers value being treated as absent instead of rejected
|
||||
|
||||
Reference in new issue
Block a user