Search in sources :

Example 16 with AWSKeyValueStore

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) AmazonServiceException(com.amazonaws.AmazonServiceException) UnknownHostException(java.net.UnknownHostException) AmazonClientException(com.amazonaws.AmazonClientException) Test(org.junit.Test)

Example 17 with AWSKeyValueStore

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));
}
Also used : Context(android.content.Context) IdToken(com.amazonaws.mobileconnectors.cognitoauth.tokens.IdToken) RefreshToken(com.amazonaws.mobileconnectors.cognitoauth.tokens.RefreshToken) AccessToken(com.amazonaws.mobileconnectors.cognitoauth.tokens.AccessToken) AuthUserSession(com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession) AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore) HashSet(java.util.HashSet)

Aggregations

AWSKeyValueStore (com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)17 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Test (org.junit.Test)4 AmazonClientException (com.amazonaws.AmazonClientException)2 AmazonServiceException (com.amazonaws.AmazonServiceException)2 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)2 UnknownHostException (java.net.UnknownHostException)2 JSONException (org.json.JSONException)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AuthUserSession (com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession)1 AccessToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.AccessToken)1 IdToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.IdToken)1 RefreshToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.RefreshToken)1 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 JSONObject (org.json.JSONObject)1