use of software.amazon.awssdk.crt.auth.credentials.Credentials 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);
}
use of software.amazon.awssdk.crt.auth.credentials.Credentials in project aws-crt-java by awslabs.
the class ProxyTest method doCredentialsProviderProxyTest.
private void doCredentialsProviderProxyTest(CredentialsProvider provider) {
try {
Credentials credentials = provider.getCredentials().get();
Assert.assertNotNull(credentials);
} catch (Exception e) {
throw new CrtRuntimeException(e.toString());
}
}
use of software.amazon.awssdk.crt.auth.credentials.Credentials in project aws-sdk-java-v2 by aws.
the class CrtCredentialProviderAdapterTest method crtCredentials_withoutSession_shouldConvert.
@Test
public void crtCredentials_withoutSession_shouldConvert() {
AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"));
CredentialsProvider crtCredentialsProvider = new CrtCredentialsProviderAdapter(awsCredentialsProvider).crtCredentials();
Credentials credentials = crtCredentialsProvider.getCredentials().join();
assertThat(credentials.getAccessKeyId()).isEqualTo("foo".getBytes(StandardCharsets.UTF_8));
assertThat(credentials.getSecretAccessKey()).isEqualTo("bar".getBytes(StandardCharsets.UTF_8));
assertThat(credentials.getSessionToken()).isNull();
}
use of software.amazon.awssdk.crt.auth.credentials.Credentials in project aws-sdk-java-v2 by aws.
the class CrtCredentialProviderAdapterTest method crtCredentials_withoutSession_shouldConvert.
@Test
public void crtCredentials_withoutSession_shouldConvert() {
AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"));
CredentialsProvider crtCredentialsProvider = new CrtCredentialsProviderAdapter(awsCredentialsProvider).crtCredentials();
Credentials credentials = crtCredentialsProvider.getCredentials().join();
assertThat(credentials.getAccessKeyId()).isEqualTo("foo".getBytes(StandardCharsets.UTF_8));
assertThat(credentials.getSecretAccessKey()).isEqualTo("bar".getBytes(StandardCharsets.UTF_8));
assertThat(credentials.getSessionToken()).isNull();
}
use of software.amazon.awssdk.crt.auth.credentials.Credentials in project aws-sdk-java-v2 by aws.
the class CrtCredentialProviderAdapterTest method crtCredentials_provideAwsCredentials_shouldInvokeResolveAndClose.
@Test
public void crtCredentials_provideAwsCredentials_shouldInvokeResolveAndClose() {
AwsCredentialsProvider awsCredentialsProvider = Mockito.mock(HttpCredentialsProvider.class);
AwsCredentials credentials = new AwsCredentials() {
@Override
public String accessKeyId() {
return "foo";
}
@Override
public String secretAccessKey() {
return "bar";
}
};
when(awsCredentialsProvider.resolveCredentials()).thenReturn(credentials);
CrtCredentialsProviderAdapter adapter = new CrtCredentialsProviderAdapter(awsCredentialsProvider);
CredentialsProvider crtCredentialsProvider = adapter.crtCredentials();
Credentials crtCredentials = crtCredentialsProvider.getCredentials().join();
assertThat(crtCredentials.getAccessKeyId()).isEqualTo("foo".getBytes(StandardCharsets.UTF_8));
assertThat(crtCredentials.getSecretAccessKey()).isEqualTo("bar".getBytes(StandardCharsets.UTF_8));
verify(awsCredentialsProvider).resolveCredentials();
adapter.close();
verify((SdkAutoCloseable) awsCredentialsProvider).close();
}
Aggregations