Search in sources :

Example 41 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixFalse.

@Test
public void testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixFalse() throws JSONException {
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
    AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(false).build();
    AWSAppSyncClients.validateAppSyncClient(awsAppSyncClient, null, appSyncConfig.getString("AuthMode"));
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 42 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testNoAuthModeObjectThrowsExceptionViaCode.

@Test
public void testNoAuthModeObjectThrowsExceptionViaCode() {
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
    RuntimeException exception = assertThrows(RuntimeException.class, () -> AWSAppSyncClient.builder().context(getTargetContext()).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(true).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix")).build());
    String expected = "No valid AuthMode object is passed in to the builder.";
    assertTrue(exception.getLocalizedMessage().startsWith(expected));
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Test(org.junit.Test)

Example 43 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testCodeHasInvalidClientDatabasePrefix.

@Test
public void testCodeHasInvalidClientDatabasePrefix() {
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
    RuntimeException exception = assertThrows(RuntimeException.class, () -> AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(true).clientDatabasePrefix(// This is the problem!!
    "MultiAuthAndroidIntegTestApp_!@#$%^&*()").build());
    String expected = "ClientDatabasePrefix validation failed. Please pass in characters " + "that matches the pattern: ^[_a-zA-Z0-9]+$";
    assertTrue(exception.getLocalizedMessage().startsWith(expected));
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 44 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class CustomCognitoUserPool method setup.

@NonNull
public static String setup() {
    // Sign in the user.
    Await.result((Await.ResultErrorEmitter<SignInResult, RuntimeException>) (onResult, onError) -> {
        DelegatingMobileClientCallback<SignInResult> callback = DelegatingMobileClientCallback.to(onResult, exception -> onError.accept(new RuntimeException(exception)));
        TestAWSMobileClient.instance(getTargetContext()).signIn("appsync-multi-auth-test-user", "P@ssw0rd!", null, callback);
    });
    // Build a custom cognito user pool.
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    awsConfiguration.setConfiguration("Custom");
    CognitoUserPool cognitoUserPool = new CognitoUserPool(getTargetContext(), awsConfiguration);
    // Get the ID token for this user.
    return Await.result((onResult, onError) -> cognitoUserPool.getUser("appsync-multi-auth-test-user").getSession(new AuthenticationHandler() {

        @Override
        public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
            onResult.accept(userSession.getIdToken().getJWTToken());
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
            Log.d(TAG, "Sending password.");
            authenticationContinuation.setAuthenticationDetails(new AuthenticationDetails("appsync-multi-auth-test-user", "P@ssw0rd!", null));
            authenticationContinuation.continueTask();
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
        }

        @Override
        public void onFailure(Exception exception) {
            onError.accept(new RuntimeException(exception));
        }
    }));
}
Also used : InstrumentationRegistry.getTargetContext(androidx.test.InstrumentationRegistry.getTargetContext) NonNull(androidx.annotation.NonNull) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Await(com.amazonaws.mobileconnectors.appsync.util.Await) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) Log(android.util.Log) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) SignInResult(com.amazonaws.mobile.client.results.SignInResult) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) Await(com.amazonaws.mobileconnectors.appsync.util.Await) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) NonNull(androidx.annotation.NonNull)

Example 45 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class AWSAppSyncClients method withApiKeyForGogiTest.

@NonNull
public static AWSAppSyncClient withApiKeyForGogiTest() {
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    awsConfiguration.setConfiguration("SubscriptionIntegrationTestGogi");
    return AWSAppSyncClient.builder().context(getTargetContext()).awsConfiguration(awsConfiguration).build();
}
Also used : AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) NonNull(androidx.annotation.NonNull)

Aggregations

AWSConfiguration (com.amazonaws.mobile.config.AWSConfiguration)48 JSONObject (org.json.JSONObject)28 Test (org.junit.Test)26 JSONException (org.json.JSONException)16 Context (android.content.Context)13 NonNull (androidx.annotation.NonNull)11 BasicAPIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 BeforeClass (org.junit.BeforeClass)7 AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)6 UserStateDetails (com.amazonaws.mobile.client.UserStateDetails)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 SignInResult (com.amazonaws.mobile.client.results.SignInResult)3 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)3 UserNotConfirmedException (com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException)3 Nullable (androidx.annotation.Nullable)2 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)2 AWSMobileClient (com.amazonaws.mobile.client.AWSMobileClient)2 Callback (com.amazonaws.mobile.client.Callback)2