mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): refuse a log level under Text as Lambda does (#5920)
Floci accepted ApplicationLogLevel and SystemLogLevel under Text and dropped them, which a test pinned and the docs described as Floci's own call rather than probed behaviour. Measured on Lambda (eu-west-1, 2026-10-18): CreateFunction and UpdateFunctionConfiguration refuse either level under Text, whether LogFormat names Text or is left to that default, with InvalidParameterValueException "LogLevel is not supported when LogFormat is set to "Text". Remove LogLevel from your request or change the LogFormat to "JSON" and try again." In a stack, a valid level under Text passes the template's validation and fails the resource with Lambda's message. Floci now refuses it in validateLoggingConfig, so the API and the CloudFormation update check, which validates through loggingSettings, both do; and its enum errors list the levels in Lambda's order: [FATAL, TRACE, WARN, ERROR, INFO, DEBUG] and [WARN, INFO, DEBUG]. The default format is worked out in one place, logFormat, for the validation and for loggingSettings. Tests: a level under Text refused on create and on update through the API (LambdaVpcSnapStartLoggingIntegrationTest, replacing the test that pinned the old behaviour) and through the SDK (LambdaFunctionConfigTest), by loggingSettings (LambdaServiceTest), and by a stack update (CloudFormationLambdaLoggingConfigIntegrationTest); the enum messages' order. They fail on main.
This commit is contained in:
1 parent
5a4413d63a
commit
d425e2d884
6 files changed
+163
-48
No files matched your search
+26
@@ -98,6 +98,32 @@ class CloudFormationLambdaLoggingConfigIntegrationTest {
|
||||
.body("LoggingConfig.ApplicationLogLevel", nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Measured on CloudFormation (eu-west-1, 2026-10-18): a valid log level under Text passes the
|
||||
* template's validation but Lambda refuses it, so the update fails and the function keeps its
|
||||
* configuration.
|
||||
*/
|
||||
@Test
|
||||
void aLogLevelUnderTextFailsTheUpdate() {
|
||||
String stackName = "cfn-lambda-logging-text-level-" + Long.toString(System.nanoTime(), 36);
|
||||
registerDeletion(stackName);
|
||||
deploy("CreateStack", stackName, template(""));
|
||||
String created = functionName(stackName);
|
||||
|
||||
submit("UpdateStack", stackName, template("""
|
||||
,"LoggingConfig": {"LogFormat": "Text", "ApplicationLogLevel": "WARN"}
|
||||
"""));
|
||||
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName);
|
||||
assertNotEquals("UPDATE_COMPLETE", state.status(), state.reason());
|
||||
given()
|
||||
.when()
|
||||
.get(LAMBDA + created + "/configuration")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("LoggingConfig.LogFormat", equalTo("Text"))
|
||||
.body("LoggingConfig.ApplicationLogLevel", nullValue());
|
||||
}
|
||||
|
||||
private void registerDeletion(String stackName) {
|
||||
cleanup.register(() -> {
|
||||
submit("DeleteStack", stackName, null);
|
||||
|
||||
@@ -3014,7 +3014,9 @@ class LambdaServiceTest {
|
||||
assertEquals(new LambdaService.LoggingSettings("JSON", null, null, null),
|
||||
LambdaService.loggingSettings(Map.of(), true));
|
||||
assertEquals(new LambdaService.LoggingSettings("Text", null, null, "/shared/app"),
|
||||
LambdaService.loggingSettings(Map.of("ApplicationLogLevel", "WARN", "LogGroup", "/shared/app"), false));
|
||||
LambdaService.loggingSettings(Map.of("LogGroup", "/shared/app"), false));
|
||||
assertEquals(new LambdaService.LoggingSettings("JSON", "WARN", null, null),
|
||||
LambdaService.loggingSettings(Map.of("ApplicationLogLevel", "WARN"), true));
|
||||
assertEquals(new LambdaService.LoggingSettings("JSON", "WARN", null, null),
|
||||
LambdaService.loggingSettings(Map.of("LogFormat", "JSON", "ApplicationLogLevel", "WARN",
|
||||
"LogGroup", ""), false));
|
||||
@@ -3028,6 +3030,21 @@ class LambdaServiceTest {
|
||||
assertEquals("ValidationException", refused.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggingSettingsRefuseALogLevelUnderText() {
|
||||
for (Map<String, String> logging : List.of(
|
||||
Map.of("LogFormat", "Text", "ApplicationLogLevel", "WARN"),
|
||||
Map.of("LogFormat", "Text", "SystemLogLevel", "WARN"),
|
||||
Map.of("ApplicationLogLevel", "WARN"))) {
|
||||
AwsException refused = assertThrows(AwsException.class,
|
||||
() -> LambdaService.loggingSettings(logging, false), logging.toString());
|
||||
|
||||
assertEquals("InvalidParameterValueException", refused.getErrorCode());
|
||||
assertEquals("LogLevel is not supported when LogFormat is set to \"Text\". Remove LogLevel from your "
|
||||
+ "request or change the LogFormat to \"JSON\" and try again.", refused.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFunctionsLoggingSettingsFillInItsDefaultFormat() {
|
||||
LambdaFunction fn = new LambdaFunction();
|
||||
|
||||
+57
-22
@@ -32,6 +32,8 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
|
||||
private static final String BASE_PATH = "/2015-03-31";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String SECURITY_GROUP_ID = "sg-0123456789abcdef0";
|
||||
private static final String LOG_LEVEL_UNDER_TEXT = "LogLevel is not supported when LogFormat is set to \"Text\". "
|
||||
+ "Remove LogLevel from your request or change the LogFormat to \"JSON\" and try again.";
|
||||
|
||||
@Inject
|
||||
Ec2Service ec2Service;
|
||||
@@ -389,7 +391,7 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("1 validation error detected: Value 'VERBOSE' at "
|
||||
+ "'loggingConfig.applicationLogLevel' failed to satisfy constraint: Member must satisfy "
|
||||
+ "enum value set: [TRACE, DEBUG, INFO, WARN, ERROR, FATAL]"));
|
||||
+ "enum value set: [FATAL, TRACE, WARN, ERROR, INFO, DEBUG]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -412,7 +414,60 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("1 validation error detected: Value 'TRACE' at "
|
||||
+ "'loggingConfig.systemLogLevel' failed to satisfy constraint: Member must satisfy "
|
||||
+ "enum value set: [DEBUG, INFO, WARN]"));
|
||||
+ "enum value set: [WARN, INFO, DEBUG]"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Measured on Lambda (eu-west-1, 2026-10-18): a log level under Text, the format named or left
|
||||
* to its default, is refused, whichever of the two levels it is.
|
||||
*/
|
||||
@Test
|
||||
void aLogLevelUnderTextIsRefusedOnCreate() {
|
||||
for (String loggingConfig : List.of(
|
||||
"{\"LogFormat\": \"Text\", \"ApplicationLogLevel\": \"WARN\"}",
|
||||
"{\"LogFormat\": \"Text\", \"SystemLogLevel\": \"WARN\"}",
|
||||
"{\"ApplicationLogLevel\": \"WARN\"}")) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "logging-text-level-fn",
|
||||
"Runtime": "nodejs20.x",
|
||||
"Role": "arn:aws:iam::000000000000:role/lambda-role",
|
||||
"Handler": "index.handler",
|
||||
"LoggingConfig": %s
|
||||
}
|
||||
""".formatted(loggingConfig))
|
||||
.when()
|
||||
.post(BASE_PATH + "/functions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterValueException"))
|
||||
.body("message", equalTo(LOG_LEVEL_UNDER_TEXT));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLogLevelUnderTextIsRefusedOnUpdateAndTheFunctionKeepsItsLogging() {
|
||||
createFunction("logging-text-level-update-fn", "");
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"LoggingConfig\": {\"ApplicationLogLevel\": \"WARN\"}}")
|
||||
.when()
|
||||
.put(BASE_PATH + "/functions/logging-text-level-update-fn/configuration")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterValueException"))
|
||||
.body("message", equalTo(LOG_LEVEL_UNDER_TEXT));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get(BASE_PATH + "/functions/logging-text-level-update-fn/configuration")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("LoggingConfig.LogFormat", equalTo("Text"))
|
||||
.body("LoggingConfig.ApplicationLogLevel", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -496,26 +551,6 @@ class LambdaVpcSnapStartLoggingIntegrationTest {
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void textFormatLogLevelsAreAcceptedButNeverStoredOrReturned() {
|
||||
createFunction("logging-text-levels-fn", """
|
||||
,
|
||||
"LoggingConfig": {
|
||||
"LogFormat": "Text",
|
||||
"ApplicationLogLevel": "DEBUG",
|
||||
"SystemLogLevel": "WARN"
|
||||
}""");
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get(BASE_PATH + "/functions/logging-text-levels-fn/configuration")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("LoggingConfig.LogFormat", equalTo("Text"))
|
||||
.body("LoggingConfig.ApplicationLogLevel", nullValue())
|
||||
.body("LoggingConfig.SystemLogLevel", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionConfigurationDetachesVpcConfigAndClearsVpcId() {
|
||||
createFunction("vpc-detach-fn", vpcConfigJson());
|
||||
|
||||
Reference in new issue
Block a user