Light, fluffy, and always free - The AWS Local Emulator alternative
fix(lambda): quote the model's FunctionName pattern in the validation error (#5487)
Hector Ventura32cb4b7b8b75
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.javaindex dcd00ef712..7fda84677e 100644--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java@@ -22,7 +22,9 @@ public final class LambdaArnUtils {private static final Pattern NAME_PATTERN = Pattern.compile("[a-zA-Z0-9-_]+");private static final int MAX_NAME_LENGTH = 64;private static final int MAX_TOTAL_LENGTH = 140;- private static final String NAME_REGEX = "(arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\\d{1}:)?"+ /** The model's {@code FunctionName} pattern, quoted in the ValidationException a bad name gets. */+ private static final String NAME_REGEX = "(arn:(aws[a-zA-Z-]*)?:lambda:)?"+ + "((eusc-)?[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\\d{1}:)?"+ "(\\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\\$LATEST|[a-zA-Z0-9-_]+))?";private static final Pattern ACCOUNT_PATTERN = Pattern.compile("\\d{12}");private static final Pattern QUALIFIER_PATTERN = Pattern.compile("\\$LATEST|[a-zA-Z0-9-_]+");diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.javaindex cfd8531893..ca4b7be16a 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.java@@ -85,6 +85,15 @@ class LambdaArnUtilsTest {assertEquals(maxLen, ref.name());}+ @Test+ void aBadNameQuotesTheModelsFunctionNamePattern() {+ AwsException ex = assertThrows(AwsException.class, () -> LambdaArnUtils.resolve("bad.name"));++ assertEquals("ValidationException", ex.getErrorCode());+ assertTrue(ex.getMessage().contains("((eusc-)?[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\\d{1}:)?"),+ ex.getMessage());+ }+@Testvoid resolveAccepts140CharPartialArn() {String name = "a".repeat(118);