From 4b860187c533e79a7e826b8e6741b17ddb23591a Mon Sep 17 00:00:00 2001 From: tsreaper Date: Tue, 7 May 2024 15:12:46 +0800 Subject: [PATCH] [test] Add more tests for PrivilegedCatalog (#3303) --- .../paimon/privilege/PrivilegedCatalog.java | 8 ++++++++ .../privilege/PrivilegeProcedureITCase.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java index 7c2ab94936f7..851cc302afd3 100644 --- a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java @@ -54,6 +54,14 @@ public PrivilegedCatalog(Catalog wrapped, PrivilegeManager privilegeManager) { this.privilegeManager = privilegeManager; } + public Catalog wrapped() { + return wrapped; + } + + public PrivilegeManager privilegeManager() { + return privilegeManager; + } + @Override public boolean caseSensitive() { return wrapped.caseSensitive(); diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/privilege/PrivilegeProcedureITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/privilege/PrivilegeProcedureITCase.java index d432c02eab89..e0c5f5d66722 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/privilege/PrivilegeProcedureITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/procedure/privilege/PrivilegeProcedureITCase.java @@ -18,8 +18,13 @@ package org.apache.paimon.flink.procedure.privilege; +import org.apache.paimon.catalog.Catalog; +import org.apache.paimon.catalog.FileSystemCatalog; +import org.apache.paimon.flink.FlinkCatalog; import org.apache.paimon.flink.util.AbstractTestBase; +import org.apache.paimon.privilege.FileBasedPrivilegeManager; import org.apache.paimon.privilege.NoPrivilegeException; +import org.apache.paimon.privilege.PrivilegedCatalog; import org.apache.flink.table.api.TableEnvironment; import org.apache.flink.types.Row; @@ -74,6 +79,17 @@ public void testUserPrivileges() throws Exception { + " 'warehouse' = '%s'\n" + ")", path)); + + org.apache.flink.table.catalog.Catalog catalog = tEnv.getCatalog("anonymouscat").get(); + assertThat(catalog).isInstanceOf(FlinkCatalog.class); + Catalog paimonCatalog = ((FlinkCatalog) catalog).catalog(); + assertThat(paimonCatalog).isInstanceOf(PrivilegedCatalog.class); + PrivilegedCatalog privilegedCatalog = (PrivilegedCatalog) paimonCatalog; + assertThat(privilegedCatalog.wrapped()).isInstanceOf(FileSystemCatalog.class); + assertThat(privilegedCatalog.privilegeManager()) + .isInstanceOf(FileBasedPrivilegeManager.class); + assertThat(privilegedCatalog.privilegeManager().privilegeEnabled()).isTrue(); + tEnv.executeSql("USE CATALOG anonymouscat"); assertNoPrivilege( () -> tEnv.executeSql("INSERT INTO mydb.T1 VALUES (1, 11), (2, 21)").await());