mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): preserve alias identity in qualified reads (#6757)
Preserve the requested alias ARN while returning the resolved published version configuration. Retain snapshot-versus-latest regressions for both read APIs. Signed-off-by: Andre Kurait <akurait@amazon.com> Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
65df465fc3
commit
0332b5cc24
4 files changed
+144
-11
No files matched your search
+71
-8
@@ -4,6 +4,8 @@ import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
@@ -12,6 +14,7 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Issue #2821: GetFunction and GetFunctionConfiguration ignored Qualifier and answered with
|
||||
@@ -25,6 +28,61 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
@QuarkusTest
|
||||
class LambdaQualifiedReadIntegrationTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"name, true", "name, false",
|
||||
"arn, true", "arn, false",
|
||||
"partial, true", "partial, false"
|
||||
})
|
||||
void aliasReadsKeepTheRequestedArnAndResolvedVersion(String form, boolean query) throws Exception {
|
||||
String fn = "alias-identity-" + Long.toString(System.nanoTime(), 36);
|
||||
createFunction(fn, "published");
|
||||
try {
|
||||
String arn = given().when().get("/2015-03-31/functions/" + fn)
|
||||
.then().statusCode(200).extract().path("Configuration.FunctionArn");
|
||||
String publishedHash = given().contentType("application/json").body("{}")
|
||||
.when().post("/2015-03-31/functions/" + fn + "/versions")
|
||||
.then().statusCode(201).body("Version", equalTo("1"))
|
||||
.extract().path("CodeSha256");
|
||||
String aliasArn = given().contentType("application/json")
|
||||
.body("{\"Name\":\"stable\",\"FunctionVersion\":\"1\"}")
|
||||
.when().post("/2015-03-31/functions/" + fn + "/aliases")
|
||||
.then().statusCode(anyOf200Or201()).extract().path("AliasArn");
|
||||
String latestHash = given().contentType("application/json")
|
||||
.body("{\"ZipFile\": \"%s\"}".formatted(zipB64("latest")))
|
||||
.when().put("/2015-03-31/functions/" + fn + "/code")
|
||||
.then().statusCode(200).extract().path("CodeSha256");
|
||||
assertNotEquals(publishedHash, latestHash);
|
||||
String reference = switch (form) {
|
||||
case "arn" -> arn;
|
||||
case "partial" -> "000000000000:function:" + fn;
|
||||
default -> fn;
|
||||
};
|
||||
String path = "/2015-03-31/functions/" + reference + (query ? "" : ":stable");
|
||||
String suffix = query ? "?Qualifier=stable" : "";
|
||||
given().when().get(path + suffix).then().statusCode(200)
|
||||
.body("Configuration.FunctionArn", equalTo(aliasArn))
|
||||
.body("Configuration.Version", equalTo("1"))
|
||||
.body("Configuration.CodeSha256", equalTo(publishedHash));
|
||||
given().when().get(path + "/configuration" + suffix).then().statusCode(200)
|
||||
.body("FunctionArn", equalTo(aliasArn))
|
||||
.body("Version", equalTo("1"))
|
||||
.body("CodeSha256", equalTo(publishedHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn + ":1").then().statusCode(200)
|
||||
.body("Configuration.FunctionArn", equalTo(arn + ":1"))
|
||||
.body("Configuration.Version", equalTo("1"))
|
||||
.body("Configuration.CodeSha256", equalTo(publishedHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn).then().statusCode(200)
|
||||
.body("Configuration.FunctionArn", equalTo(arn))
|
||||
.body("Configuration.Version", equalTo("$LATEST"))
|
||||
.body("Configuration.CodeSha256", equalTo(latestHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn + "/configuration")
|
||||
.then().statusCode(200).body("CodeSha256", equalTo(latestHash));
|
||||
} finally {
|
||||
given().when().delete("/2015-03-31/functions/" + fn).then().statusCode(204);
|
||||
}
|
||||
}
|
||||
|
||||
private static String zipB64(String body) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
@@ -59,30 +117,35 @@ class LambdaQualifiedReadIntegrationTest {
|
||||
String fn = "qual-read-" + Long.toString(System.nanoTime(), 36);
|
||||
createFunction(fn, "v1");
|
||||
|
||||
given().contentType("application/json").body("{}")
|
||||
String publishedHash = given().contentType("application/json").body("{}")
|
||||
.when().post("/2015-03-31/functions/" + fn + "/versions")
|
||||
.then().statusCode(201).body("Version", equalTo("1"));
|
||||
.then().statusCode(201).body("Version", equalTo("1")).extract().path("CodeSha256");
|
||||
|
||||
// $LATEST moves on past version 1.
|
||||
given()
|
||||
String latestHash = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"ZipFile\": \"%s\"}".formatted(zipB64("v2")))
|
||||
.when()
|
||||
.put("/2015-03-31/functions/" + fn + "/code")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
.statusCode(200).extract().path("CodeSha256");
|
||||
assertNotEquals(publishedHash, latestHash);
|
||||
|
||||
given().when().get("/2015-03-31/functions/" + fn + "?Qualifier=1")
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("1"));
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("1"))
|
||||
.body("Configuration.CodeSha256", equalTo(publishedHash));
|
||||
|
||||
given().when().get("/2015-03-31/functions/" + fn + "/configuration?Qualifier=1")
|
||||
.then().statusCode(200).body("Version", equalTo("1"));
|
||||
.then().statusCode(200).body("Version", equalTo("1"))
|
||||
.body("CodeSha256", equalTo(publishedHash));
|
||||
|
||||
// Unqualified and an explicit $LATEST both still mean $LATEST.
|
||||
given().when().get("/2015-03-31/functions/" + fn)
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"));
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"))
|
||||
.body("Configuration.CodeSha256", equalTo(latestHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn + "?Qualifier=$LATEST")
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"));
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"))
|
||||
.body("Configuration.CodeSha256", equalTo(latestHash));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user