mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix: resolve CloudFormation Lambda Code.S3Key base64 decode error (#62)
* fix: resolve CloudFormation Lambda Code.S3Key base64 decode error * fix: conflicts with main + 2 tests failing Signed-off-by: Hector Ventura <hectorvent@gmail.com> Co-authored-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
020a54642d
commit
78be5232e2
5 files changed
+307
-13
No files matched your search
+231
@@ -7,6 +7,12 @@ import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -28,6 +34,20 @@ class CloudFormationIntegrationTest {
|
||||
.encodeContentTypeAs(SSM_CONTENT_TYPE, ContentType.TEXT));
|
||||
}
|
||||
|
||||
private static byte[] buildHandlerZip() {
|
||||
try {
|
||||
var baos = new ByteArrayOutputStream();
|
||||
try (var zos = new ZipOutputStream(baos)) {
|
||||
zos.putNextEntry(new ZipEntry("index.js"));
|
||||
zos.write("exports.handler=async(e)=>({statusCode:200})".getBytes(StandardCharsets.UTF_8));
|
||||
zos.closeEntry();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_withS3AndSqs() {
|
||||
String template = """
|
||||
@@ -106,6 +126,217 @@ class CloudFormationIntegrationTest {
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_lambdaWithS3Code() {
|
||||
byte[] zipBytes = buildHandlerZip();
|
||||
|
||||
// Create S3 bucket
|
||||
given()
|
||||
.when()
|
||||
.put("/cfn-lambda-code-bucket")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Upload ZIP to S3
|
||||
given()
|
||||
.contentType("application/zip")
|
||||
.body(zipBytes)
|
||||
.when()
|
||||
.put("/cfn-lambda-code-bucket/handler.zip")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"MyFunction": {
|
||||
"Type": "AWS::Lambda::Function",
|
||||
"Properties": {
|
||||
"FunctionName": "cfn-s3code-func",
|
||||
"Runtime": "nodejs20.x",
|
||||
"Handler": "index.handler",
|
||||
"Code": {
|
||||
"S3Bucket": "cfn-lambda-code-bucket",
|
||||
"S3Key": "handler.zip"
|
||||
},
|
||||
"Role": "arn:aws:iam::000000000000:role/cfn-test-lambda-role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-s3code-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", "cfn-s3code-stack")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
|
||||
// Verify Lambda function was created
|
||||
given()
|
||||
.when()
|
||||
.get("/2015-03-31/functions/cfn-s3code-func")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Configuration.FunctionName", equalTo("cfn-s3code-func"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_lambdaWithNoCode() {
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"MyFunction": {
|
||||
"Type": "AWS::Lambda::Function",
|
||||
"Properties": {
|
||||
"FunctionName": "cfn-nocode-func",
|
||||
"Runtime": "nodejs20.x",
|
||||
"Handler": "index.handler",
|
||||
"Role": "arn:aws:iam::000000000000:role/cfn-test-lambda-role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-nocode-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", "cfn-nocode-stack")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/2015-03-31/functions/cfn-nocode-func")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Configuration.FunctionName", equalTo("cfn-nocode-func"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_lambdaWithImageUri() {
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"MyFunction": {
|
||||
"Type": "AWS::Lambda::Function",
|
||||
"Properties": {
|
||||
"FunctionName": "cfn-image-func",
|
||||
"Handler": "index.handler",
|
||||
"Code": {
|
||||
"ImageUri": "123456789012.dkr.ecr.us-east-1.amazonaws.com/my-repo:latest"
|
||||
},
|
||||
"Role": "arn:aws:iam::000000000000:role/cfn-test-lambda-role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-image-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", "cfn-image-stack")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_lambdaWithZipFile() {
|
||||
String base64Zip = Base64.getEncoder().encodeToString(buildHandlerZip());
|
||||
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"MyFunction": {
|
||||
"Type": "AWS::Lambda::Function",
|
||||
"Properties": {
|
||||
"FunctionName": "cfn-zipfile-func",
|
||||
"Runtime": "nodejs20.x",
|
||||
"Handler": "index.handler",
|
||||
"Code": {
|
||||
"ZipFile": "%s"
|
||||
},
|
||||
"Role": "arn:aws:iam::000000000000:role/cfn-test-lambda-role"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".formatted(base64Zip);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "cfn-zipfile-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", "cfn-zipfile-stack")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/2015-03-31/functions/cfn-zipfile-func")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Configuration.FunctionName", equalTo("cfn-zipfile-func"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_withDynamoDbGsiAndLsi() {
|
||||
String template = """
|
||||
|
||||
Reference in new issue
Block a user