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();
}
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));
}
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"));
}
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);
}
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));
}
Aggregations