Skip to content

Commit 7fe4933

Browse files
committed
IcebergCatalogAdapterTest: Added test to ensure refresh credentials endpoint is included
1 parent eb3e360 commit 7fe4933

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapterTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@
1919

2020
package org.apache.polaris.service.catalog.iceberg;
2121

22+
import static org.assertj.core.api.Assertions.assertThat;
23+
2224
import java.io.IOException;
2325
import java.lang.reflect.Field;
2426
import java.util.List;
2527
import java.util.Map;
2628
import java.util.stream.Stream;
2729
import org.apache.iceberg.Schema;
30+
import org.apache.iceberg.aws.AwsClientProperties;
2831
import org.apache.iceberg.catalog.Namespace;
2932
import org.apache.iceberg.catalog.TableIdentifier;
3033
import org.apache.iceberg.inmemory.InMemoryCatalog;
34+
import org.apache.iceberg.rest.requests.CreateTableRequest;
3135
import org.apache.iceberg.rest.responses.ListNamespacesResponse;
3236
import org.apache.iceberg.rest.responses.ListTablesResponse;
37+
import org.apache.iceberg.rest.responses.LoadTableResponse;
38+
import org.apache.iceberg.types.Types;
3339
import org.apache.polaris.core.admin.model.AuthenticationParameters;
3440
import org.apache.polaris.core.admin.model.AwsStorageConfigInfo;
3541
import org.apache.polaris.core.admin.model.BearerAuthenticationParameters;
@@ -43,6 +49,7 @@
4349
import org.assertj.core.api.Assertions;
4450
import org.assertj.core.util.Strings;
4551
import org.junit.jupiter.api.BeforeEach;
52+
import org.junit.jupiter.api.Test;
4653
import org.junit.jupiter.params.ParameterizedTest;
4754
import org.junit.jupiter.params.provider.Arguments;
4855
import org.junit.jupiter.params.provider.MethodSource;
@@ -242,4 +249,60 @@ private static Stream<Arguments> paginationTestCases() {
242249
Arguments.of("5", 5),
243250
Arguments.of("5", 10));
244251
}
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+
}
245308
}

0 commit comments

Comments
 (0)