Search in sources :

Example 1 with CredentialsProvider

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);
    }
}
Also used : CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) X509CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider) Test(org.junit.Test)

Example 2 with CredentialsProvider

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);
    }
}
Also used : CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) X509CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider) Test(org.junit.Test)

Example 3 with CredentialsProvider

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);
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) StaticCredentialsProvider(software.amazon.awssdk.crt.auth.credentials.StaticCredentialsProvider) CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) StaticCredentialsProvider(software.amazon.awssdk.crt.auth.credentials.StaticCredentialsProvider) DefaultChainCredentialsProvider(software.amazon.awssdk.crt.auth.credentials.DefaultChainCredentialsProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) Test(org.junit.Test)

Example 4 with CredentialsProvider

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();
    }
}
Also used : software.amazon.awssdk.crt.io(software.amazon.awssdk.crt.io) BeforeClass(org.junit.BeforeClass) DeleteObjectRequest(com.amazonaws.s3.model.DeleteObjectRequest) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) software.amazon.awssdk.crt.s3(software.amazon.awssdk.crt.s3) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) AwsClientTestFixture(com.amazonaws.test.AwsClientTestFixture) GetObjectRequest(com.amazonaws.s3.model.GetObjectRequest) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) GetObjectOutput(com.amazonaws.s3.model.GetObjectOutput) ArgumentCaptor(org.mockito.ArgumentCaptor) PutObjectOutput(com.amazonaws.s3.model.PutObjectOutput) Duration(java.time.Duration) Map(java.util.Map) Assume(org.junit.Assume) CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) ListObjectsRequest(com.amazonaws.s3.model.ListObjectsRequest) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) ListObjectsOutput(com.amazonaws.s3.model.ListObjectsOutput) CancellationException(java.util.concurrent.CancellationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) PutObjectRequest(com.amazonaws.s3.model.PutObjectRequest) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Mockito.any(org.mockito.Mockito.any) Mockito.reset(org.mockito.Mockito.reset) DeleteObjectOutput(com.amazonaws.s3.model.DeleteObjectOutput) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) Test(org.junit.Test)

Example 5 with CredentialsProvider

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();
    }
}
Also used : CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) GetObjectOutput(com.amazonaws.s3.model.GetObjectOutput) CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

CredentialsProvider (software.amazon.awssdk.crt.auth.credentials.CredentialsProvider)20 Test (org.junit.Test)11 GetObjectOutput (com.amazonaws.s3.model.GetObjectOutput)7 ByteBuffer (java.nio.ByteBuffer)7 CrtRuntimeException (software.amazon.awssdk.crt.CrtRuntimeException)7 Test (org.junit.jupiter.api.Test)6 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)6 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)6 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)6 AwsSessionCredentials (software.amazon.awssdk.auth.credentials.AwsSessionCredentials)6 HttpCredentialsProvider (software.amazon.awssdk.auth.credentials.HttpCredentialsProvider)6 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)6 Credentials (software.amazon.awssdk.crt.auth.credentials.Credentials)6 CancellationException (java.util.concurrent.CancellationException)5 CompletionException (java.util.concurrent.CompletionException)4 DeleteObjectOutput (com.amazonaws.s3.model.DeleteObjectOutput)3 DeleteObjectRequest (com.amazonaws.s3.model.DeleteObjectRequest)3 GetObjectRequest (com.amazonaws.s3.model.GetObjectRequest)3 ListObjectsOutput (com.amazonaws.s3.model.ListObjectsOutput)3 ListObjectsRequest (com.amazonaws.s3.model.ListObjectsRequest)3