|
@@ -7,7 +7,7 @@
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
*
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
@@ -30,42 +30,45 @@ import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.Future;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
-import com.amazonaws.auth.AWSCredentials;
|
|
|
-import com.amazonaws.auth.AWSCredentialsProvider;
|
|
|
-import com.amazonaws.auth.ContainerCredentialsProvider;
|
|
|
+import org.assertj.core.api.Assertions;
|
|
|
+import org.junit.Test;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
|
|
import software.amazon.awssdk.auth.credentials.AwsCredentials;
|
|
|
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
|
|
|
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
|
|
|
import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
|
|
|
|
|
|
-import org.apache.hadoop.fs.s3a.adapter.V1V2AwsCredentialProviderAdapter;
|
|
|
-import org.apache.hadoop.util.Sets;
|
|
|
-import org.junit.Rule;
|
|
|
-import org.junit.Test;
|
|
|
-import org.junit.rules.ExpectedException;
|
|
|
-
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.fs.s3a.auth.AbstractSessionCredentialsProvider;
|
|
|
import org.apache.hadoop.fs.s3a.auth.AssumedRoleCredentialProvider;
|
|
|
+import org.apache.hadoop.fs.s3a.auth.IAMInstanceCredentialsProvider;
|
|
|
import org.apache.hadoop.fs.s3a.auth.NoAuthWithAWSException;
|
|
|
+import org.apache.hadoop.fs.s3a.impl.InstantiationIOException;
|
|
|
import org.apache.hadoop.io.retry.RetryPolicy;
|
|
|
+import org.apache.hadoop.util.Sets;
|
|
|
|
|
|
-import static org.apache.hadoop.fs.s3a.Constants.*;
|
|
|
-import static org.apache.hadoop.fs.s3a.S3ATestConstants.*;
|
|
|
-import static org.apache.hadoop.fs.s3a.S3ATestUtils.*;
|
|
|
-import static org.apache.hadoop.fs.s3a.S3AUtils.*;
|
|
|
-import static org.apache.hadoop.fs.s3a.auth.AwsCredentialListProvider.ABSTRACT_PROVIDER;
|
|
|
-import static org.apache.hadoop.fs.s3a.auth.AwsCredentialListProvider.NOT_AWS_V2_PROVIDER;
|
|
|
-import static org.apache.hadoop.fs.s3a.auth.AwsCredentialListProvider.STANDARD_AWS_PROVIDERS;
|
|
|
-import static org.apache.hadoop.fs.s3a.auth.AwsCredentialListProvider.buildAWSProviderList;
|
|
|
-import static org.apache.hadoop.fs.s3a.auth.AwsCredentialListProvider.createAWSCredentialProviderSet;
|
|
|
+import static org.apache.hadoop.fs.s3a.Constants.ASSUMED_ROLE_CREDENTIALS_PROVIDER;
|
|
|
+import static org.apache.hadoop.fs.s3a.Constants.AWS_CREDENTIALS_PROVIDER;
|
|
|
+import static org.apache.hadoop.fs.s3a.S3ATestConstants.DEFAULT_CSVTEST_FILE;
|
|
|
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.authenticationContains;
|
|
|
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.buildClassListString;
|
|
|
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.getCSVTestPath;
|
|
|
+import static org.apache.hadoop.fs.s3a.auth.CredentialProviderListFactory.STANDARD_AWS_PROVIDERS;
|
|
|
+import static org.apache.hadoop.fs.s3a.auth.CredentialProviderListFactory.buildAWSProviderList;
|
|
|
+import static org.apache.hadoop.fs.s3a.auth.CredentialProviderListFactory.createAWSCredentialProviderList;
|
|
|
+import static org.apache.hadoop.fs.s3a.impl.InstantiationIOException.DOES_NOT_IMPLEMENT;
|
|
|
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
|
import static org.apache.hadoop.test.LambdaTestUtils.interceptFuture;
|
|
|
-import static org.junit.Assert.*;
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
|
+import static org.junit.Assert.assertNotNull;
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
/**
|
|
|
* Unit tests for {@link Constants#AWS_CREDENTIALS_PROVIDER} logic.
|
|
@@ -78,19 +81,18 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
private static final URI TESTFILE_URI = new Path(
|
|
|
DEFAULT_CSVTEST_FILE).toUri();
|
|
|
|
|
|
- @Rule
|
|
|
- public ExpectedException exception = ExpectedException.none();
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(TestS3AAWSCredentialsProvider.class);
|
|
|
|
|
|
@Test
|
|
|
public void testProviderWrongClass() throws Exception {
|
|
|
expectProviderInstantiationFailure(this.getClass(),
|
|
|
- NOT_AWS_V2_PROVIDER);
|
|
|
+ DOES_NOT_IMPLEMENT + " software.amazon.awssdk.auth.credentials.AwsCredentialsProvider");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testProviderAbstractClass() throws Exception {
|
|
|
expectProviderInstantiationFailure(AbstractProvider.class,
|
|
|
- ABSTRACT_PROVIDER);
|
|
|
+ InstantiationIOException.ABSTRACT_PROVIDER);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -103,14 +105,14 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
public void testProviderConstructorError() throws Exception {
|
|
|
expectProviderInstantiationFailure(
|
|
|
ConstructorSignatureErrorProvider.class,
|
|
|
- CONSTRUCTOR_EXCEPTION);
|
|
|
+ InstantiationIOException.CONSTRUCTOR_EXCEPTION);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testProviderFailureError() throws Exception {
|
|
|
expectProviderInstantiationFailure(
|
|
|
ConstructorFailureProvider.class,
|
|
|
- INSTANTIATION_EXCEPTION);
|
|
|
+ InstantiationIOException.INSTANTIATION_EXCEPTION);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -122,7 +124,7 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
+ " ,\n " + AnonymousAWSCredentialsProvider.NAME);
|
|
|
Path testFile = getCSVTestPath(conf);
|
|
|
|
|
|
- AWSCredentialProviderList list = createAWSCredentialProviderSet(
|
|
|
+ AWSCredentialProviderList list = createAWSCredentialProviderList(
|
|
|
testFile.toUri(), conf);
|
|
|
List<Class<?>> expectedClasses =
|
|
|
Arrays.asList(
|
|
@@ -138,9 +140,9 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
Configuration conf = new Configuration(false);
|
|
|
// use the default credential provider chain
|
|
|
conf.unset(AWS_CREDENTIALS_PROVIDER);
|
|
|
- AWSCredentialProviderList list1 = createAWSCredentialProviderSet(
|
|
|
+ AWSCredentialProviderList list1 = createAWSCredentialProviderList(
|
|
|
uri1, conf);
|
|
|
- AWSCredentialProviderList list2 = createAWSCredentialProviderSet(
|
|
|
+ AWSCredentialProviderList list2 = createAWSCredentialProviderList(
|
|
|
uri2, conf);
|
|
|
List<Class<?>> expectedClasses = STANDARD_AWS_PROVIDERS;
|
|
|
assertCredentialProviders(expectedClasses, list1);
|
|
@@ -153,28 +155,7 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
// use the default credential provider chain
|
|
|
conf.unset(AWS_CREDENTIALS_PROVIDER);
|
|
|
assertCredentialProviders(STANDARD_AWS_PROVIDERS,
|
|
|
- createAWSCredentialProviderSet(null, conf));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testConfiguredChainV1V2() throws Exception {
|
|
|
- URI uri1 = new URI("s3a://bucket1"), uri2 = new URI("s3a://bucket2");
|
|
|
- List<Class<?>> credentialProviders =
|
|
|
- Arrays.asList(
|
|
|
- ContainerCredentialsProvider.class,
|
|
|
- AnonymousAWSCredentialsProvider.class);
|
|
|
- List<Class<?>> expectedClasses =
|
|
|
- Arrays.asList(
|
|
|
- V1V2AwsCredentialProviderAdapter.class,
|
|
|
- AnonymousAWSCredentialsProvider.class);
|
|
|
- Configuration conf =
|
|
|
- createProviderConfiguration(buildClassListString(credentialProviders));
|
|
|
- AWSCredentialProviderList list1 = createAWSCredentialProviderSet(
|
|
|
- uri1, conf);
|
|
|
- AWSCredentialProviderList list2 = createAWSCredentialProviderSet(
|
|
|
- uri2, conf);
|
|
|
- assertCredentialProviders(expectedClasses, list1);
|
|
|
- assertCredentialProviders(expectedClasses, list2);
|
|
|
+ createAWSCredentialProviderList(null, conf));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -182,14 +163,15 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
URI uri1 = new URI("s3a://bucket1"), uri2 = new URI("s3a://bucket2");
|
|
|
List<Class<?>> expectedClasses =
|
|
|
Arrays.asList(
|
|
|
- EnvironmentVariableCredentialsProvider.class,
|
|
|
- InstanceProfileCredentialsProvider.class,
|
|
|
- AnonymousAWSCredentialsProvider.class);
|
|
|
+ IAMInstanceCredentialsProvider.class,
|
|
|
+ AnonymousAWSCredentialsProvider.class,
|
|
|
+ EnvironmentVariableCredentialsProvider.class
|
|
|
+ );
|
|
|
Configuration conf =
|
|
|
createProviderConfiguration(buildClassListString(expectedClasses));
|
|
|
- AWSCredentialProviderList list1 = createAWSCredentialProviderSet(
|
|
|
+ AWSCredentialProviderList list1 = createAWSCredentialProviderList(
|
|
|
uri1, conf);
|
|
|
- AWSCredentialProviderList list2 = createAWSCredentialProviderSet(
|
|
|
+ AWSCredentialProviderList list2 = createAWSCredentialProviderList(
|
|
|
uri2, conf);
|
|
|
assertCredentialProviders(expectedClasses, list1);
|
|
|
assertCredentialProviders(expectedClasses, list2);
|
|
@@ -203,9 +185,9 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
Arrays.asList(
|
|
|
InstanceProfileCredentialsProvider.class);
|
|
|
conf.set(AWS_CREDENTIALS_PROVIDER, buildClassListString(expectedClasses));
|
|
|
- AWSCredentialProviderList list1 = createAWSCredentialProviderSet(
|
|
|
+ AWSCredentialProviderList list1 = createAWSCredentialProviderList(
|
|
|
uri1, conf);
|
|
|
- AWSCredentialProviderList list2 = createAWSCredentialProviderSet(
|
|
|
+ AWSCredentialProviderList list2 = createAWSCredentialProviderList(
|
|
|
uri2, conf);
|
|
|
assertCredentialProviders(expectedClasses, list1);
|
|
|
assertCredentialProviders(expectedClasses, list2);
|
|
@@ -222,51 +204,75 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
EnvironmentVariableCredentialsProvider.class),
|
|
|
Sets.newHashSet());
|
|
|
assertTrue("empty credentials", credentials.size() > 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testProviderConstructor() throws Throwable {
|
|
|
+ final AWSCredentialProviderList list = new AWSCredentialProviderList("name",
|
|
|
+ new AnonymousAWSCredentialsProvider(),
|
|
|
+ new ErrorProvider(TESTFILE_URI, new Configuration()));
|
|
|
+ Assertions.assertThat(list.getProviders())
|
|
|
+ .describedAs("provider list in %s", list)
|
|
|
+ .hasSize(2);
|
|
|
+ final AwsCredentials credentials = list.resolveCredentials();
|
|
|
+ Assertions.assertThat(credentials)
|
|
|
+ .isInstanceOf(AwsBasicCredentials.class);
|
|
|
+ assertCredentialResolution(credentials, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void assertCredentialResolution(AwsCredentials creds, String key, String secret) {
|
|
|
+ Assertions.assertThat(creds.accessKeyId())
|
|
|
+ .describedAs("access key of %s", creds)
|
|
|
+ .isEqualTo(key);
|
|
|
+ Assertions.assertThat(creds.secretAccessKey())
|
|
|
+ .describedAs("secret key of %s", creds)
|
|
|
+ .isEqualTo(secret);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildClassList(Class... classes) {
|
|
|
+ return Arrays.stream(classes)
|
|
|
+ .map(Class::getCanonicalName)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ }
|
|
|
|
|
|
+ private String buildClassList(String... classes) {
|
|
|
+ return Arrays.stream(classes)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* A credential provider declared as abstract, so it cannot be instantiated.
|
|
|
*/
|
|
|
- static abstract class AbstractProvider implements AWSCredentialsProvider {
|
|
|
+ static abstract class AbstractProvider implements AwsCredentialsProvider {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AwsCredentials resolveCredentials() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* A credential provider whose constructor signature doesn't match.
|
|
|
*/
|
|
|
protected static class ConstructorSignatureErrorProvider
|
|
|
- implements AWSCredentialsProvider {
|
|
|
+ extends AbstractProvider {
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
public ConstructorSignatureErrorProvider(String str) {
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public AWSCredentials getCredentials() {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void refresh() {
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* A credential provider whose constructor raises an NPE.
|
|
|
*/
|
|
|
protected static class ConstructorFailureProvider
|
|
|
- implements AwsCredentialsProvider {
|
|
|
+ extends AbstractProvider {
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
public ConstructorFailureProvider() {
|
|
|
throw new NullPointerException("oops");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public AwsCredentials resolveCredentials() {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -279,33 +285,23 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected static class AWSExceptionRaisingFactory implements AWSCredentialsProvider {
|
|
|
+ protected static class AWSExceptionRaisingFactory extends AbstractProvider {
|
|
|
|
|
|
public static final String NO_AUTH = "No auth";
|
|
|
|
|
|
- public static AWSCredentialsProvider getInstance() {
|
|
|
+ public static AwsCredentialsProvider create() {
|
|
|
throw new NoAuthWithAWSException(NO_AUTH);
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public AWSCredentials getCredentials() {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void refresh() {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testFactoryWrongType() throws Throwable {
|
|
|
expectProviderInstantiationFailure(
|
|
|
FactoryOfWrongType.class,
|
|
|
- CONSTRUCTOR_EXCEPTION);
|
|
|
+ InstantiationIOException.CONSTRUCTOR_EXCEPTION);
|
|
|
}
|
|
|
|
|
|
- static class FactoryOfWrongType implements AWSCredentialsProvider {
|
|
|
+ static class FactoryOfWrongType extends AbstractProvider {
|
|
|
|
|
|
public static final String NO_AUTH = "No auth";
|
|
|
|
|
@@ -314,14 +310,10 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AWSCredentials getCredentials() {
|
|
|
+ public AwsCredentials resolveCredentials() {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void refresh() {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -334,7 +326,7 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
private IOException expectProviderInstantiationFailure(String option,
|
|
|
String expectedErrorText) throws Exception {
|
|
|
return intercept(IOException.class, expectedErrorText,
|
|
|
- () -> createAWSCredentialProviderSet(
|
|
|
+ () -> createAWSCredentialProviderList(
|
|
|
TESTFILE_URI,
|
|
|
createProviderConfiguration(option)));
|
|
|
}
|
|
@@ -385,7 +377,9 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
AWSCredentialProviderList list) {
|
|
|
assertNotNull(list);
|
|
|
List<AwsCredentialsProvider> providers = list.getProviders();
|
|
|
- assertEquals(expectedClasses.size(), providers.size());
|
|
|
+ Assertions.assertThat(providers)
|
|
|
+ .describedAs("providers")
|
|
|
+ .hasSize(expectedClasses.size());
|
|
|
for (int i = 0; i < expectedClasses.size(); ++i) {
|
|
|
Class<?> expectedClass =
|
|
|
expectedClasses.get(i);
|
|
@@ -493,22 +487,13 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
/**
|
|
|
* Credential provider which raises an IOE when constructed.
|
|
|
*/
|
|
|
- protected static class IOERaisingProvider implements AWSCredentialsProvider {
|
|
|
+ protected static class IOERaisingProvider extends AbstractProvider {
|
|
|
|
|
|
public IOERaisingProvider(URI uri, Configuration conf)
|
|
|
throws IOException {
|
|
|
throw new InterruptedIOException("expected");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public AWSCredentials getCredentials() {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void refresh() {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private static final AwsCredentials EXPECTED_CREDENTIALS =
|
|
@@ -538,13 +523,13 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
Configuration conf = createProviderConfiguration(SlowProvider.class.getName());
|
|
|
Path testFile = getCSVTestPath(conf);
|
|
|
|
|
|
- AWSCredentialProviderList list = createAWSCredentialProviderSet(testFile.toUri(), conf);
|
|
|
+ AWSCredentialProviderList list = createAWSCredentialProviderList(testFile.toUri(), conf);
|
|
|
|
|
|
SlowProvider provider = (SlowProvider) list.getProviders().get(0);
|
|
|
|
|
|
ExecutorService pool = Executors.newFixedThreadPool(CONCURRENT_THREADS);
|
|
|
|
|
|
- List<Future<AWSCredentials>> results = new ArrayList<>();
|
|
|
+ List<Future<AwsCredentials>> results = new ArrayList<>();
|
|
|
|
|
|
try {
|
|
|
assertFalse(
|
|
@@ -560,15 +545,15 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < CONCURRENT_THREADS; i++) {
|
|
|
- results.add(pool.submit(() -> list.getCredentials()));
|
|
|
+ results.add(pool.submit(() -> list.resolveCredentials()));
|
|
|
}
|
|
|
|
|
|
- for (Future<AWSCredentials> result : results) {
|
|
|
- AWSCredentials credentials = result.get();
|
|
|
+ for (Future<AwsCredentials> result : results) {
|
|
|
+ AwsCredentials credentials = result.get();
|
|
|
assertEquals("Access key from credential provider",
|
|
|
- "expectedAccessKey", credentials.getAWSAccessKeyId());
|
|
|
+ "expectedAccessKey", credentials.accessKeyId());
|
|
|
assertEquals("Secret key from credential provider",
|
|
|
- "expectedSecret", credentials.getAWSSecretKey());
|
|
|
+ "expectedSecret", credentials.secretAccessKey());
|
|
|
}
|
|
|
} finally {
|
|
|
pool.awaitTermination(10, TimeUnit.SECONDS);
|
|
@@ -577,7 +562,7 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
|
|
|
assertTrue(
|
|
|
"Provider initialized without errors. isInitialized should be true",
|
|
|
- provider.isInitialized());
|
|
|
+ provider.isInitialized());
|
|
|
assertTrue(
|
|
|
"Provider initialized without errors. hasCredentials should be true",
|
|
|
provider.hasCredentials());
|
|
@@ -608,12 +593,12 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
Configuration conf = createProviderConfiguration(ErrorProvider.class.getName());
|
|
|
Path testFile = getCSVTestPath(conf);
|
|
|
|
|
|
- AWSCredentialProviderList list = createAWSCredentialProviderSet(testFile.toUri(), conf);
|
|
|
+ AWSCredentialProviderList list = createAWSCredentialProviderList(testFile.toUri(), conf);
|
|
|
ErrorProvider provider = (ErrorProvider) list.getProviders().get(0);
|
|
|
|
|
|
ExecutorService pool = Executors.newFixedThreadPool(CONCURRENT_THREADS);
|
|
|
|
|
|
- List<Future<AWSCredentials>> results = new ArrayList<>();
|
|
|
+ List<Future<AwsCredentials>> results = new ArrayList<>();
|
|
|
|
|
|
try {
|
|
|
assertFalse("Provider not initialized. isInitialized should be false",
|
|
@@ -627,10 +612,10 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < CONCURRENT_THREADS; i++) {
|
|
|
- results.add(pool.submit(() -> list.getCredentials()));
|
|
|
+ results.add(pool.submit(() -> list.resolveCredentials()));
|
|
|
}
|
|
|
|
|
|
- for (Future<AWSCredentials> result : results) {
|
|
|
+ for (Future<AwsCredentials> result : results) {
|
|
|
interceptFuture(CredentialInitializationException.class,
|
|
|
"expected error",
|
|
|
result
|
|
@@ -651,4 +636,39 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
"Provider initialization failed. getInitializationException should contain the error",
|
|
|
provider.getInitializationException().getMessage().contains("expected error"));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * V2 Credentials whose factory method raises ClassNotFoundException.
|
|
|
+ * This will fall back to an attempted v1 load which will fail because it
|
|
|
+ * is the wrong type.
|
|
|
+ * The exception raised will be from the v2 instantiation attempt,
|
|
|
+ * not the v1 attempt.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testV2ClassNotFound() throws Throwable {
|
|
|
+ InstantiationIOException expected = intercept(InstantiationIOException.class,
|
|
|
+ "simulated v2 CNFE",
|
|
|
+ () -> createAWSCredentialProviderList(
|
|
|
+ TESTFILE_URI,
|
|
|
+ createProviderConfiguration(V2CredentialProviderDoesNotInstantiate.class.getName())));
|
|
|
+ // print for the curious
|
|
|
+ LOG.info("{}", expected.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * V2 credentials which raises an instantiation exception in
|
|
|
+ * the factory method.
|
|
|
+ */
|
|
|
+ public static final class V2CredentialProviderDoesNotInstantiate
|
|
|
+ extends AbstractProvider {
|
|
|
+
|
|
|
+ private V2CredentialProviderDoesNotInstantiate() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public static AwsCredentialsProvider create() throws ClassNotFoundException {
|
|
|
+ throw new ClassNotFoundException("simulated v2 CNFE");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|