test(stepfunctions): reuse client for remaining IAM task setup (#7840)

Complete the separate follow-up requested in upstream #7783. Preserve account-bound names, role paths, task definitions and cleanup while delegating to the existing StepFunctionsTestClient.

Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-11-10 10:52:11 -04:00
1 parent ef1e00fba7
commit 9dae9f8036
3 files changed
+10 -19

No files matched your search

@@ -859,17 +859,15 @@ class StepFunctionsDataTaskIamIntegrationTest {
}
private String role(String trust, String policy) {
return EnforcementFixtures.createRole(cleanup, baseUri.getPort(), ACCOUNT, "/",
"sfn-data-" + UUID.randomUUID(), trust, policy);
return sfn().role(ACCOUNT, "sfn-data-", trust, policy);
}
private String machine(Map<String, Object> task, String role) throws Exception {
return machineWithDefinition(MAPPER.writeValueAsString(
Map.of("StartAt", "Send", "States", Map.of("Send", task))), role);
return sfn().machine(ACCOUNT, "sfn-data-iam-", task, role);
}
private String machineWithDefinition(String definition, String role) {
return sfn().createMachine(ACCOUNT, "sfn-data-iam-", definition, "STANDARD", role);
return sfn().machineWithDefinition(ACCOUNT, "sfn-data-iam-", definition, role);
}
private String start(String machine, String input) {
@@ -305,8 +305,7 @@ class StepFunctionsMessagingTaskIamIntegrationTest {
void aForeignCredentialsRoleNeedsTheTopicPolicyToo() throws Exception {
Target target = target("sns:publish");
String executionRole = role(STATES_TRUST, ASSUME);
String foreignRole = EnforcementFixtures.createRole(cleanup, baseUri.getPort(), OTHER_ACCOUNT, "/",
"sfn-msg-" + UUID.randomUUID(), trusting(executionRole), PUBLISH_ANY);
String foreignRole = sfn().role(OTHER_ACCOUNT, "sfn-msg-", trusting(executionRole), PUBLISH_ANY);
String machine = machine(jsonPathTask(target, foreignRole), executionRole);
Response refused = terminal(start(machine, "{}"));
@@ -328,8 +327,7 @@ class StepFunctionsMessagingTaskIamIntegrationTest {
void aForeignCredentialsRoleNeedsItsIdentityPolicyToo() throws Exception {
Target target = target("sns:publish");
String executionRole = role(STATES_TRUST, ASSUME);
String foreignRole = EnforcementFixtures.createRole(cleanup, baseUri.getPort(), OTHER_ACCOUNT, "/",
"sfn-msg-" + UUID.randomUUID(), trusting(executionRole), READ_ONLY);
String foreignRole = sfn().role(OTHER_ACCOUNT, "sfn-msg-", trusting(executionRole), READ_ONLY);
setTopicPolicy(target.resourceArn(), topicStatement("Allow", foreignRole, target.resourceArn()));
Response completed = terminal(start(machine(jsonPathTask(target, foreignRole), executionRole), "{}"));
@@ -426,8 +424,7 @@ class StepFunctionsMessagingTaskIamIntegrationTest {
void aForeignCredentialsRoleNeedsTheBusPolicyToo() throws Exception {
Target target = target("events:putEvents");
String executionRole = role(STATES_TRUST, ASSUME);
String foreignRole = EnforcementFixtures.createRole(cleanup, baseUri.getPort(), OTHER_ACCOUNT, "/",
"sfn-msg-" + UUID.randomUUID(), trusting(executionRole), PUBLISH_ANY);
String foreignRole = sfn().role(OTHER_ACCOUNT, "sfn-msg-", trusting(executionRole), PUBLISH_ANY);
String machine = machine(jsonPathTask(target, foreignRole), executionRole);
Response refused = terminal(start(machine, "{}"));
@@ -449,8 +446,7 @@ class StepFunctionsMessagingTaskIamIntegrationTest {
void aForeignCredentialsRoleNeedsItsIdentityPolicyOnABusToo() throws Exception {
Target target = target("events:putEvents");
String executionRole = role(STATES_TRUST, ASSUME);
String foreignRole = EnforcementFixtures.createRole(cleanup, baseUri.getPort(), OTHER_ACCOUNT, "/",
"sfn-msg-" + UUID.randomUUID(), trusting(executionRole), READ_ONLY);
String foreignRole = sfn().role(OTHER_ACCOUNT, "sfn-msg-", trusting(executionRole), READ_ONLY);
events("PutPermission", Map.of("EventBusName", busName(target.resourceArn()), "StatementId", "s",
"Action", "events:PutEvents", "Principal", OTHER_ACCOUNT));
@@ -181,8 +181,7 @@ class StepFunctionsSqsTaskIamIntegrationTest {
void aForeignCredentialsRoleNeedsTheQueueToGrantIt() throws Exception {
SqsTestQueue queue = queue();
String executionRole = role(STATES_TRUST, ASSUME);
String foreignRole = EnforcementFixtures.createRole(cleanup, baseUri.getPort(), OTHER_ACCOUNT, "/",
"sfn-sqs-" + UUID.randomUUID(), trusting(executionRole), SEND);
String foreignRole = sfn().role(OTHER_ACCOUNT, "sfn-sqs-", trusting(executionRole), SEND);
String machine = machine(jsonPathTask("sqs:sendMessage", queue, foreignRole), executionRole);
Response refused = terminal(start(machine, "{}"));
@@ -201,8 +200,7 @@ class StepFunctionsSqsTaskIamIntegrationTest {
@Test
void aQueueInAnotherAccountNeedsItsOwnGrant() throws Exception {
SqsTestQueue queue = SqsTestQueue.create(sqsService, OTHER_ACCOUNT, REGION, "sfn-sqs-iam-");
cleanup.register(queue::delete);
SqsTestQueue queue = sfn().queue(sqsService, OTHER_ACCOUNT, REGION, "sfn-sqs-iam-");
String role = role(STATES_TRUST, SEND);
String machine = machine(jsonPathTask("sqs:sendMessage", queue, null), role);
@@ -220,8 +218,7 @@ class StepFunctionsSqsTaskIamIntegrationTest {
@Test
void aQueueInAnotherAccountCannotGrantWhatTheRoleLacks() throws Exception {
SqsTestQueue queue = SqsTestQueue.create(sqsService, OTHER_ACCOUNT, REGION, "sfn-sqs-iam-");
cleanup.register(queue::delete);
SqsTestQueue queue = sfn().queue(sqsService, OTHER_ACCOUNT, REGION, "sfn-sqs-iam-");
String role = role(STATES_TRUST, READ_ONLY);
queue.setPolicy(queuePolicy("Allow", role, queue.arn()));