use of software.amazon.awssdk.crt.auth.credentials.DelegateCredentialsProvider in project aws-crt-java by awslabs.
the class SigningTest method testSigningException.
@Test
public void testSigningException() throws Exception {
DelegateCredentialsHandler credentialsHandler = new DelegateCredentialsHandler() {
@Override
public Credentials getCredentials() {
throw new RuntimeException("failed");
}
};
boolean failed = false;
try (DelegateCredentialsProvider provider = new DelegateCredentialsProvider.DelegateCredentialsProviderBuilder().withHandler(credentialsHandler).build()) {
HttpRequest request = createSimpleRequest("https://www.example.com", "POST", "/derp", "<body>Hello</body>");
Predicate<String> filterParam = param -> !param.equals("bad-param");
try (AwsSigningConfig config = new AwsSigningConfig()) {
config.setAlgorithm(AwsSigningConfig.AwsSigningAlgorithm.SIGV4);
config.setSignatureType(AwsSigningConfig.AwsSignatureType.HTTP_REQUEST_VIA_HEADERS);
config.setRegion("us-east-1");
config.setService("service");
config.setTime(System.currentTimeMillis());
config.setCredentialsProvider(provider);
config.setShouldSignHeader(filterParam);
config.setUseDoubleUriEncode(true);
config.setShouldNormalizeUriPath(true);
config.setSignedBodyValue(AwsSigningConfig.AwsSignedBodyValue.EMPTY_SHA256);
CompletableFuture<HttpRequest> result = AwsSigner.signRequest(request, config);
HttpRequest signedRequest = result.get();
assertNotNull(signedRequest);
assertTrue(hasHeader(signedRequest, "X-Amz-Date"));
assertTrue(hasHeader(signedRequest, "Authorization"));
}
} catch (Exception ex) {
failed = true;
}
assertTrue(failed);
}
Aggregations