use of software.amazon.awssdk.services.cognitoidentity.model.Credentials in project formkiq-core by formkiq.
the class AwsResourceTest method testAdminAddUserToGroup.
/**
* Test Having Admin add new user to group.
*/
@Test(timeout = TEST_TIMEOUT)
public void testAdminAddUserToGroup() {
// given
String email = UUID.randomUUID() + "@formkiq.com";
String group = getParameterStoreValue("/formkiq/" + getAppenvironment() + "/cognito/AdminGroup");
Credentials cred = getAdminCognitoService().getCredentials(getAdminToken());
AwsCredentials basic = AwsSessionCredentials.create(cred.accessKeyId(), cred.secretKey(), cred.sessionToken());
CognitoConnectionBuilder userBuilder = createCognitoConnectionBuilder().setCredentials(StaticCredentialsProvider.create(basic));
CognitoService userCognitoService = new CognitoService(userBuilder);
// when
GetUserResponse user = userCognitoService.getUser(getAdminToken());
userCognitoService.addUser(email, USER_TEMP_PASSWORD);
userCognitoService.addUserToGroup(email, group);
// then
assertNotNull(user.username());
assertEquals("testadminuser@formkiq.com", user.userAttributes().stream().filter(f -> f.name().equals("email")).findFirst().get().value());
}
Aggregations