@BeforeAll
static void setUpOnce() throws IOException {
discoverAssets(
IamClient.class,
AwsIamUserScanner::new,
api -> {
when(api.listUsers())
.thenReturn(
ListUsersResponse.builder()
.users(
User.builder().arn(USER1_ARN).userName("USER1").build(),
User.builder().arn(USER2_ARN).userName("USER2").build(),
User.builder().arn(USER3_ARN).userName("USER3").build())
.build());
when(api.listMFADevices(ListMfaDevicesRequest.builder().userName("USER1").build()))
.thenReturn(ListMfaDevicesResponse.builder().build());
when(api.listGroupsForUser(ListGroupsForUserRequest.builder().userName("USER1").build()))
.thenReturn(
ListGroupsForUserResponse.builder()
.groups(Group.builder().groupName("some-group").build())
.build());
when(api.listAccessKeys(ListAccessKeysRequest.builder().userName("USER1").build()))
.thenReturn(
ListAccessKeysResponse.builder()
.accessKeyMetadata(
AccessKeyMetadata.builder().accessKeyId("some-key").build())
.build());
when(api.listMFADevices(ListMfaDevicesRequest.builder().userName("USER2").build()))
.thenReturn(
ListMfaDevicesResponse.builder()
.mfaDevices(MFADevice.builder().serialNumber("1234556").build())
.build());
when(api.listGroupsForUser(ListGroupsForUserRequest.builder().userName("USER2").build()))
.thenReturn(
ListGroupsForUserResponse.builder()
.groups(Group.builder().groupName("some-group").build())
.build());
when(api.listAccessKeys(ListAccessKeysRequest.builder().userName("USER2").build()))
.thenReturn(
ListAccessKeysResponse.builder()
.accessKeyMetadata(AccessKeyMetadata.builder().accessKeyId("old-key").build())
.build());
when(api.listMFADevices(ListMfaDevicesRequest.builder().userName("USER3").build()))
.thenReturn(ListMfaDevicesResponse.builder().build());
when(api.listGroupsForUser(ListGroupsForUserRequest.builder().userName("USER3").build()))
.thenReturn(ListGroupsForUserResponse.builder().build());
when(api.listAccessKeys(ListAccessKeysRequest.builder().userName("USER3").build()))
.thenReturn(
ListAccessKeysResponse.builder()
.accessKeyMetadata(
AccessKeyMetadata.builder()
.accessKeyId("some-key")
.status(StatusType.INACTIVE)
.build())
.build());
when(api.getAccessKeyLastUsed(
GetAccessKeyLastUsedRequest.builder().accessKeyId("some-key").build()))
.thenReturn(
GetAccessKeyLastUsedResponse.builder()
.accessKeyLastUsed(
AccessKeyLastUsed.builder().lastUsedDate(Instant.now()).build())
.build());
when(api.getAccessKeyLastUsed(
GetAccessKeyLastUsedRequest.builder().accessKeyId("old-key").build()))
.thenReturn(
GetAccessKeyLastUsedResponse.builder()
.accessKeyLastUsed(
AccessKeyLastUsed.builder().lastUsedDate(Instant.MIN).build())
.build());
});
}