|
19 | 19 |
|
20 | 20 | package org.apache.polaris.service.catalog.iceberg; |
21 | 21 |
|
| 22 | +import static org.assertj.core.api.Assertions.assertThat; |
| 23 | + |
22 | 24 | import java.io.IOException; |
23 | 25 | import java.lang.reflect.Field; |
24 | 26 | import java.util.List; |
25 | 27 | import java.util.Map; |
26 | 28 | import java.util.stream.Stream; |
27 | 29 | import org.apache.iceberg.Schema; |
| 30 | +import org.apache.iceberg.aws.AwsClientProperties; |
28 | 31 | import org.apache.iceberg.catalog.Namespace; |
29 | 32 | import org.apache.iceberg.catalog.TableIdentifier; |
30 | 33 | import org.apache.iceberg.inmemory.InMemoryCatalog; |
| 34 | +import org.apache.iceberg.rest.requests.CreateTableRequest; |
31 | 35 | import org.apache.iceberg.rest.responses.ListNamespacesResponse; |
32 | 36 | import org.apache.iceberg.rest.responses.ListTablesResponse; |
| 37 | +import org.apache.iceberg.rest.responses.LoadTableResponse; |
| 38 | +import org.apache.iceberg.types.Types; |
33 | 39 | import org.apache.polaris.core.admin.model.AuthenticationParameters; |
34 | 40 | import org.apache.polaris.core.admin.model.AwsStorageConfigInfo; |
35 | 41 | import org.apache.polaris.core.admin.model.BearerAuthenticationParameters; |
|
43 | 49 | import org.assertj.core.api.Assertions; |
44 | 50 | import org.assertj.core.util.Strings; |
45 | 51 | import org.junit.jupiter.api.BeforeEach; |
| 52 | +import org.junit.jupiter.api.Test; |
46 | 53 | import org.junit.jupiter.params.ParameterizedTest; |
47 | 54 | import org.junit.jupiter.params.provider.Arguments; |
48 | 55 | import org.junit.jupiter.params.provider.MethodSource; |
@@ -242,4 +249,60 @@ private static Stream<Arguments> paginationTestCases() { |
242 | 249 | Arguments.of("5", 5), |
243 | 250 | Arguments.of("5", 10)); |
244 | 251 | } |
| 252 | + |
| 253 | + @Test |
| 254 | + void testLoadTableReturnsCredentialsRefreshEndpoint() throws IOException { |
| 255 | + try (InMemoryCatalog inMemoryCatalog = new InMemoryCatalog()) { |
| 256 | + // Initialize and replace the default handler with one backed by in-memory catalog |
| 257 | + inMemoryCatalog.initialize("inMemory", Map.of()); |
| 258 | + mockCatalogAdapter(inMemoryCatalog); |
| 259 | + |
| 260 | + // Create a namespace and table |
| 261 | + String namespace = "test_ns"; |
| 262 | + String tableName = "test_table"; |
| 263 | + inMemoryCatalog.createNamespace(Namespace.of(namespace)); |
| 264 | + |
| 265 | + Schema schema = |
| 266 | + new Schema( |
| 267 | + Types.NestedField.required(1, "id", Types.LongType.get()), |
| 268 | + Types.NestedField.optional(2, "name", Types.StringType.get())); |
| 269 | + |
| 270 | + CreateTableRequest createTableRequest = |
| 271 | + CreateTableRequest.builder().withName(tableName).withSchema(schema).build(); |
| 272 | + |
| 273 | + // Create the table first |
| 274 | + catalogAdapter.createTable( |
| 275 | + FEDERATED_CATALOG_NAME, |
| 276 | + namespace, |
| 277 | + createTableRequest, |
| 278 | + "vended-credentials", |
| 279 | + testServices.realmContext(), |
| 280 | + testServices.securityContext()); |
| 281 | + |
| 282 | + // Load the table with vended credentials access delegation mode |
| 283 | + LoadTableResponse response = |
| 284 | + (LoadTableResponse) |
| 285 | + catalogAdapter |
| 286 | + .loadTable( |
| 287 | + FEDERATED_CATALOG_NAME, |
| 288 | + namespace, |
| 289 | + tableName, |
| 290 | + "vended-credentials", |
| 291 | + null, |
| 292 | + null, |
| 293 | + testServices.realmContext(), |
| 294 | + testServices.securityContext()) |
| 295 | + .getEntity(); |
| 296 | + |
| 297 | + // Verify that the response contains the credentials refresh endpoint configuration |
| 298 | + assertThat(response.config()).containsKey(AwsClientProperties.REFRESH_CREDENTIALS_ENDPOINT); |
| 299 | + |
| 300 | + String expectedEndpoint = |
| 301 | + String.format( |
| 302 | + "v1/%s/namespaces/%s/tables/%s/credentials", |
| 303 | + FEDERATED_CATALOG_NAME, namespace, tableName); |
| 304 | + assertThat(response.config().get(AwsClientProperties.REFRESH_CREDENTIALS_ENDPOINT)) |
| 305 | + .isEqualTo(expectedEndpoint); |
| 306 | + } |
| 307 | + } |
245 | 308 | } |
0 commit comments