use of com.amplifyframework.api.aws.ApiAuthProviders in project amplify-android by aws-amplify.
the class ApiRequestDecoratorFactoryTest method testOidcOverrideNotProvided.
/**
* If a custom OIDC provider is not provided AND there is
* an API that uses {@link AuthorizationType#OPENID_CONNECT}
* as its auth mechanism, then the process will fail at runtime
* while sending a request with that API.
*/
@Test
public void testOidcOverrideNotProvided() {
ApiAuthProviders providers = ApiAuthProviders.noProviderOverrides();
ApiRequestDecoratorFactory factory = new ApiRequestDecoratorFactory(providers, AuthorizationType.OPENID_CONNECT, "", EndpointType.GRAPHQL, "CONFIG_API_KEY");
Request request = new Request.Builder().url("https://localhost/").build();
assertThrows(ApiException.ApiAuthException.class, () -> factory.forAuthType(AuthorizationType.OPENID_CONNECT).decorate(request));
}
use of com.amplifyframework.api.aws.ApiAuthProviders in project amplify-android by aws-amplify.
the class ApiRequestDecoratorFactoryTest method testApiKeyProvidedInterceptSucceeds.
/**
* If API key is not mentioned in API configuration AND auth mode is
* API_KEY BUT a valid custom API key provider is provided via
* ApiAuthProvider, then intercept succeeds.
* @throws ApiException.ApiAuthException From factory.forAuthType
*/
@Test
public void testApiKeyProvidedInterceptSucceeds() throws ApiException.ApiAuthException {
ApiAuthProviders providers = ApiAuthProviders.builder().apiKeyAuthProvider(() -> "CUSTOM_API_KEY").build();
ApiRequestDecoratorFactory factory = new ApiRequestDecoratorFactory(providers, AuthorizationType.API_KEY, "", EndpointType.GRAPHQL, null);
Request request = new Request.Builder().url("https://localhost/").build();
Request decoratedRequest = factory.forAuthType(AuthorizationType.API_KEY).decorate(request);
assertEquals("CUSTOM_API_KEY", decoratedRequest.header(X_API_KEY));
}
use of com.amplifyframework.api.aws.ApiAuthProviders in project amplify-android by aws-amplify.
the class ApiRequestDecoratorFactoryTest method testApiKeyNotProvidedInConfiguration.
/**
* Test cases for when no API key is provided by the config file..
*/
@Test
public void testApiKeyNotProvidedInConfiguration() {
ApiAuthProviders providers = ApiAuthProviders.noProviderOverrides();
ApiRequestDecoratorFactory factory = new ApiRequestDecoratorFactory(providers, AuthorizationType.API_KEY, "", EndpointType.GRAPHQL, null);
Request request = new Request.Builder().url("https://localhost/").build();
assertThrows(ApiException.ApiAuthException.class, () -> factory.forAuthType(AuthorizationType.API_KEY).decorate(request));
}
use of com.amplifyframework.api.aws.ApiAuthProviders in project amplify-android by aws-amplify.
the class ApiRequestDecoratorFactoryTest method testOidcOverrideProvided.
/**
* Test to confirm that passing any custom implementation of
* {@link com.amplifyframework.api.aws.sigv4.OidcAuthProvider}
* prevents crashes while intercepting requests.
* @throws ApiException From API configuration
*/
@Test
public void testOidcOverrideProvided() throws ApiException {
final String oidcJwtToken = "OIDC_JWT_TOKEN";
ApiAuthProviders providers = ApiAuthProviders.builder().oidcAuthProvider(() -> oidcJwtToken).build();
ApiRequestDecoratorFactory factory = new ApiRequestDecoratorFactory(providers, AuthorizationType.OPENID_CONNECT, "", EndpointType.GRAPHQL, "CONFIG_API_KEY");
Request request = new Request.Builder().url("https://localhost/").build();
Request decoratedRequest = factory.forAuthType(AuthorizationType.OPENID_CONNECT).decorate(request);
assertEquals(oidcJwtToken, decoratedRequest.header(AUTHORIZATION));
}
use of com.amplifyframework.api.aws.ApiAuthProviders in project amplify-android by aws-amplify.
the class ApiRequestDecoratorFactoryTest method testCustomOverrideNotProvided.
/**
* If a custom auth provider is not provided AND there is
* an API that uses {@link AuthorizationType#AWS_LAMBDA}
* as its auth mechanism, then the process will fail at runtime
* while sending a request with that API.
*/
@Test
public void testCustomOverrideNotProvided() {
ApiAuthProviders providers = ApiAuthProviders.noProviderOverrides();
ApiRequestDecoratorFactory factory = new ApiRequestDecoratorFactory(providers, AuthorizationType.AWS_LAMBDA, "", EndpointType.GRAPHQL, "CONFIG_API_KEY");
Request request = new Request.Builder().url("https://localhost/").build();
assertThrows(ApiException.ApiAuthException.class, () -> factory.forAuthType(AuthorizationType.AWS_LAMBDA).decorate(request));
}
Aggregations