Skip to content

Commit 8b94286

Browse files
committed
Fix integration test
1 parent 68e53c8 commit 8b94286

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

integration-tests/src/main/java/org/apache/polaris/service/it/test/CatalogFederationIntegrationTest.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public class CatalogFederationIntegrationTest {
8888
private static String federatedCatalogRoleName;
8989
private static URI localStorageBase;
9090
private static URI remoteStorageBase;
91-
private static URI remoteStorageExtraAllowedLocation;
91+
private static URI remoteStorageExtraAllowedLocationNs1;
92+
private static URI remoteStorageExtraAllowedLocationNs2;
9293
private static String endpoint;
9394

9495
private static final String PRINCIPAL_NAME = "test-catalog-federation-user";
@@ -118,8 +119,10 @@ static void setup(
118119
localStorageBase = minioAccess.s3BucketUri(BUCKET_URI_PREFIX + "/local_catalog");
119120
remoteStorageBase = minioAccess.s3BucketUri(BUCKET_URI_PREFIX + "/federated_catalog");
120121
// Allow credential vending for tables located under ns1
121-
remoteStorageExtraAllowedLocation =
122+
remoteStorageExtraAllowedLocationNs1 =
122123
minioAccess.s3BucketUri(BUCKET_URI_PREFIX + "/local_catalog/ns1");
124+
remoteStorageExtraAllowedLocationNs2 =
125+
minioAccess.s3BucketUri(BUCKET_URI_PREFIX + "/local_catalog/ns2");
123126
}
124127

125128
@AfterAll
@@ -206,7 +209,10 @@ private void setupCatalogs() {
206209
.setPathStyleAccess(true)
207210
.setEndpoint(endpoint)
208211
.setAllowedLocations(
209-
List.of(remoteStorageBase.toString(), remoteStorageExtraAllowedLocation.toString()))
212+
List.of(
213+
remoteStorageBase.toString(),
214+
remoteStorageExtraAllowedLocationNs1.toString(),
215+
remoteStorageExtraAllowedLocationNs2.toString()))
210216
.build();
211217
ExternalCatalog externalCatalog =
212218
ExternalCatalog.builder()
@@ -259,6 +265,11 @@ private void setupExampleNamespacesAndTables() {
259265
spark.sql("INSERT INTO ns2.test_table VALUES (1, 'Apache Spark')");
260266
spark.sql("INSERT INTO ns2.test_table VALUES (2, 'Apache Iceberg')");
261267

268+
spark.sql("CREATE NAMESPACE IF NOT EXISTS ns3");
269+
spark.sql("CREATE TABLE IF NOT EXISTS ns3.test_table (id int, name string)");
270+
spark.sql("INSERT INTO ns3.test_table VALUES (1, 'Apache Spark')");
271+
spark.sql("INSERT INTO ns3.test_table VALUES (2, 'Apache Iceberg')");
272+
262273
spark.sql("CREATE NAMESPACE IF NOT EXISTS ns1.ns1a");
263274
spark.sql("CREATE TABLE IF NOT EXISTS ns1.ns1a.test_table (id int, name string)");
264275
spark.sql("INSERT INTO ns1.ns1a.test_table VALUES (1, 'Alice')");
@@ -271,7 +282,7 @@ private void setupExampleNamespacesAndTables() {
271282
void testFederatedCatalogBasicReadWriteOperations() {
272283
spark.sql("USE " + federatedCatalogName);
273284
List<Row> namespaces = spark.sql("SHOW NAMESPACES").collectAsList();
274-
assertThat(namespaces).hasSize(2);
285+
assertThat(namespaces).hasSize(3);
275286
List<Row> ns1Data = spark.sql("SELECT * FROM ns1.test_table ORDER BY id").collectAsList();
276287
List<Row> refNs1Data =
277288
spark
@@ -455,33 +466,33 @@ void testFederatedCatalogNotVendCredentialForTablesOutsideAllowedLocations() {
455466
TableGrant.builder()
456467
.setType(GrantResource.TypeEnum.TABLE)
457468
.setPrivilege(TablePrivilege.TABLE_READ_DATA)
458-
.setNamespace(List.of("ns2"))
469+
.setNamespace(List.of("ns3"))
459470
.setTableName("test_table")
460471
.build();
461472
managementApi.addGrant(federatedCatalogName, federatedCatalogRoleName, tableReadDataGrant);
462473

463-
// Verify that credential vending is blocked for table under ns2, even with enough privilege
464-
assertThatThrownBy(() -> spark.sql("SELECT * FROM ns2.test_table ORDER BY id").collectAsList())
474+
// Verify that credential vending is blocked for table under ns3, even with enough privilege
475+
assertThatThrownBy(() -> spark.sql("SELECT * FROM ns3.test_table ORDER BY id").collectAsList())
465476
.isInstanceOf(ForbiddenException.class)
466477
.hasMessageContaining(
467-
"Table 'ns2.test_table' in remote catalog has locations outside catalog's allowed locations:");
478+
"Table 'ns3.test_table' in remote catalog has locations outside catalog's allowed locations:");
468479

469480
// Case 3: TABLE_WRITE_DATA
470481
managementApi.revokeGrant(federatedCatalogName, federatedCatalogRoleName, tableReadDataGrant);
471482
TableGrant tableWriteDataGrant =
472483
TableGrant.builder()
473484
.setType(GrantResource.TypeEnum.TABLE)
474485
.setPrivilege(TablePrivilege.TABLE_WRITE_DATA)
475-
.setNamespace(List.of("ns2"))
486+
.setNamespace(List.of("ns3"))
476487
.setTableName("test_table")
477488
.build();
478489
managementApi.addGrant(federatedCatalogName, federatedCatalogRoleName, tableWriteDataGrant);
479490

480-
// Verify that credential vending is blocked for table under ns2, even with enough privilege
491+
// Verify that credential vending is blocked for table under ns3, even with enough privilege
481492
assertThatThrownBy(
482-
() -> spark.sql("INSERT INTO ns2.test_table VALUES (3, 'Charlie')").collectAsList())
493+
() -> spark.sql("INSERT INTO ns3.test_table VALUES (3, 'Charlie')").collectAsList())
483494
.isInstanceOf(ForbiddenException.class)
484495
.hasMessageContaining(
485-
"Table 'ns2.test_table' in remote catalog has locations outside catalog's allowed locations:");
496+
"Table 'ns3.test_table' in remote catalog has locations outside catalog's allowed locations:");
486497
}
487498
}

0 commit comments

Comments
 (0)