refactor(ses): share the name length and character checks (#9034)

Template, configuration set, event destination, tenant and metric
dimension names each carried their own copy of the 64-character limit,
the [A-Za-z0-9_-]+ pattern and the sentence that quotes a refused name.
SesNames now holds the limit, the pattern and the two checks; each
caller passes its error code and wording and keeps its own blank check
and its own order of the two.

Contact list, topic and policy names, which have their own sentences,
ask SesNames's predicates in place of two more copies of the pattern.

No behaviour change.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-11-19 18:41:43 -04:00
1 parent dca36665b5
commit b8a74a2a67
8 files changed
+115 -61

No files matched your search

@@ -0,0 +1,54 @@
package io.floci.aws.services.ses;
import io.floci.aws.core.common.AwsException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SesNamesTest {
@Test
void hasOnlyAllowedCharacters_acceptsAsciiLettersDigitsUnderscoreAndHyphen() {
assertTrue(SesNames.hasOnlyAllowedCharacters("Name_probe-09"));
assertFalse(SesNames.hasOnlyAllowedCharacters("name probe"));
assertFalse(SesNames.hasOnlyAllowedCharacters("name.probe"));
assertFalse(SesNames.hasOnlyAllowedCharacters("name-probé"));
assertFalse(SesNames.hasOnlyAllowedCharacters(""));
}
@Test
void isValid_appliesTheLengthAndTheCharacters() {
assertTrue(SesNames.isValid("a".repeat(64)));
assertFalse(SesNames.isValid("a".repeat(65)));
assertFalse(SesNames.isValid("a b"));
assertFalse(SesNames.isValid(""));
}
@Test
void requireMaxLength_refusesTheSixtyFifthCharacterWithTheCallersWording() {
assertDoesNotThrow(() -> SesNames.requireMaxLength("a".repeat(64), "BadRequestException", "TenantName"));
AwsException e = assertThrows(AwsException.class,
() -> SesNames.requireMaxLength("a".repeat(65), "BadRequestException", "TenantName"));
assertEquals("BadRequestException", e.getErrorCode());
assertEquals("TenantName cannot exceed 64 characters.", e.getMessage());
assertEquals(400, e.getHttpStatus());
}
@Test
void requireAllowedCharacters_quotesTheNameAfterTheCallersWording() {
assertDoesNotThrow(
() -> SesNames.requireAllowedCharacters("a_b-1", "InvalidParameterValue", "Template name"));
AwsException e = assertThrows(AwsException.class,
() -> SesNames.requireAllowedCharacters("a b", "InvalidParameterValue", "Template name"));
assertEquals("InvalidParameterValue", e.getErrorCode());
assertEquals("Template name <a b>: only alphanumeric ASCII characters, '_', and '-' are allowed.",
e.getMessage());
assertEquals(400, e.getHttpStatus());
}
}