Search in sources :

Example 1 with BasicAPIKeyAuthProvider

use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.

the class AppSyncClientUnitTest method testConfigMismatch_AmazonCognitoUserPools.

@Test(expected = RuntimeException.class)
public void testConfigMismatch_AmazonCognitoUserPools() {
    awsConfiguration.setConfiguration("ApiKey");
    APIKeyAuthProvider apiKeyAuthProvider = new BasicAPIKeyAuthProvider(awsConfiguration);
    awsConfiguration.setConfiguration("AmazonCognitoUserPools");
    CognitoUserPool cognitoUserPool = new CognitoUserPool(shadowContext, awsConfiguration);
    BasicCognitoUserPoolsAuthProvider basicCognitoUserPoolsAuthProvider = new BasicCognitoUserPoolsAuthProvider(cognitoUserPool);
    final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(shadowContext).awsConfiguration(awsConfiguration).apiKey(apiKeyAuthProvider).build();
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) BasicCognitoUserPoolsAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicCognitoUserPoolsAuthProvider) APIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.APIKeyAuthProvider) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 2 with BasicAPIKeyAuthProvider

use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testCodeHasEmptyClientDatabasePrefix.

@Test
public void testCodeHasEmptyClientDatabasePrefix() {
    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(// Note: this is the problem!!
    "").build());
    String expected = "Please pass in a valid ClientDatabasePrefix when useClientDatabasePrefix is true.";
    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 3 with BasicAPIKeyAuthProvider

use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixTrue.

@Test
public void testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixTrue() throws JSONException {
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
    AWSAppSyncClient.Builder awsAppSyncClientBuilder = AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(true).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix"));
    AWSAppSyncClient awsAppSyncClient = awsAppSyncClientBuilder.build();
    AWSAppSyncClients.validateAppSyncClient(awsAppSyncClient, appSyncConfig.getString("ClientDatabasePrefix"), 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 4 with BasicAPIKeyAuthProvider

use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixFalse.

@Test
public void testCodeHasClientDatabasePrefixAndUseClientDatabasePrefixFalse() 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).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix")).build();
    AWSAppSyncClients.validateAppSyncClient(awsAppSyncClient, null, null);
}
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 5 with BasicAPIKeyAuthProvider

use of com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider in project aws-mobile-appsync-sdk-android by awslabs.

the class MultiClientInstrumentationTest method testUseSameClientDatabasePrefixForDifferentAuthModes.

@Test
public void testUseSameClientDatabasePrefixForDifferentAuthModes() throws JSONException {
    // Construct client-1 with API_KEY AuthMode and MultiAuthAndroidIntegTestApp_API_KEY prefix
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
    AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(true).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix")).build();
    // Construct client-2 with AWS_IAM AuthMode and same prefix ("MultiAuthAndroidIntegTestApp_API_KEY")
    RuntimeException exception = assertThrows(RuntimeException.class, () -> AWSAppSyncClient.builder().context(getTargetContext()).cognitoUserPoolsAuthProvider(() -> {
        try {
            return AWSMobileClient.getInstance().getTokens().getIdToken().toString();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }).useClientDatabasePrefix(true).clientDatabasePrefix(appSyncConfig.getString("ClientDatabasePrefix")).build());
    String expected = "ClientDatabasePrefix validation failed. The ClientDatabasePrefix ";
    assertTrue(exception.getLocalizedMessage().startsWith(expected));
}
Also used : JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) AWSAppSyncClientException(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClientException) JSONException(org.json.JSONException) ClearCacheException(com.amazonaws.mobileconnectors.appsync.ClearCacheException) Test(org.junit.Test)

Aggregations

BasicAPIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider)11 Test (org.junit.Test)11 AWSConfiguration (com.amazonaws.mobile.config.AWSConfiguration)9 JSONObject (org.json.JSONObject)9 AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)3 APIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.APIKeyAuthProvider)2 BasicCognitoUserPoolsAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicCognitoUserPoolsAuthProvider)2 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)2 AWSAppSyncClientException (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClientException)1 ClearCacheException (com.amazonaws.mobileconnectors.appsync.ClearCacheException)1 JSONException (org.json.JSONException)1