mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(lambda): add missing runtimes, fix handler validation, long path… (#256)
* feat(lambda): add missing runtimes, fix handler validation, long path extraction, and code signing config * fix: removed unrequired go.sum and package-lock.json from compatibility test
This commit is contained in:
1 parent
48b6ca3475
commit
0ef6f87cba
16 files changed
+477
-4026
No files matched your search
+74
@@ -0,0 +1,74 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
import software.amazon.awssdk.services.lambda.model.*;
|
||||
import software.amazon.awssdk.services.lambda.model.Runtime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Compatibility tests for GetFunctionCodeSigningConfig.
|
||||
*
|
||||
* Regression for https://github.com/floci-io/floci/issues/226:
|
||||
* The SDK calls GET /2020-06-30/functions/{name}/code-signing-config — a different
|
||||
* API version prefix than most Lambda endpoints (/2015-03-31). Without an explicit
|
||||
* route, Floci returned an HTML/XML 404 which the SDK failed to parse as JSON.
|
||||
*/
|
||||
@DisplayName("Lambda - GetFunctionCodeSigningConfig (issue #226)")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class LambdaCodeSigningTest {
|
||||
|
||||
private static final String FUNCTION_NAME = "sdk-test-code-signing-fn";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/lambda-role";
|
||||
|
||||
private static LambdaClient lambda;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
lambda = TestFixtures.lambdaClient();
|
||||
lambda.createFunction(CreateFunctionRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.runtime(Runtime.NODEJS20_X)
|
||||
.role(ROLE)
|
||||
.handler("index.handler")
|
||||
.code(FunctionCode.builder()
|
||||
.zipFile(SdkBytes.fromByteArray(LambdaUtils.minimalZip()))
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (lambda != null) {
|
||||
try {
|
||||
lambda.deleteFunction(DeleteFunctionRequest.builder()
|
||||
.functionName(FUNCTION_NAME).build());
|
||||
} catch (Exception ignored) {}
|
||||
lambda.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void getFunctionCodeSigningConfig_existingFunction_returnsEmptyArn() {
|
||||
GetFunctionCodeSigningConfigResponse response = lambda.getFunctionCodeSigningConfig(
|
||||
GetFunctionCodeSigningConfigRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.build());
|
||||
|
||||
assertThat(response.functionName()).isEqualTo(FUNCTION_NAME);
|
||||
assertThat(response.codeSigningConfigArn()).isNullOrEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getFunctionCodeSigningConfig_unknownFunction_throws404() {
|
||||
assertThatThrownBy(() -> lambda.getFunctionCodeSigningConfig(
|
||||
GetFunctionCodeSigningConfigRequest.builder()
|
||||
.functionName("does-not-exist")
|
||||
.build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.floci.test;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
import software.amazon.awssdk.services.lambda.model.*;
|
||||
import software.amazon.awssdk.services.lambda.model.Runtime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Regression test for https://github.com/floci-io/floci/issues/232
|
||||
*
|
||||
* Lambda zip extraction was truncating file paths at 99 characters due to the
|
||||
* legacy POSIX USTAR tar header name field limit in the hand-rolled tar writer.
|
||||
* Files with paths longer than 99 chars were silently renamed to their truncated
|
||||
* form, causing "cannot load such file" errors at runtime.
|
||||
*/
|
||||
@DisplayName("Lambda - Long file path in ZIP (issue #232)")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class LambdaLongPathTest {
|
||||
|
||||
private static final String FUNCTION_NAME = "sdk-test-long-path-fn";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/lambda-role";
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private static LambdaClient lambda;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
lambda = TestFixtures.lambdaClient();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (lambda != null) {
|
||||
try {
|
||||
lambda.deleteFunction(DeleteFunctionRequest.builder()
|
||||
.functionName(FUNCTION_NAME).build());
|
||||
} catch (Exception ignored) {}
|
||||
lambda.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createFunctionWithLongPathZip() {
|
||||
CreateFunctionResponse response = lambda.createFunction(CreateFunctionRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.runtime(Runtime.NODEJS20_X)
|
||||
.role(ROLE)
|
||||
.handler("index.handler")
|
||||
.timeout(30)
|
||||
.memorySize(256)
|
||||
.code(FunctionCode.builder()
|
||||
.zipFile(SdkBytes.fromByteArray(LambdaUtils.longPathZip()))
|
||||
.build())
|
||||
.build());
|
||||
|
||||
assertThat(response.functionName()).isEqualTo(FUNCTION_NAME);
|
||||
assertThat(response.stateAsString()).isEqualTo("Active");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void longPathFileIsAccessibleAtRuntime() throws Exception {
|
||||
InvokeResponse response = lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.invocationType(InvocationType.REQUEST_RESPONSE)
|
||||
.payload(SdkBytes.fromUtf8String("{}"))
|
||||
.build());
|
||||
|
||||
assertThat(response.statusCode()).isEqualTo(200);
|
||||
assertThat(response.functionError()).isNull();
|
||||
|
||||
String payload = response.payload().asUtf8String();
|
||||
JsonNode result = MAPPER.readTree(payload);
|
||||
|
||||
assertThat(result.get("exists").asBoolean())
|
||||
.as("File at path >99 chars must exist inside the container — was it truncated during zip extraction?")
|
||||
.isTrue();
|
||||
assertThat(result.get("pathLength").asInt())
|
||||
.isEqualTo(128); // /var/task/ (10) + relative path (118 chars) — well above the 99-char USTAR limit
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,46 @@ public final class LambdaUtils {
|
||||
return createZip("index.js", code);
|
||||
}
|
||||
|
||||
/**
|
||||
* ZIP containing a Node.js handler that checks whether a file at a deeply nested
|
||||
* long path (> 100 chars) exists inside the container.
|
||||
*
|
||||
* Used to test that zip extraction correctly preserves long file paths.
|
||||
* Regression test for: https://github.com/floci-io/floci/issues/232
|
||||
*
|
||||
* The nested file path is intentionally > 99 characters to exceed the legacy
|
||||
* POSIX USTAR tar header name field limit, which is where truncation occurred.
|
||||
*/
|
||||
public static byte[] longPathZip() {
|
||||
// Relative path is 117 chars — well over the 99-char USTAR limit
|
||||
String longPath = "vendor/bundle/ruby/3.3.0/gems/bundler-4.0.3/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.txt";
|
||||
String handler = """
|
||||
const fs = require('fs');
|
||||
exports.handler = async () => {
|
||||
const longPath = '/var/task/%s';
|
||||
const exists = fs.existsSync(longPath);
|
||||
return { exists, pathLength: longPath.length };
|
||||
};
|
||||
""".formatted(longPath);
|
||||
String fileContent = "present";
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
zos.putNextEntry(new ZipEntry("index.js"));
|
||||
zos.write(handler.getBytes(StandardCharsets.UTF_8));
|
||||
zos.closeEntry();
|
||||
|
||||
zos.putNextEntry(new ZipEntry(longPath));
|
||||
zos.write(fileContent.getBytes(StandardCharsets.UTF_8));
|
||||
zos.closeEntry();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to build long-path ZIP", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] createZip(String filename, String content) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
Reference in new issue
Block a user