use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class AWSMobileClientNetworkIssueTest method testNetworkExceptionPropagation_getUserAttributes.
@Test
public void testNetworkExceptionPropagation_getUserAttributes() throws Exception {
reinitialize();
final AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(appContext, AWSMobileClient.SHARED_PREFERENCES_KEY, true);
awsKeyValueStore.put(AWSMobileClient.PROVIDER_KEY, AWSMobileClient.getInstance().getLoginKey());
awsKeyValueStore.put(AWSMobileClient.TOKEN_KEY, getValidJWT(-3600L));
awsKeyValueStore.put(AWSMobileClient.IDENTITY_ID_KEY, "");
writeUserPoolsTokens(appContext, auth.getConfiguration().optJsonObject("CognitoUserPool").getString("AppClientId"), username, -3600L);
Object originalClient = getField(auth.userpool, CognitoUserPool.class, "client");
setField(auth.userpool, CognitoUserPool.class, "client", mockLowLevel);
try {
auth.getUserAttributes();
fail("Should throw exception for network issue");
} catch (Exception e) {
assertTrue("Deep cause should be network exception", e.getCause().getCause() instanceof UnknownHostException);
} finally {
setField(auth.userpool, CognitoUserPool.class, "client", originalClient);
}
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceWithRestartabilityTest method mockHostedUISignIn.
// Note that most tests create valid JWT tokens with expiry dates in the past. However, because
// we want to assert that HostedUI can get tokens, without making a network call to refresh a
// session, we're going to mock up valid session data, and ensure we call `getTokens` with
// `waitForSignIn = false`.
private void mockHostedUISignIn() throws JSONException {
AuthUserSession authUserSession = new AuthUserSession(new IdToken(getValidJWT(3600L)), new AccessToken(getValidJWT(3600L)), new RefreshToken(getValidJWT(360000L)));
Context targetContext = ApplicationProvider.getApplicationContext();
AWSKeyValueStore storeForHostedUI = new AWSKeyValueStore(targetContext, "CognitoIdentityProviderCache", true);
final Set<String> scopes = new HashSet<String>(Arrays.asList("aws.cognito.signin.user.admin", "phone", "openid", "profile", "email"));
LocalDataManager.cacheSession(storeForHostedUI, targetContext, getPackageConfigure().getString("app_client_id"), getPackageConfigure().getString("username"), authUserSession, scopes);
// Set the AWSMobileClient metadata that is specific to HostedUI
auth.mStore.set(FEDERATION_ENABLED_KEY, "true");
auth.mStore.set(HOSTED_UI_KEY, "dummyJson");
auth.mStore.set(SIGN_IN_MODE, SignInMode.HOSTED_UI.toString());
auth.mStore.set(PROVIDER_KEY, auth.getLoginKey());
auth.mStore.set(TOKEN_KEY, getValidJWT(3600L));
}
Aggregations