Light, fluffy, and always free - The AWS Local Emulator alternative
fix(lambda): resolve handler paths with a leading "./" against the package (#1575)
Alex Banna0a806f7382d4
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.javaindex 3f65695d1d..0d75e3f874 100644--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java@@ -1201,6 +1201,12 @@ public class LambdaService {if (fn.getRuntime().startsWith("python")) {return modulePath.replace('.', '/');}+ // A file-based handler may be given with a leading "./" (e.g.+ // "./v1/lambda-handlers/entry.handler"); deployment-package entries are stored without+ // it, so normalize the prefix away before matching.+ if (modulePath.startsWith("./")) {+ modulePath = modulePath.substring(2);+ }return modulePath;}diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.javaindex 0803eae008..85cdb26d5b 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java@@ -279,6 +279,43 @@ class LambdaIntegrationTest {given().delete(BASE_PATH + "/functions/large-zip-fn");}+ @Test+ @Order(15)+ void createFunctionWithDotSlashNestedHandler() throws Exception {+ // A handler given with a leading "./" and a nested path (e.g.+ // "./v1/lambda-handlers/entry.handler") must resolve against the zip entry+ // "v1/lambda-handlers/entry.js" — the "./" prefix is normalized away.+ ByteArrayOutputStream baos = new ByteArrayOutputStream();+ try (ZipOutputStream zos = new ZipOutputStream(baos)) {+ zos.putNextEntry(new ZipEntry("v1/lambda-handlers/entry.js"));+ zos.write("exports.handler = async () => ({ ok: true });".getBytes());+ zos.closeEntry();+ }+ String base64Zip = Base64.getEncoder().encodeToString(baos.toByteArray());++ given()+ .contentType("application/json")+ .body("""+ {+ "FunctionName": "dotslash-fn",+ "Runtime": "nodejs20.x",+ "Role": "arn:aws:iam::000000000000:role/lambda-role",+ "Handler": "./v1/lambda-handlers/entry.handler",+ "Code": {+ "ZipFile": "%s"+ }+ }+ """.formatted(base64Zip))+ .when()+ .post(BASE_PATH + "/functions")+ .then()+ .statusCode(201)+ .body("FunctionName", equalTo("dotslash-fn"));++ // cleanup+ given().delete(BASE_PATH + "/functions/dotslash-fn");+ }+// ── ImageConfig ───────────────────────────────────────────────────────────@Test