use of software.amazon.awssdk.crt.auth.credentials.CredentialsProvider in project aws-crt-java by awslabs.
the class ProxyTest method testX509Credentials_TunnelingProxy_BasicAuth.
@Test
public void testX509Credentials_TunnelingProxy_BasicAuth() {
skipIfNetworkUnavailable();
Assume.assumeTrue(isEnvironmentSetUpForProxyTests());
try (CredentialsProvider provider = buildProxiedX509CredentialsProvider(ProxyTestType.TUNNELING_HTTPS, ProxyAuthType.Basic)) {
doCredentialsProviderProxyTest(provider);
}
}
use of software.amazon.awssdk.crt.auth.credentials.CredentialsProvider in project aws-crt-java by awslabs.
the class ProxyTest method testX509Credentials_TunnelingProxy_NoAuth.
@Test
public void testX509Credentials_TunnelingProxy_NoAuth() {
skipIfNetworkUnavailable();
Assume.assumeTrue(isEnvironmentSetUpForProxyTests());
try (CredentialsProvider provider = buildProxiedX509CredentialsProvider(ProxyTestType.TUNNELING_HTTPS, ProxyAuthType.None)) {
doCredentialsProviderProxyTest(provider);
}
}
use of software.amazon.awssdk.crt.auth.credentials.CredentialsProvider in project aws-crt-java by awslabs.
the class S3ClientTest method testS3OverrideRequestCredentials.
@Test
public void testS3OverrideRequestCredentials() {
skipIfNetworkUnavailable();
Log.initLoggingToFile(Log.LogLevel.Error, "log.txt");
Assume.assumeTrue(hasAwsCredentials());
S3ClientOptions clientOptions = new S3ClientOptions().withEndpoint(ENDPOINT).withRegion(REGION);
boolean expectedException = false;
byte[] madeUpCredentials = "I am a madeup credentials".getBytes();
StaticCredentialsProvider.StaticCredentialsProviderBuilder builder = new StaticCredentialsProvider.StaticCredentialsProviderBuilder().withAccessKeyId(madeUpCredentials).withSecretAccessKey(madeUpCredentials);
try (S3Client client = createS3Client(clientOptions);
CredentialsProvider emptyCredentialsProvider = builder.build()) {
CompletableFuture<Integer> onFinishedFuture = new CompletableFuture<>();
S3MetaRequestResponseHandler responseHandler = new S3MetaRequestResponseHandler() {
@Override
public void onFinished(int errorCode, int responseStatus, byte[] errorPayload) {
Log.log(Log.LogLevel.Info, Log.LogSubject.JavaCrtS3, "Meta request finished with error code " + errorCode);
if (errorCode != 0) {
onFinishedFuture.completeExceptionally(new CrtS3RuntimeException(errorCode, responseStatus, errorPayload));
return;
}
onFinishedFuture.complete(Integer.valueOf(errorCode));
}
};
HttpHeader[] headers = { new HttpHeader("Host", ENDPOINT) };
HttpRequest httpRequest = new HttpRequest("GET", "/get_object_test_1MB.txt", headers, null);
S3MetaRequestOptions metaRequestOptions = new S3MetaRequestOptions().withMetaRequestType(MetaRequestType.GET_OBJECT).withHttpRequest(httpRequest).withResponseHandler(responseHandler).withCredentialsProvider(emptyCredentialsProvider);
try (S3MetaRequest metaRequest = client.makeMetaRequest(metaRequestOptions)) {
Assert.assertEquals(Integer.valueOf(0), onFinishedFuture.get());
}
} catch (InterruptedException | ExecutionException ex) {
expectedException = true;
/*
* Maybe better to have a cause of the max retries exceed to be more informative
*/
if (!(ex.getCause() instanceof CrtS3RuntimeException)) {
Assert.fail(ex.getMessage());
}
}
Assert.assertTrue(expectedException);
}
use of software.amazon.awssdk.crt.auth.credentials.CredentialsProvider in project aws-crt-java by awslabs.
the class S3NativeClientTest method testPutObject.
@Test
public void testPutObject() {
skipIfNetworkUnavailable();
try (final EventLoopGroup elGroup = new EventLoopGroup(DEFAULT_NUM_THREADS);
final HostResolver resolver = new HostResolver(elGroup, DEFAULT_MAX_HOST_ENTRIES);
final ClientBootstrap clientBootstrap = new ClientBootstrap(elGroup, resolver);
final CredentialsProvider provider = getTestCredentialsProvider();
final S3NativeClient nativeClient = new S3NativeClient(REGION, clientBootstrap, provider, 64_000_000l, 100.)) {
final long contentLength = 1024l;
final long[] lengthWritten = { 0 };
nativeClient.putObject(PutObjectRequest.builder().bucket(BUCKET).key(PUT_OBJECT_KEY).contentLength(contentLength).build(), buffer -> {
while (buffer.hasRemaining()) {
buffer.put((byte) 42);
++lengthWritten[0];
}
return lengthWritten[0] == contentLength;
}).join();
}
}
use of software.amazon.awssdk.crt.auth.credentials.CredentialsProvider in project aws-crt-java by awslabs.
the class S3NativeClientTest method testGetObjectVersioned.
@Test
public void testGetObjectVersioned() {
skipIfNetworkUnavailable();
try (final EventLoopGroup elGroup = new EventLoopGroup(DEFAULT_NUM_THREADS);
final HostResolver resolver = new HostResolver(elGroup, DEFAULT_MAX_HOST_ENTRIES);
final ClientBootstrap clientBootstrap = new ClientBootstrap(elGroup, resolver);
final CredentialsProvider provider = getTestCredentialsProvider();
final S3NativeClient nativeClient = new S3NativeClient(REGION, clientBootstrap, provider, 64_000_000l, 100.)) {
final long[] length = { 0 };
nativeClient.getObject(GetObjectRequest.builder().bucket(BUCKET).key(GET_OBJECT_KEY).versionId(GET_OBJECT_VERSION).build(), new ResponseDataConsumer<GetObjectOutput>() {
@Override
public void onResponse(GetObjectOutput response) {
assertNotNull(response);
assertEquals(response.versionId(), GET_OBJECT_VERSION);
}
@Override
public void onResponseData(ByteBuffer bodyBytesIn) {
length[0] += bodyBytesIn.remaining();
}
@Override
public void onFinished() {
}
@Override
public void onException(final CrtRuntimeException e) {
}
}).join();
}
}
Aggregations