DefaultSignerProvider extends SignerProvider { @Override public Signer getSigner(SignerProviderContext context) { Request<?> request = context.getRequest(); if (request == null || shouldUseDefaultSigner(request.getOriginalRequest())) { if (context.isRedirect()) { return awsClient.getSignerByURI(context.getUri()); } return defaultSigner; } SignerTypeAware signerTypeAware = (SignerTypeAware) request.getOriginalRequest(); SignerParams params = new SignerParams(awsClient.getServiceName(), getSigningRegionForRequestURI(request.getEndpoint())); return SignerFactory.createSigner(signerTypeAware.getSignerType(), params); } DefaultSignerProvider(final AmazonWebServiceClient awsClient,
                                 final Signer defaultSigner); @Override Signer getSigner(SignerProviderContext context);  }
@Test public void usesDefaultIfSignerOverridden() { when(mockClient.getSignerOverride()).thenReturn("NoOpSignerType"); SignerProviderContext ctx = SignerProviderContext.builder() .withRequest(signerAwareRequest) .build(); assertThat(defaultSignerProvider.getSigner(ctx), is(equalTo(DEFAULT_SIGNER))); }
@Test public void usesDefaultIfNotSignerAware() { SignerProviderContext ctx = SignerProviderContext.builder() .withRequest(nonSignerAwareRequest) .build(); assertThat(defaultSignerProvider.getSigner(ctx), is(equalTo(DEFAULT_SIGNER))); }
@Test public void usesOperationSignerType() { SignerProviderContext ctx = SignerProviderContext.builder() .withRequest(signerAwareRequest) .build(); assertThat(defaultSignerProvider.getSigner(ctx) instanceof FooSigner, is(true)); }
@Test public void configuresServiceAndRegionWhenUsingOperationSigner() throws URISyntaxException { when(mockClient.getServiceName()).thenReturn("MockService"); SignerProviderContext ctx = SignerProviderContext.builder() .withRequest(signerAwareRequest) .build(); Signer signer = defaultSignerProvider.getSigner(ctx); FooSigner fooSigner = (FooSigner) signer; assertThat(fooSigner.getRegionName(), is(equalTo("us-east-1"))); assertThat(fooSigner.getServiceName(), is(equalTo("MockService"))); }
@Test public void testSignerRegionWhenUsingNonStandardEndpoint() throws URISyntaxException { when(mockClient.getServiceName()).thenReturn("MockService"); when(mockClient.getEndpointPrefix()).thenReturn("MockEndpointPrefix"); Request<?> signerAwareRequest = new DefaultRequest<FooSignedRequest>(new FooSignedRequest(), "MockService"); String bjsEndpoint = "https: signerAwareRequest.setEndpoint(new URI(bjsEndpoint)); SignerProviderContext ctx = SignerProviderContext.builder() .withRequest(signerAwareRequest) .build(); Signer signer = defaultSignerProvider.getSigner(ctx); FooSigner fooSigner = (FooSigner) signer; assertThat(fooSigner.getRegionName(), is(equalTo("cn-north-1"))); assertThat(fooSigner.getServiceName(), is(equalTo("MockService"))); }
@Test public void usesDefaultSignerWhenNoRequest() { SignerProviderContext ctx = SignerProviderContext.builder().build(); assertThat(defaultSignerProvider.getSigner(ctx) == DEFAULT_SIGNER, is(true)); }