|
28 | 28 | import java.util.List; |
29 | 29 | import java.util.Map; |
30 | 30 | import java.util.Set; |
| 31 | +import java.util.function.Supplier; |
31 | 32 | import org.apache.iceberg.exceptions.ValidationException; |
32 | 33 | import org.apache.polaris.core.PolarisCallContext; |
33 | 34 | import org.apache.polaris.core.admin.model.AwsStorageConfigInfo; |
@@ -68,6 +69,7 @@ public void setup() { |
68 | 69 | services = |
69 | 70 | TestServices.builder() |
70 | 71 | .config(Map.of("SUPPORTED_CATALOG_STORAGE_TYPES", List.of("S3", "GCS", "AZURE"))) |
| 72 | + .config(Map.of("ALLOW_SETTING_S3_ENDPOINTS", Boolean.FALSE)) |
71 | 73 | .build(); |
72 | 74 | } |
73 | 75 |
|
@@ -97,6 +99,51 @@ public void testCreateCatalogWithDisallowedStorageConfig() { |
97 | 99 | .hasMessage("Unsupported storage type: FILE"); |
98 | 100 | } |
99 | 101 |
|
| 102 | + @Test |
| 103 | + public void testCreateCatalogWithDisallowedS3Endpoints() { |
| 104 | + AwsStorageConfigInfo.Builder storageConfig = |
| 105 | + AwsStorageConfigInfo.builder() |
| 106 | + .setRoleArn("arn:aws:iam::123456789012:role/my-role") |
| 107 | + .setExternalId("externalId") |
| 108 | + .setUserArn("userArn") |
| 109 | + .setStorageType(StorageConfigInfo.StorageTypeEnum.S3) |
| 110 | + .setAllowedLocations(List.of("s3://my-old-bucket/path/to/data")); |
| 111 | + String catalogName = "test-catalog"; |
| 112 | + Supplier<Catalog> catalog = |
| 113 | + () -> |
| 114 | + PolarisCatalog.builder() |
| 115 | + .setType(Catalog.TypeEnum.INTERNAL) |
| 116 | + .setName(catalogName) |
| 117 | + .setProperties(new CatalogProperties("s3://bucket/path/to/data")) |
| 118 | + .setStorageConfigInfo(storageConfig.build()) |
| 119 | + .build(); |
| 120 | + Supplier<Response> createCatalog = |
| 121 | + () -> |
| 122 | + services |
| 123 | + .catalogsApi() |
| 124 | + .createCatalog( |
| 125 | + new CreateCatalogRequest(catalog.get()), |
| 126 | + services.realmContext(), |
| 127 | + services.securityContext()); |
| 128 | + |
| 129 | + storageConfig.setEndpoint("http://example.com"); |
| 130 | + assertThatThrownBy(createCatalog::get) |
| 131 | + .isInstanceOf(IllegalArgumentException.class) |
| 132 | + .hasMessage("Explicitly setting S3 endpoints is not allowed."); |
| 133 | + |
| 134 | + storageConfig.setEndpoint(null); |
| 135 | + storageConfig.setStsEndpoint("http://example.com"); |
| 136 | + assertThatThrownBy(createCatalog::get) |
| 137 | + .isInstanceOf(IllegalArgumentException.class) |
| 138 | + .hasMessage("Explicitly setting S3 endpoints is not allowed."); |
| 139 | + |
| 140 | + storageConfig.setStsEndpoint(null); |
| 141 | + storageConfig.setEndpointInternal("http://example.com"); |
| 142 | + assertThatThrownBy(createCatalog::get) |
| 143 | + .isInstanceOf(IllegalArgumentException.class) |
| 144 | + .hasMessage("Explicitly setting S3 endpoints is not allowed."); |
| 145 | + } |
| 146 | + |
100 | 147 | @Test |
101 | 148 | public void testUpdateCatalogWithDisallowedStorageConfig() { |
102 | 149 | AwsStorageConfigInfo awsConfigModel = |
@@ -162,6 +209,23 @@ public void testUpdateCatalogWithDisallowedStorageConfig() { |
162 | 209 | services.securityContext())) |
163 | 210 | .isInstanceOf(IllegalArgumentException.class) |
164 | 211 | .hasMessage("Unsupported storage type: FILE"); |
| 212 | + |
| 213 | + UpdateCatalogRequest update2 = |
| 214 | + new UpdateCatalogRequest( |
| 215 | + fetchedCatalog.getEntityVersion(), |
| 216 | + Map.of(), |
| 217 | + AwsStorageConfigInfo.builder(StorageConfigInfo.StorageTypeEnum.S3) |
| 218 | + .setRoleArn("arn:aws:iam::123456789012:role/my-role") |
| 219 | + .setEndpoint("http://example.com") |
| 220 | + .build()); |
| 221 | + assertThatThrownBy( |
| 222 | + () -> |
| 223 | + services |
| 224 | + .catalogsApi() |
| 225 | + .updateCatalog( |
| 226 | + catalogName, update2, services.realmContext(), services.securityContext())) |
| 227 | + .isInstanceOf(IllegalArgumentException.class) |
| 228 | + .hasMessage("Explicitly setting S3 endpoints is not allowed."); |
165 | 229 | } |
166 | 230 |
|
167 | 231 | private PolarisMetaStoreManager setupMetaStoreManager() { |
|
0 commit comments