S3ClientProvider { AWSCredentials getAwsCredentials() { AWSCredentials credentials; if(s3Configuration.isDefaultChainEnabled()) { credentials = new DefaultAWSCredentialsProviderChain().getCredentials(); } else if (s3Configuration.getSessionToken() == null) { credentials = new BasicAWSCredentials(s3Configuration.getAccessKey(), s3Configuration.getSecretKey()); } else { credentials = new BasicSessionCredentials(s3Configuration.getAccessKey(), s3Configuration.getSecretKey(), s3Configuration.getSessionToken()); } return credentials; }  @Bean AmazonS3Client getClient();  }
@Test public void defaultChain() { S3ClientProvider provider = new S3ClientProvider(); S3Configuration s3Configuration = new S3Configuration(null, null, true, null, null, 5, "s3-transfer-manager-worker-", 100); ReflectionTestUtils.setField(provider, "s3Configuration", s3Configuration); System.setProperty("aws.accessKeyId", "fakeKeyId"); System.setProperty("aws.secretKey", "fakeSecretKey"); AWSCredentials credentials = provider.getAwsCredentials(); assertEquals("fakeKeyId", credentials.getAWSAccessKeyId()); assertEquals("fakeSecretKey", credentials.getAWSSecretKey()); }
@Test public void accessKey() { S3ClientProvider provider = new S3ClientProvider(); S3Configuration s3Configuration = new S3Configuration("fakeProvidedKeyId", "fakeProvidedSecretKey", false, null, null, 5, "s3-transfer-manager-worker-", 100); ReflectionTestUtils.setField(provider, "s3Configuration", s3Configuration); AWSCredentials credentials = provider.getAwsCredentials(); assertEquals("fakeProvidedKeyId", credentials.getAWSAccessKeyId()); assertEquals("fakeProvidedSecretKey", credentials.getAWSSecretKey()); }
@Test public void sessionToken() { S3ClientProvider provider = new S3ClientProvider(); S3Configuration s3Configuration = new S3Configuration("fakeProvidedKeyId", "fakeProvidedSecretKey", false, "fakeProvidedSessionToken", null, 5, "s3-transfer-manager-worker-", 100); ReflectionTestUtils.setField(provider, "s3Configuration", s3Configuration); BasicSessionCredentials credentials = (BasicSessionCredentials) provider.getAwsCredentials(); assertEquals("fakeProvidedKeyId", credentials.getAWSAccessKeyId()); assertEquals("fakeProvidedSecretKey", credentials.getAWSSecretKey()); assertEquals("fakeProvidedSessionToken", credentials.getSessionToken()); }