|
23 | 23 | import java.util.HashMap;
|
24 | 24 | import java.util.List;
|
25 | 25 | import java.util.Map;
|
| 26 | +import org.apache.pulsar.jcloud.shade.com.google.common.base.Supplier; |
26 | 27 |
|
| 28 | +import org.jclouds.domain.Credentials; |
27 | 29 | import org.testng.annotations.Test;
|
28 | 30 |
|
29 | 31 | public class TieredStorageConfigurationTests {
|
@@ -113,7 +115,36 @@ public final void awsS3BackwardCompatiblePropertiesTest() {
|
113 | 115 | assertEquals(config.getReadBufferSizeInBytes(), new Integer(500));
|
114 | 116 | assertEquals(config.getServiceEndpoint(), "http://some-url:9093");
|
115 | 117 | }
|
116 |
| - |
| 118 | + |
| 119 | + /** |
| 120 | + * Confirm that with AWS we create different instances of the credentials |
| 121 | + * object each time we call the supplier, this ensure that we get fresh credentials |
| 122 | + * if the aws credential provider changes |
| 123 | + */ |
| 124 | + @Test |
| 125 | + public final void awsS3CredsProviderTest() { |
| 126 | + Map<String, String> map = new HashMap<>(); |
| 127 | + map.put(TieredStorageConfiguration.BLOB_STORE_PROVIDER_KEY, JCloudBlobStoreProvider.AWS_S3.getDriver()); |
| 128 | + TieredStorageConfiguration config = new TieredStorageConfiguration(map); |
| 129 | + |
| 130 | + // set the aws properties with fake creds so the defaultProviderChain works |
| 131 | + System.setProperty("aws.accessKeyId", "fakeid1"); |
| 132 | + System.setProperty("aws.secretKey", "fakekey1"); |
| 133 | + Credentials creds1 = config.getProviderCredentials().get(); |
| 134 | + assertEquals(creds1.identity, "fakeid1"); |
| 135 | + assertEquals(creds1.credential, "fakekey1"); |
| 136 | + |
| 137 | + // reset the properties and ensure we get different values by re-evaluating the chain |
| 138 | + System.setProperty("aws.accessKeyId", "fakeid2"); |
| 139 | + System.setProperty("aws.secretKey", "fakekey2"); |
| 140 | + Credentials creds2 = config.getProviderCredentials().get(); |
| 141 | + assertEquals(creds2.identity, "fakeid2"); |
| 142 | + assertEquals(creds2.credential, "fakekey2"); |
| 143 | + |
| 144 | + System.clearProperty("aws.accessKeyId"); |
| 145 | + System.clearProperty("aws.secretKey"); |
| 146 | + } |
| 147 | + |
117 | 148 | /**
|
118 | 149 | * Confirm that both property options are available for GCS
|
119 | 150 | */
|
@@ -177,25 +208,4 @@ public final void gcsBackwardCompatiblePropertiesTest() {
|
177 | 208 | assertEquals(config.getMaxBlockSizeInBytes(), new Integer(12));
|
178 | 209 | assertEquals(config.getReadBufferSizeInBytes(), new Integer(500));
|
179 | 210 | }
|
180 |
| - |
181 |
| - /** |
182 |
| - * Confirm that we can configure AWS using the old properties |
183 |
| - */ |
184 |
| - @Test |
185 |
| - public final void s3BackwardCompatiblePropertiesTest() { |
186 |
| - Map<String, String> map = new HashMap<String,String>(); |
187 |
| - map.put(TieredStorageConfiguration.BLOB_STORE_PROVIDER_KEY, JCloudBlobStoreProvider.AWS_S3.getDriver()); |
188 |
| - map.put(BC_S3_BUCKET, "test bucket"); |
189 |
| - map.put(BC_S3_ENDPOINT, "http://some-url:9093"); |
190 |
| - map.put(BC_S3_MAX_BLOCK_SIZE, "12"); |
191 |
| - map.put(BC_S3_READ_BUFFER_SIZE, "500"); |
192 |
| - map.put(BC_S3_REGION, "test region"); |
193 |
| - TieredStorageConfiguration config = new TieredStorageConfiguration(map); |
194 |
| - |
195 |
| - assertEquals(config.getRegion(), "test region"); |
196 |
| - assertEquals(config.getBucket(), "test bucket"); |
197 |
| - assertEquals(config.getMaxBlockSizeInBytes(), new Integer(12)); |
198 |
| - assertEquals(config.getReadBufferSizeInBytes(), new Integer(500)); |
199 |
| - assertEquals(config.getServiceEndpoint(), "http://some-url:9093"); |
200 |
| - } |
201 | 211 | }
|
0 commit comments