mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): support account aliases (#2103)
* feat(iam): support account aliases Implement ListAccountAliases, CreateAccountAlias and DeleteAccountAlias. An account holds at most one alias: creating a second returns EntityAlreadyExists, and deleting requires the current alias by name so a stale value cannot silently clear it. FLOCI_SERVICES_IAM_ACCOUNT_ALIAS seeds an alias at startup for callers that expect to read one without creating it first. Closes #2101 * fix(iam): make account alias create and delete atomic Concurrent CreateAccountAlias calls could all pass the emptiness check and write, reporting success to every caller while keeping only one value. Unlike a named resource, where racing creates carry the same name and either winner is equivalent, racing alias creates carry different values, so a loser is told their alias was set when another is stored. Guard the check-then-write on both create and delete, and cover it with a concurrency trial asserting exactly one winner. Also track the alias created by the bats delete case in ACCOUNT_ALIAS so teardown clears it if the test fails midway. * fix(iam): match verified AWS account alias semantics and unbreak the test fixture IamServiceTestHelper resolves the package-private IamService constructor reflectively against a hardcoded parameter list, so the extra storage backend broke it at run time with no compile-time signal. Every test using that fixture errored, and one of them hangs on a socket read rather than failing, which is what exhausted the CI job. Extend both lookups to the new arity. Checking the error message against a live AWS account showed the operation itself was modelled wrongly: CreateAccountAlias does not reject a second alias, it replaces the current one. EntityAlreadyExists means the requested name is taken, which for a single-account store is only the alias already held. Create now replaces and rejects just that case, which also makes the message name the alias the caller asked for. DeleteAccountAlias applies the same pattern constraint as create, so a malformed value is a ValidationError. Concurrent creates therefore all succeed with last-write-wins; the trial now asserts the store settles on one of the requested values. Seeding logs when it skips because an alias is already stored, which is otherwise invisible under persistent storage. * fix(test): repair iam.bats after the merge fused test bodies Resolving the merge by keeping both sides concatenated the OIDC and account alias cases as text, which left the create_oidc_provider helper nested inside an alias test and dropped a closing brace, so bats could not parse the file and produced no report at all. Rebuild it from main plus the alias cases, with the alias tracked in setup and teardown. * test(iam): pin account alias isolation, and document the two-dash rule The alias is the only IAM entity keyed by a constant rather than a caller-supplied name, so every account shares one storage key and the separation rests entirely on AccountAwareStorageBackend prefixing. Every integration test here signs as the same account, so that prefixing was never exercised for aliases. The new case pins it: handing both services the store unwrapped fails it. The docs still described the pre-fix constraint. They now carry the consecutive-hyphen rule and note that the ValidationError message, reproduced from AWS verbatim, does not itself mention it. --------- Co-authored-by: Michal Schreiber <michal.p.schreiber@gmail.com> Co-authored-by: Michal Schreiber <michal.schreiber@benefitsystems.pl>
This commit is contained in:
12 files changed
+727
-4
No files matched your search
+202
@@ -0,0 +1,202 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryController;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
|
||||
/**
|
||||
* Integration tests for IAM account aliases via the Query Protocol, covering the full HTTP stack
|
||||
* through {@link AwsQueryController} → {@link IamQueryHandler}.
|
||||
*
|
||||
* <p>Ordered: the alias is a single per-account value, so these cases share state deliberately —
|
||||
* empty list, create, read back, reject a second create, reject a mismatched delete, delete.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class IamAccountAliasIntegrationTest {
|
||||
|
||||
private static final String ALIAS = "floci-test-alias";
|
||||
|
||||
// The Query-protocol controller resolves the target service from the credential scope,
|
||||
// so every IAM call carries one.
|
||||
private static final String IAM_CREDENTIAL =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void listAccountAliasesIsEmptyBeforeAnyCreate() {
|
||||
given()
|
||||
.formParam("Action", "ListAccountAliases")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml")
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.AccountAliases", isEmptyOrNullString())
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.IsTruncated", equalTo("false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createAccountAlias() {
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", ALIAS)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listAccountAliasesReturnsTheCreatedAlias() {
|
||||
given()
|
||||
.formParam("Action", "ListAccountAliases")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.AccountAliases.member", equalTo(ALIAS))
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.IsTruncated", equalTo("false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void creatingAnotherAliasReplacesTheCurrentOne() {
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", "another-alias")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.formParam("Action", "ListAccountAliases")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.AccountAliases.member",
|
||||
equalTo("another-alias"));
|
||||
|
||||
// Restore the alias the later ordered cases expect.
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", ALIAS)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void recreatingTheHeldAliasIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", ALIAS)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("EntityAlreadyExists"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void deleteWithAMalformedAliasIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAccountAlias")
|
||||
.formParam("AccountAlias", "Bad_Alias")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void deleteWithMismatchedAliasIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAccountAlias")
|
||||
.formParam("AccountAlias", "not-the-current-alias")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deleteAccountAlias() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAccountAlias")
|
||||
.formParam("AccountAlias", ALIAS)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.formParam("Action", "ListAccountAliases")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.AccountAliases", isEmptyOrNullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void deleteWhenNoAliasIsSetIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAccountAlias")
|
||||
.formParam("AccountAlias", ALIAS)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"ab", "-leading-hyphen", "trailing-hyphen-", "Upper-Case", "has_underscore"})
|
||||
@Order(8)
|
||||
void malformedAliasesAreRejected(String alias) {
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", alias)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
|
||||
}
|
||||
}
|
||||
@@ -296,6 +296,56 @@ class IamConcurrencyTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating a free alias replaces whatever is set, so concurrent creates of different aliases
|
||||
* all succeed and the last write wins — that is AWS behaviour, not a race to be prevented.
|
||||
* What must hold is that the store ends on exactly one of the requested values rather than a
|
||||
* torn or absent one.
|
||||
*/
|
||||
@Test
|
||||
void concurrentAccountAliasCreatesLeaveOneRequestedValue() throws Exception {
|
||||
ExecutorService pool = Executors.newFixedThreadPool(THREADS);
|
||||
try {
|
||||
for (int trial = 0; trial < TRIALS; trial++) {
|
||||
IamService iam = newIamService();
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
CountDownLatch done = new CountDownLatch(N);
|
||||
List<String> winners = new CopyOnWriteArrayList<>();
|
||||
List<String> unexpected = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
String alias = "alias-" + i;
|
||||
pool.execute(() -> {
|
||||
try {
|
||||
start.await(10, TimeUnit.SECONDS);
|
||||
iam.createAccountAlias(alias);
|
||||
winners.add(alias);
|
||||
} catch (io.github.hectorvent.floci.core.common.AwsException e) {
|
||||
if (!"EntityAlreadyExists".equals(e.getErrorCode())) {
|
||||
unexpected.add(e.getErrorCode());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
done.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
start.countDown();
|
||||
assertTrue(done.await(30, TimeUnit.SECONDS), "alias workers stalled");
|
||||
|
||||
String stored = iam.getAccountAlias().orElse(null);
|
||||
if (winners.size() != N || stored == null || !winners.contains(stored)
|
||||
|| !unexpected.isEmpty()) {
|
||||
fail("accountAlias trial " + trial + ": winners=" + winners.size() + "/" + N
|
||||
+ " stored=" + stored + " unexpectedErrors=" + unexpected);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] createPolicies(IamService iam, String prefix) {
|
||||
String[] arns = new String[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
|
||||
+30
@@ -292,4 +292,34 @@ class IamManagedPolicyAccountScopeTest {
|
||||
assertTrue(caller.identityPolicies().contains(AwsManagedPolicies.PERMISSIVE_DOCUMENT));
|
||||
assertEquals(AwsManagedPolicies.PERMISSIVE_DOCUMENT, caller.boundaryPolicyDocument());
|
||||
}
|
||||
/**
|
||||
* The alias is the only IAM entity keyed by a constant rather than a caller-supplied name, so
|
||||
* every account shares one storage key and the separation rests entirely on
|
||||
* AccountAwareStorageBackend prefixing. The failure mode is two-sided and quiet: one account
|
||||
* would read another's alias, and would also be refused an alias it never set.
|
||||
*/
|
||||
@Test
|
||||
void accountAliasIsScopedToTheCallingAccount() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
IamService defaultAccount = serviceWithAliases(
|
||||
new AccountAwareStorageBackend<>(raw, requestContextFor(DEFAULT_ACCT), DEFAULT_ACCT));
|
||||
IamService otherAccount = serviceWithAliases(
|
||||
new AccountAwareStorageBackend<>(raw, requestContextFor(REQUEST_ACCT), DEFAULT_ACCT));
|
||||
|
||||
defaultAccount.createAccountAlias("acct-one");
|
||||
|
||||
assertTrue(otherAccount.getAccountAlias().isEmpty(), "the other account must not see it");
|
||||
otherAccount.createAccountAlias("acct-two");
|
||||
assertEquals("acct-one", defaultAccount.getAccountAlias().orElseThrow());
|
||||
assertEquals("acct-two", otherAccount.getAccountAlias().orElseThrow());
|
||||
}
|
||||
|
||||
private static IamService serviceWithAliases(AccountAwareStorageBackend<String> aliases) {
|
||||
return new IamService(
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
aliases, new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new RegionResolver("us-east-1", DEFAULT_ACCT), false, null);
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Verifies that {@code floci.services.iam.account-alias} seeds the alias at startup, so callers
|
||||
* that read an account alias find one without creating it first.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(IamSeededAccountAliasIntegrationTest.SeededAliasProfile.class)
|
||||
class IamSeededAccountAliasIntegrationTest {
|
||||
|
||||
private static final String SEEDED_ALIAS = "seeded-alias";
|
||||
|
||||
private static final String IAM_CREDENTIAL =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request";
|
||||
|
||||
public static class SeededAliasProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of("floci.services.iam.account-alias", SEEDED_ALIAS);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void configuredAliasIsSeededAtStartup() {
|
||||
given()
|
||||
.formParam("Action", "ListAccountAliases")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.AccountAliases.member",
|
||||
equalTo(SEEDED_ALIAS));
|
||||
}
|
||||
|
||||
@Test
|
||||
void recreatingTheSeededAliasIsRejected() {
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", SEEDED_ALIAS)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("EntityAlreadyExists"));
|
||||
}
|
||||
|
||||
/** A seeded alias is ordinary state, so a later create replaces it like any other. */
|
||||
@Test
|
||||
void creatingAnotherAliasReplacesTheSeededOne() {
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", "replacement-alias")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.formParam("Action", "ListAccountAliases")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ListAccountAliasesResponse.ListAccountAliasesResult.AccountAliases.member",
|
||||
equalTo("replacement-alias"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "CreateAccountAlias")
|
||||
.formParam("AccountAlias", SEEDED_ALIAS)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -92,10 +92,12 @@ class IamServicePersistenceTest {
|
||||
load(dir, "iam-access-keys.json", new TypeReference<Map<String, AccessKey>>() {}),
|
||||
load(dir, "iam-instance-profiles.json", new TypeReference<Map<String, InstanceProfile>>() {}),
|
||||
load(dir, "iam-sessions.json", new TypeReference<Map<String, SessionCredential>>() {}),
|
||||
load(dir, "iam-account-aliases.json", new TypeReference<Map<String, String>>() {}),
|
||||
load(dir, "iam-oidc-providers.json", new TypeReference<Map<String, OpenIDConnectProvider>>() {}),
|
||||
load(dir, "iam-slr-deletions.json", new TypeReference<Map<String, String>>() {}),
|
||||
new RegionResolver("us-east-1", "000000000000"),
|
||||
false);
|
||||
false,
|
||||
null);
|
||||
}
|
||||
|
||||
private <V> StorageBackend<String, V> load(Path dir, String file, TypeReference<Map<String, V>> type) {
|
||||
|
||||
@@ -1073,4 +1073,111 @@ class IamServiceTest {
|
||||
assertEquals(1, remaining.size());
|
||||
assertEquals("platform", remaining.get("team"));
|
||||
}
|
||||
// =========================================================================
|
||||
// Account Aliases
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void createAndGetAccountAlias() {
|
||||
assertTrue(iamService.getAccountAlias().isEmpty());
|
||||
|
||||
iamService.createAccountAlias("my-account");
|
||||
|
||||
assertEquals("my-account", iamService.getAccountAlias().orElseThrow());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verified against a live AWS account: creating a free alias while another is set replaces it
|
||||
* rather than failing, which is how the one-alias-per-account rule is actually enforced.
|
||||
*/
|
||||
@Test
|
||||
void createAccountAliasReplacesAnExistingOne() {
|
||||
iamService.createAccountAlias("my-account");
|
||||
|
||||
iamService.createAccountAlias("other-account");
|
||||
|
||||
assertEquals("other-account", iamService.getAccountAlias().orElseThrow());
|
||||
}
|
||||
|
||||
/** Re-creating the alias the account already holds is the case AWS rejects. */
|
||||
@Test
|
||||
void createAccountAliasRejectsTheAliasAlreadyHeld() {
|
||||
iamService.createAccountAlias("my-account");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.createAccountAlias("my-account"));
|
||||
assertEquals("EntityAlreadyExists", ex.getErrorCode());
|
||||
assertTrue(ex.getMessage().contains("my-account"));
|
||||
assertEquals("my-account", iamService.getAccountAlias().orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAccountAliasRejectsAMalformedValue() {
|
||||
iamService.createAccountAlias("my-account");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.deleteAccountAlias("Bad_Alias"));
|
||||
assertEquals("ValidationError", ex.getErrorCode());
|
||||
assertEquals("my-account", iamService.getAccountAlias().orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAccountAlias() {
|
||||
iamService.createAccountAlias("my-account");
|
||||
|
||||
iamService.deleteAccountAlias("my-account");
|
||||
|
||||
assertTrue(iamService.getAccountAlias().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAccountAliasWithMismatchedNameFails() {
|
||||
iamService.createAccountAlias("my-account");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.deleteAccountAlias("some-other-alias"));
|
||||
assertEquals("NoSuchEntity", ex.getErrorCode());
|
||||
assertEquals("my-account", iamService.getAccountAlias().orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAccountAliasWhenNoneSetFails() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.deleteAccountAlias("my-account"));
|
||||
assertEquals("NoSuchEntity", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedAccountAliasesAreRejected() {
|
||||
for (String alias : List.of("ab", "-leading", "trailing-", "Upper", "under_score", "a".repeat(64))) {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.createAccountAlias(alias), "expected rejection for: " + alias);
|
||||
assertEquals("ValidationError", ex.getErrorCode(), "wrong code for: " + alias);
|
||||
}
|
||||
assertThrows(AwsException.class, () -> iamService.createAccountAlias(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS documents the pattern as {@code ^[a-z0-9]([a-z0-9]|-(?!-)){1,61}[a-z0-9]$} — consecutive
|
||||
* dashes are rejected, which a plain character class would let through.
|
||||
*/
|
||||
@Test
|
||||
void accountAliasRejectsConsecutiveDashes() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.createAccountAlias("my--account"));
|
||||
assertEquals("ValidationError", ex.getErrorCode());
|
||||
assertTrue(iamService.getAccountAlias().isEmpty());
|
||||
|
||||
iamService.createAccountAlias("my-account");
|
||||
assertEquals("my-account", iamService.getAccountAlias().orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountAliasBoundaryLengthsAreAccepted() {
|
||||
iamService.createAccountAlias("abc");
|
||||
iamService.deleteAccountAlias("abc");
|
||||
|
||||
iamService.createAccountAlias("a".repeat(63));
|
||||
assertEquals("a".repeat(63), iamService.getAccountAlias().orElseThrow());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user