use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderForgotPasswordTest method confirmPasswordInBackground.
@Test
public void confirmPasswordInBackground() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
testUser = testPool.getUser(TEST_USER_NAME);
final FlowTracker tracker;
tracker = new FlowTracker("onSuccess");
tracker.activate();
doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
testUser.confirmPasswordInBackground(TEST_CODE, TEST_USER_PASSWORD, new ForgotPasswordHandler() {
public void onSuccess() {
// Check the flow
assertTrue(tracker.check("onSuccess"));
}
public void getResetCode(ForgotPasswordContinuation var1) {
assertTrue(tracker.check("getResetCode"));
// Except to fail
tracker.setNext("onFailure");
}
public void onFailure(Exception var1) {
assertTrue(tracker.check("onFailure"));
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderForgotPasswordTest method forgotPasswordInCurrentThreadInvalidUser.
@Test
public void forgotPasswordInCurrentThreadInvalidUser() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
testUser = testPool.getUser(TEST_USER_NAME);
// Set mock result for the change password request API call
InvalidParameterException exception = new InvalidParameterException("password change request failed");
doThrow(exception).when(mockCSIClient).forgotPassword(any(ForgotPasswordRequest.class));
// Except to fail
final FlowTracker tracker;
tracker = new FlowTracker("onFailure");
tracker.activate();
testUser.forgotPassword(new ForgotPasswordHandler() {
public void onSuccess() {
// Check the flow
assertTrue(tracker.check("onSuccess"));
}
public void getResetCode(ForgotPasswordContinuation var1) {
assertTrue(tracker.check("getResetCode"));
tracker.setNext("onSuccess");
doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
var1.setPassword(TEST_USER_PASSWORD);
var1.setVerificationCode(TEST_CODE);
var1.continueTask();
}
public void onFailure(Exception var1) {
assertTrue(tracker.check("onFailure"));
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpUserInBackgroundThread.
@Test
public void signUpUserInBackgroundThread() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
expected_result_boolean = true;
testPool.signUpInBackground(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
// Verify the arguments
ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
verify(mockCSIClient).signUp(argumentCaptor.capture());
SignUpRequest requestSent = argumentCaptor.getValue();
assertNotNull(requestSent);
assertEquals(TEST_USER_NAME, requestSent.getUsername());
assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
assertNotNull(requestSent.getUserAttributes());
assertEquals(2, requestSent.getUserAttributes().size());
assertNotNull(requestSent.getValidationData());
assertEquals(3, requestSent.getValidationData().size());
assertNotNull(user);
assertNotNull(signUpResult.getUserConfirmed());
assertNotNull(signUpResult.getCodeDeliveryDetails());
assertEquals(TEST_USER_NAME, user.getUserId());
assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
}
@Override
public void onFailure(Exception exception) {
assertNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method testCacheWithEncryptionKeyNotRetrieved.
@Test
public void testCacheWithEncryptionKeyNotRetrieved() throws Exception {
SharedPreferences sharedPreferencesForEncryptionMaterials = appContext.getSharedPreferences(SHARED_PREFERENCES_NAME + ".encryptionKey", Context.MODE_PRIVATE);
// Test with a user cached in shared preferences
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser", TEST_USER_NAME);
CognitoUser user = testPool.getCurrentUser();
assertNotNull(user);
String username = user.getUserId();
assertEquals(TEST_USER_NAME, username);
deleteAllEncryptionKeys();
CognitoUserPool testPoolAfterKeyDeleted = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET);
AWSKeyValueStore store = getAWSKeyValueStorageUtility(testPoolAfterKeyDeleted);
assertNull(store.get("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser"));
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method newUserPoolWithPinpointWithoutCachedApp.
@Test
public void newUserPoolWithPinpointWithoutCachedApp() {
// Test new user pool creation with PP app id.
CognitoUserPool pool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, new ClientConfiguration(), TEST_AWS_REGION_1, TEST_PP_APP_ID_1);
assertNotNull(pool);
assertNotNull(pool.getUserPoolId());
assertEquals(TEST_USER_POOL, pool.getUserPoolId());
assertNotNull(pool.getClientId());
assertEquals(TEST_CLIENT_ID, pool.getClientId());
}
Aggregations