fix(secretsmanager): refuse an unreadable rotation function reference with InvalidParameterException (#4768)

Follow-up from the review of #4709.

A RotationLambdaARN that Lambda's reference parser cannot read was refused
with Lambda's own error, InvalidParameterValueException for a malformed
reference or ValidationException for a name outside the FunctionName pattern.
Neither is an error RotateSecret declares: its four are ResourceNotFoundException,
InvalidParameterException, InternalServiceError and InvalidRequestException,
so an SDK client could not type the refusal. It is now Secrets Manager's
InvalidParameterException ("The parameter name or value is invalid.", HTTP 400),
with Lambda's explanation kept in the message.

The unit test that pinned the old code used a Region-prefixed partial ARN,
which Lambda's documented FunctionName pattern accepts even though Floci's
parser does not yet. It now uses references that are invalid under that
pattern too: an empty function name, a character the name pattern excludes,
and an empty qualifier. They cover both of Lambda's codes. An integration test
checks the error type on the wire.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-01 21:17:37 -05:00
1 parent 62bcfb95ed
commit 44e9b1600e
3 files changed
+57 -8

No files matched your search

@@ -12,6 +12,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -98,4 +99,27 @@ public class SecretsManagerRotationIntegrationTest {
assertTrue(hasTest, "Should invoke testSecret");
assertTrue(hasFinish, "Should invoke finishSecret");
}
@Test
void rotationFunctionReferenceLambdaCannotReadIsAnInvalidParameter() {
String secretName = "rotation-invalid-reference-secret";
given()
.header("X-Amz-Target", "secretsmanager.CreateSecret")
.contentType(SM_CONTENT_TYPE)
.body("{\"Name\": \"" + secretName + "\", \"SecretString\": \"initial-value\"}")
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("X-Amz-Target", "secretsmanager.RotateSecret")
.contentType(SM_CONTENT_TYPE)
.body("{\"SecretId\": \"" + secretName + "\", \"RotationLambdaARN\": \"rotator!\"}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterException"));
}
}
@@ -12,6 +12,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.ArrayList;
import java.util.List;
@@ -74,14 +75,25 @@ class SecretsManagerRotationInvokeAuthorizationTest {
verify(lambda, timeout(5000).atLeastOnce()).invoke(eq(REGION), eq(expected), any(byte[].class), any());
}
@Test
void referenceLambdaCannotReadIsRejectedBeforeTheCheck() {
/**
* Each reference is invalid under Lambda's documented {@code FunctionName} pattern, not only
* under Floci's parser: an empty name, a character the name pattern excludes, an empty qualifier.
* RotateSecret answers with its own {@code InvalidParameterException}, not Lambda's codes.
*/
@ParameterizedTest
@ValueSource(strings = {
"arn:aws:lambda:us-east-1:111122223333:function:",
"rotator!",
"rotator:"
})
void referenceLambdaCannotReadIsRejectedBeforeTheCheck(String reference) {
List<String> checked = new ArrayList<>();
AwsException e = assertThrows(AwsException.class, () -> service.rotateSecret("my-secret", TOKEN,
"us-east-1:111122223333:function:rotator", null, false, REGION, checked::add));
reference, null, false, REGION, checked::add));
assertEquals("InvalidParameterValueException", e.getErrorCode());
assertEquals("InvalidParameterException", e.getErrorCode());
assertEquals(400, e.getHttpStatus());
assertEquals(List.of(), checked);
assertNull(service.describeSecret("my-secret", REGION).getRotationLambdaArn());
}