Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete AssumeRoleIntegrationTest test resources on completion #5815

Merged
merged 6 commits into from
Jan 24, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.Duration;
import java.util.Comparator;
import java.util.Optional;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
Expand Down Expand Up @@ -63,14 +64,15 @@ public class AssumeRoleIntegrationTest extends IntegrationTestBaseWithIAM {
private static final String ROLE_NAME = "assume-role-integration-test-role";
private static final String ROLE_ARN_FORMAT = "arn:aws:iam::%s:role/" + ROLE_NAME;
private static String ROLE_ARN;
private static String accountId;

private static final String ASSUME_ROLE = "sts:AssumeRole";

private static AwsCredentials userCredentials;

@BeforeClass
public static void setup() {
String accountId = sts.getCallerIdentity().account();
accountId = sts.getCallerIdentity().account();
USER_ARN = String.format(USER_ARN_FORMAT, accountId);
ROLE_ARN = String.format(ROLE_ARN_FORMAT, accountId);

Expand Down Expand Up @@ -133,6 +135,21 @@ public static void setup() {
.orFailAfter(Duration.ofMinutes(5));
}

@AfterClass
public static void cleanup() {
iam.listAccessKeysPaginator(r -> r.userName(USER_NAME))
L-Applin marked this conversation as resolved.
Show resolved Hide resolved
.accessKeyMetadata()
.stream()
.forEach(meta -> iam.deleteAccessKey(req -> req.userName(USER_NAME).accessKeyId(meta.accessKeyId())));
iam.detachUserPolicy(req -> req.userName(USER_NAME).policyArn(String.format(POLICY_ARN_FORMAT, accountId)));
iam.deleteUser(req -> req.userName(USER_NAME));

// deleting the IAM User referenced in the IAM Role trust relationship leaves the role in a bad state where it cant be
// assumed anymore. Therefore, we need to delete the role as well.
iam.deleteRole(req -> req.roleName(ROLE_NAME));
}


/** Tests that we can call assumeRole successfully. */
@Test
public void testAssumeRole() throws InterruptedException {
Expand Down
Loading