mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): validate enum and pattern-constrained request fields (#4611)
* fix(lambda): validate enum and pattern-constrained request fields CreateFunction, UpdateFunctionConfiguration, PublishLayerVersion, the event source mapping calls, and the function URL calls now reject values outside the botocore Runtime/Architecture/FunctionResponseType/FunctionUrlAuthType/InvokeMode enums and the Role/Handler/KMSKeyArn/LayerVersionArn/Alias/Arn patterns (including AWS-managed awslayer ARNs and eusc- regions), and ListEventSourceMappings honors its EventSourceArn filter. Constraint failures use ValidationException, matching the existing pattern checks in LambdaArnUtils. * fix(lambda): validate KMSKeyArn on update, alias names, event source ARNs, and PackageType Adds KMSKeyArn pattern on UpdateFunctionConfiguration, alias name pattern and length on Create/UpdateAlias, EventSourceArn pattern on CreateEventSourceMapping, and PackageType enum on CreateFunction. * fix(lambda): accept every botocore NamespacedFunctionName in ListEventSourceMappings Add eusc- region, dotted names and $LATEST.PUBLISHED to the function name pattern. * fix(lambda): reject non-list members and validate before mutating on update UpdateFunctionUrlConfig now validates AuthType and InvokeMode before applying either, so a rejected request leaves the stored config unchanged. A non-list Layers, CompatibleRuntimes or CompatibleArchitectures is a SerializationException instead of being read as absent. Get and DeleteFunctionUrlConfig enforce the FunctionUrlQualifier constraint, UpdateFunctionConfiguration enforces the 256 character Description limit, and an empty or missing alias name is rejected.
This commit is contained in:
1 parent
0383ecf53e
commit
e6d22e8bcf
7 files changed
+763
-18
No files matched your search
@@ -1737,4 +1737,112 @@ class EsmIntegrationTest {
|
||||
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid).then().statusCode(202);
|
||||
}
|
||||
|
||||
// ── Request-shape validation ────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(90)
|
||||
void createEventSourceMapping_rejectsUnknownFunctionResponseType() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"FunctionResponseTypes": ["Bogus"]
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterValueException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(91)
|
||||
void updateEventSourceMapping_appliesAndRejectsFunctionResponseTypes() {
|
||||
String uuid = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s"
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.extract().path("UUID");
|
||||
|
||||
try {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{ \"FunctionResponseTypes\": [\"Bogus\"] }")
|
||||
.when()
|
||||
.put(LAMBDA_BASE + "/event-source-mappings/" + uuid)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterValueException"));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{ \"FunctionResponseTypes\": [\"ReportBatchItemFailures\"] }")
|
||||
.when()
|
||||
.put(LAMBDA_BASE + "/event-source-mappings/" + uuid)
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.body("FunctionResponseTypes", hasItem("ReportBatchItemFailures"));
|
||||
} finally {
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(92)
|
||||
void listEventSourceMappings_rejectsMalformedEventSourceArn() {
|
||||
given()
|
||||
.when()
|
||||
.get(LAMBDA_BASE + "/event-source-mappings?EventSourceArn=not-an-arn")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(93)
|
||||
void listEventSourceMappings_filtersByEventSourceArn() {
|
||||
String uuid = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s"
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.extract().path("UUID");
|
||||
|
||||
try {
|
||||
given()
|
||||
.when()
|
||||
.get(LAMBDA_BASE + "/event-source-mappings?EventSourceArn=" + QUEUE_ARN)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EventSourceMappings.UUID", hasItem(uuid));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get(LAMBDA_BASE + "/event-source-mappings?EventSourceArn=" + STREAM_ARN)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EventSourceMappings.UUID", not(hasItem(uuid)));
|
||||
} finally {
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.lambda;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaLayerVersion;
|
||||
@@ -20,6 +21,7 @@ import java.util.zip.ZipOutputStream;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -113,6 +115,24 @@ class LambdaLayerCodePathIsolationTest {
|
||||
assertEqualsContent(restored.getCodeLocalPath(), "persisted");
|
||||
}
|
||||
|
||||
@Test
|
||||
void publishLayerVersionRejectsBareStringCompatibilityLists(@TempDir Path baseDir) throws Exception {
|
||||
// Catches: a non-list CompatibleRuntimes/CompatibleArchitectures being ignored instead of rejected
|
||||
LambdaLayerService service = serviceFor(baseDir, "111111111111");
|
||||
Map<String, Object> runtimes = Map.of("Content", Map.of("ZipFile", zipBase64("r")),
|
||||
"CompatibleRuntimes", "python3.12");
|
||||
Map<String, Object> architectures = Map.of("Content", Map.of("ZipFile", zipBase64("a")),
|
||||
"CompatibleArchitectures", "x86_64");
|
||||
|
||||
AwsException badRuntimes = assertThrows(AwsException.class,
|
||||
() -> service.publishLayerVersion("us-east-1", LAYER_NAME, runtimes));
|
||||
AwsException badArchitectures = assertThrows(AwsException.class,
|
||||
() -> service.publishLayerVersion("us-east-1", LAYER_NAME, architectures));
|
||||
|
||||
assertEquals("SerializationException", badRuntimes.getErrorCode());
|
||||
assertEquals("SerializationException", badArchitectures.getErrorCode());
|
||||
}
|
||||
|
||||
private static LambdaLayerVersion publish(LambdaLayerService service, String content) throws Exception {
|
||||
return service.publishLayerVersion("us-east-1", LAYER_NAME, request(content));
|
||||
}
|
||||
|
||||
+56
@@ -501,4 +501,60 @@ class LambdaLayerIntegrationTest {
|
||||
.statusCode(200);
|
||||
// Layer should no longer appear (all versions deleted)
|
||||
}
|
||||
|
||||
// ── Request-shape validation ────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void publishLayerVersion_rejectsUnknownCompatibleRuntime() throws Exception {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"Content": { "ZipFile": "%s" },
|
||||
"CompatibleRuntimes": ["cobol99"]
|
||||
}
|
||||
""".formatted(layerZipBase64()))
|
||||
.when()
|
||||
.post("/2018-10-31/layers/validation-test-layer/versions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void publishLayerVersion_rejectsUnknownCompatibleArchitecture() throws Exception {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"Content": { "ZipFile": "%s" },
|
||||
"CompatibleArchitectures": ["mips"]
|
||||
}
|
||||
""".formatted(layerZipBase64()))
|
||||
.when()
|
||||
.post("/2018-10-31/layers/validation-test-layer/versions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(25)
|
||||
void publishLayerVersion_rejectsTooManyCompatibleArchitectures() throws Exception {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"Content": { "ZipFile": "%s" },
|
||||
"CompatibleArchitectures": ["x86_64", "arm64", "x86_64"]
|
||||
}
|
||||
""".formatted(layerZipBase64()))
|
||||
.when()
|
||||
.post("/2018-10-31/layers/validation-test-layer/versions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.lambda.model.EventSourceMapping;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaFileSystemConfig;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaUrlConfig;
|
||||
import io.github.hectorvent.floci.services.lambda.zip.CodeStore;
|
||||
import io.github.hectorvent.floci.services.lambda.zip.ZipExtractor;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -20,6 +21,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
@@ -1315,6 +1317,306 @@ class LambdaServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── Request-shape validation ────────────────────────────
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsUnknownRuntime() {
|
||||
Map<String, Object> request = baseRequest("bad-runtime-fn");
|
||||
request.put("Runtime", "cobol99");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfigurationRejectsUnknownRuntime() {
|
||||
service.createFunction(REGION, baseRequest("update-bad-runtime-fn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionConfiguration(REGION, "update-bad-runtime-fn",
|
||||
Map.of("Runtime", "cobol99")));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsMalformedRoleArn() {
|
||||
Map<String, Object> request = baseRequest("bad-role-fn");
|
||||
request.put("Role", "not-an-arn");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsHandlerWithWhitespace() {
|
||||
Map<String, Object> request = baseRequest("bad-handler-fn");
|
||||
request.put("Handler", "index handler");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsDescriptionOverMaxLength() {
|
||||
Map<String, Object> request = baseRequest("bad-description-fn");
|
||||
request.put("Description", "x".repeat(257));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsMalformedKmsKeyArn() {
|
||||
Map<String, Object> request = baseRequest("bad-kms-fn");
|
||||
request.put("KMSKeyArn", "not-an-arn");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsMalformedLayerArn() {
|
||||
Map<String, Object> request = baseRequest("bad-layer-fn");
|
||||
request.put("Layers", List.of("not-a-layer-arn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsMoreThanFiveLayers() {
|
||||
Map<String, Object> request = baseRequest("too-many-layers-fn");
|
||||
List<String> layers = new ArrayList<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
layers.add("arn:aws:lambda:us-east-1:000000000000:layer:l" + i + ":1");
|
||||
}
|
||||
request.put("Layers", layers);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfigurationRejectsMalformedLayerArn() {
|
||||
service.createFunction(REGION, baseRequest("update-bad-layer-fn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionConfiguration(REGION, "update-bad-layer-fn",
|
||||
Map.of("Layers", List.of("not-a-layer-arn"))));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
// Architectures is validated by upstream's validateArchitectures, which reports the error
|
||||
// botocore actually models for CreateFunction: ValidationException is not in that operation's
|
||||
// error set, InvalidParameterValueException is.
|
||||
@Test
|
||||
void createFunctionRejectsUnknownArchitecture() {
|
||||
Map<String, Object> request = baseRequest("bad-arch-fn");
|
||||
request.put("Architectures", List.of("mips"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("InvalidParameterValueException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionRejectsMoreThanOneArchitecture() {
|
||||
Map<String, Object> request = baseRequest("too-many-arch-fn");
|
||||
request.put("Architectures", List.of("x86_64", "arm64"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
assertEquals("InvalidParameterValueException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionCodeAppliesValidArchitecture() {
|
||||
service.createFunction(REGION, baseRequest("update-code-arch-fn"));
|
||||
|
||||
LambdaFunction updated = service.updateFunctionCode(REGION, "update-code-arch-fn",
|
||||
Map.of("Architectures", List.of("arm64")));
|
||||
|
||||
assertEquals(List.of("arm64"), updated.getArchitectures());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionCodeRejectsUnknownArchitecture() {
|
||||
service.createFunction(REGION, baseRequest("update-code-bad-arch-fn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionCode(REGION, "update-code-bad-arch-fn",
|
||||
Map.of("Architectures", List.of("mips"))));
|
||||
assertEquals("InvalidParameterValueException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAliasRejectsMalformedName() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.deleteAlias(REGION, "some-fn", "123"));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionUrlConfigRejectsUnknownAuthType() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunctionUrlConfig(REGION, "any-fn", null,
|
||||
Map.of("AuthType", "BOGUS")));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionUrlConfigRejectsUnknownInvokeMode() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunctionUrlConfig(REGION, "any-fn", null,
|
||||
Map.of("InvokeMode", "BOGUS")));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionUrlConfigRejectsAllNumericQualifier() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunctionUrlConfig(REGION, "any-fn", "123", Map.of()));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionUrlConfig_invalidInvokeMode_leavesAuthTypeUnchanged() {
|
||||
// Catches: UpdateFunctionUrlConfig applying AuthType to the stored config before InvokeMode is rejected
|
||||
service.createFunction(REGION, baseRequest("url-atomic-fn"));
|
||||
LambdaUrlConfig seeded = new LambdaUrlConfig();
|
||||
seeded.setAuthType("NONE");
|
||||
service.getFunction(REGION, "url-atomic-fn").setUrlConfig(seeded);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionUrlConfig(REGION, "url-atomic-fn", null,
|
||||
Map.of("AuthType", "AWS_IAM", "InvokeMode", "BOGUS")));
|
||||
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
assertEquals("NONE", service.getFunctionUrlConfig(REGION, "url-atomic-fn", null).getAuthType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAndDeleteFunctionUrlConfig_rejectMalformedQualifier() {
|
||||
// Catches: Get/DeleteFunctionUrlConfig skipping the FunctionUrlQualifier constraint that Create/Update enforce
|
||||
AwsException numeric = assertThrows(AwsException.class,
|
||||
() -> service.getFunctionUrlConfig(REGION, "any-fn", "123"));
|
||||
AwsException empty = assertThrows(AwsException.class,
|
||||
() -> service.getFunctionUrlConfig(REGION, "any-fn", ""));
|
||||
AwsException deleteNumeric = assertThrows(AwsException.class,
|
||||
() -> service.deleteFunctionUrlConfig(REGION, "any-fn", "123"));
|
||||
|
||||
assertEquals("ValidationException", numeric.getErrorCode());
|
||||
assertEquals("ValidationException", empty.getErrorCode());
|
||||
assertEquals("ValidationException", deleteNumeric.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfiguration_overlongDescription_isRejectedAndNotStored() {
|
||||
// Catches: UpdateFunctionConfiguration persisting a Description over the 256-character shape limit
|
||||
service.createFunction(REGION, baseRequest("update-desc-fn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionConfiguration(REGION, "update-desc-fn",
|
||||
Map.of("Description", "d".repeat(257))));
|
||||
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
assertNull(service.getFunction(REGION, "update-desc-fn").getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunction_bareStringLayers_isRejectedAsSerializationError() {
|
||||
// Catches: a non-list Layers value being treated as absent instead of rejected
|
||||
Map<String, Object> request = baseRequest("bare-layers-fn");
|
||||
request.put("Layers", "arn:aws:lambda:us-east-1:000000000000:layer:l0:1");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createFunction(REGION, request));
|
||||
|
||||
assertEquals("SerializationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfiguration_bareStringLayers_isRejectedAndKeepsStoredLayers() {
|
||||
// Catches: a non-list Layers value on update silently clearing the stored layers
|
||||
service.createFunction(REGION, baseRequest("bare-layers-update-fn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateFunctionConfiguration(REGION, "bare-layers-update-fn",
|
||||
Map.of("Layers", "not-a-list")));
|
||||
|
||||
assertEquals("SerializationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listEventSourceMappingsRejectsMalformedFunctionName() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.listEventSourceMappings("not a valid name!"));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
// Catches: EventSourceArn pattern missing the optional eusc- region prefix from the Arn shape.
|
||||
@Test
|
||||
void listEventSourceMappingsAcceptsEuscRegionEventSourceArn() {
|
||||
assertEquals(List.of(),
|
||||
service.listEventSourceMappings(null, "arn:aws-eusc:sqs:eusc-de-east-1:000000000000:q"));
|
||||
}
|
||||
|
||||
// Catches: FunctionName pattern missing "." in the name characters, so a dotted name is rejected.
|
||||
@Test
|
||||
void listEventSourceMappingsAcceptsDottedFunctionName() {
|
||||
assertNotRejectedByListEsmPattern("my.func");
|
||||
}
|
||||
|
||||
// Catches: FunctionName pattern missing the optional eusc- region prefix.
|
||||
@Test
|
||||
void listEventSourceMappingsAcceptsEuscRegionFunctionArn() {
|
||||
assertEquals(List.of(), service.listEventSourceMappings(
|
||||
"arn:aws-eusc:lambda:eusc-de-east-1:000000000000:function:my-func"));
|
||||
}
|
||||
|
||||
// Catches: FunctionName pattern missing the $LATEST.PUBLISHED qualifier.
|
||||
@Test
|
||||
void listEventSourceMappingsAcceptsLatestPublishedQualifier() {
|
||||
assertNotRejectedByListEsmPattern(
|
||||
"arn:aws:lambda:us-east-1:000000000000:function:my-func:$LATEST.PUBLISHED");
|
||||
}
|
||||
|
||||
// LambdaArnUtils.resolve still rejects dotted names and $LATEST.PUBLISHED downstream, so only the
|
||||
// ListEventSourceMappings pattern check (anchored with ^) is asserted here.
|
||||
private void assertNotRejectedByListEsmPattern(String functionName) {
|
||||
try {
|
||||
service.listEventSourceMappings(functionName);
|
||||
} catch (AwsException e) {
|
||||
assertFalse(e.getMessage().contains("pattern: ^(arn:"), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Catches: LayerVersionArn pattern missing the AWS-managed awslayer alternative, so a valid
|
||||
// AWS-managed layer ARN is rejected as a ValidationException.
|
||||
@Test
|
||||
void createFunctionAcceptsAwsManagedLayerArn() {
|
||||
Map<String, Object> request = baseRequest("aws-layer-fn");
|
||||
request.put("Layers", List.of("arn:aws:lambda:::awslayer:AmazonLinux2"));
|
||||
|
||||
LambdaFunction created = service.createFunction(REGION, request);
|
||||
|
||||
assertEquals(List.of("arn:aws:lambda:::awslayer:AmazonLinux2"), created.getLayers());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listEventSourceMappingsRejectsMalformedEventSourceArn() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.listEventSourceMappings(null, "not-an-arn"));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createEventSourceMapping_selfManagedKafka_success() {
|
||||
service.createFunction(REGION, baseRequest("kafka-fn"));
|
||||
@@ -1518,6 +1820,26 @@ class LambdaServiceTest {
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateEventSourceMapping_invalidLaterField_leavesBatchSizeAndEnabledUnchanged() {
|
||||
// Catches: UpdateEventSourceMapping mutating the stored mapping before a later member fails validation
|
||||
service.createFunction(REGION, baseRequest("kafka-fn-update-atomic"));
|
||||
EventSourceMapping esm = service.createEventSourceMapping(REGION, Map.of(
|
||||
"FunctionName", "kafka-fn-update-atomic",
|
||||
"Topics", List.of("valid-topic"),
|
||||
"SelfManagedEventSource", Map.of(
|
||||
"Endpoints", Map.of("KAFKA_BOOTSTRAP_SERVERS", List.of("localhost:9092")))));
|
||||
|
||||
assertThrows(AwsException.class, () -> service.updateEventSourceMapping(esm.getUuid(), Map.of(
|
||||
"BatchSize", 5,
|
||||
"Enabled", false,
|
||||
"FunctionResponseTypes", List.of("Bogus"))));
|
||||
|
||||
EventSourceMapping stored = service.getEventSourceMapping(esm.getUuid());
|
||||
assertEquals(10, stored.getBatchSize());
|
||||
assertTrue(stored.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateEventSourceMapping_functionTargetValidation() {
|
||||
service.createFunction(REGION, baseRequest("fn-esm-target-1"));
|
||||
@@ -1762,4 +2084,71 @@ class LambdaServiceTest {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfiguration_malformedKmsKeyArn_isRejectedAndNotStored() {
|
||||
// Catches: UpdateFunctionConfiguration storing a KMSKeyArn that violates the botocore pattern
|
||||
service.createFunction(REGION, baseRequest("kms-update-fn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.updateFunctionConfiguration(
|
||||
REGION, "kms-update-fn", new HashMap<>(Map.of("KMSKeyArn", "not-an-arn"))));
|
||||
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
assertNull(service.getFunction(REGION, "kms-update-fn").getKmsKeyArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAlias_invalidName_isRejectedAndNotStored() {
|
||||
// Catches: CreateAlias accepting an all-digit or over-128-character alias name
|
||||
service.createFunction(REGION, baseRequest("alias-name-fn"));
|
||||
|
||||
AwsException digits = assertThrows(AwsException.class,
|
||||
() -> service.createAlias(REGION, "alias-name-fn", "123", "$LATEST", null, null));
|
||||
AwsException tooLong = assertThrows(AwsException.class,
|
||||
() -> service.createAlias(REGION, "alias-name-fn", "a".repeat(129), "$LATEST", null, null));
|
||||
|
||||
assertEquals("ValidationException", digits.getErrorCode());
|
||||
assertEquals("ValidationException", tooLong.getErrorCode());
|
||||
assertEquals(0, service.listAliases(REGION, "alias-name-fn").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAlias_emptyOrMissingName_isRejected() {
|
||||
// Catches: CreateAlias accepting an empty or null alias name despite the 1-character minimum
|
||||
service.createFunction(REGION, baseRequest("alias-empty-fn"));
|
||||
|
||||
AwsException empty = assertThrows(AwsException.class,
|
||||
() -> service.createAlias(REGION, "alias-empty-fn", "", "$LATEST", null, null));
|
||||
AwsException missing = assertThrows(AwsException.class,
|
||||
() -> service.createAlias(REGION, "alias-empty-fn", null, "$LATEST", null, null));
|
||||
|
||||
assertEquals("ValidationException", empty.getErrorCode());
|
||||
assertEquals("ValidationException", missing.getErrorCode());
|
||||
assertEquals(0, service.listAliases(REGION, "alias-empty-fn").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createEventSourceMapping_malformedEventSourceArn_isRejectedAndNotStored() {
|
||||
// Catches: CreateEventSourceMapping accepting an ARN that only contains ":sqs:" but is not a valid ARN
|
||||
LambdaFunction fn = service.createFunction(REGION, baseRequest("esm-arn-fn"));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createEventSourceMapping(REGION,
|
||||
new HashMap<>(Map.of("FunctionName", "esm-arn-fn", "EventSourceArn", "junk:sqs:queue"))));
|
||||
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
assertEquals(0, service.listEventSourceMappings(fn.getFunctionArn()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunction_unknownPackageType_isRejectedAndNotStored() {
|
||||
// Catches: CreateFunction accepting a PackageType outside the Zip/Image enum
|
||||
Map<String, Object> request = baseRequest("package-type-fn");
|
||||
request.put("PackageType", "Rar");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createFunction(REGION, request));
|
||||
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
assertEquals("ResourceNotFoundException",
|
||||
assertThrows(AwsException.class, () -> service.getFunction(REGION, "package-type-fn")).getErrorCode());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user