[fix](show-table-status) fix priv error on show table status stmt (#22918)
This commit is contained in:
@ -26,6 +26,7 @@ import org.apache.doris.analysis.CreateViewStmt;
|
||||
import org.apache.doris.analysis.DropCatalogStmt;
|
||||
import org.apache.doris.analysis.GrantStmt;
|
||||
import org.apache.doris.analysis.ShowCatalogStmt;
|
||||
import org.apache.doris.analysis.ShowTableStatusStmt;
|
||||
import org.apache.doris.analysis.UserIdentity;
|
||||
import org.apache.doris.catalog.Column;
|
||||
import org.apache.doris.catalog.Env;
|
||||
@ -39,6 +40,7 @@ import org.apache.doris.mysql.privilege.Auth;
|
||||
import org.apache.doris.mysql.privilege.CatalogAccessController;
|
||||
import org.apache.doris.mysql.privilege.PrivPredicate;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
import org.apache.doris.qe.ShowExecutor;
|
||||
import org.apache.doris.qe.ShowResultSet;
|
||||
import org.apache.doris.utframe.TestWithFeService;
|
||||
|
||||
@ -80,6 +82,17 @@ public class ColumnPrivTest extends TestWithFeService {
|
||||
rootCtx);
|
||||
env.getCatalogMgr().createCatalog(testCatalog);
|
||||
|
||||
CreateCatalogStmt testCatalog2 = (CreateCatalogStmt) parseAndAnalyzeStmt(
|
||||
"create catalog test2 properties(\n"
|
||||
+ " \"type\" = \"test\",\n"
|
||||
+ " \"catalog_provider.class\" "
|
||||
+ "= \"org.apache.doris.datasource.ColumnPrivTest$MockedCatalogProvider\",\n"
|
||||
+ " \"access_controller.properties.key1\" = \"val1\",\n"
|
||||
+ " \"access_controller.properties.key2\" = \"val2\"\n"
|
||||
+ ");",
|
||||
rootCtx);
|
||||
env.getCatalogMgr().createCatalog(testCatalog2);
|
||||
|
||||
// 2. create internal db and tbl
|
||||
CreateDbStmt createDbStmt = (CreateDbStmt) parseAndAnalyzeStmt("create database innerdb1");
|
||||
env.createDb(createDbStmt);
|
||||
@ -132,7 +145,7 @@ public class ColumnPrivTest extends TestWithFeService {
|
||||
String showCatalogSql = "SHOW CATALOGS";
|
||||
ShowCatalogStmt showStmt = (ShowCatalogStmt) parseAndAnalyzeStmt(showCatalogSql);
|
||||
ShowResultSet showResultSet = mgr.showCatalogs(showStmt);
|
||||
Assertions.assertEquals(2, showResultSet.getResultRows().size());
|
||||
Assertions.assertEquals(3, showResultSet.getResultRows().size());
|
||||
|
||||
CreateRoleStmt createRole1 = (CreateRoleStmt) parseAndAnalyzeStmt("create role role1;", rootCtx);
|
||||
auth.createRole(createRole1);
|
||||
@ -197,12 +210,38 @@ public class ColumnPrivTest extends TestWithFeService {
|
||||
testSql(user1Ctx, "select * from numbers(\"number\" = \"1\");", "0:VDataGenScanNode");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowTableStatusPrivs() throws Exception {
|
||||
ConnectContext root = createCtx(UserIdentity.ROOT, "127.0.0.1");
|
||||
CreateUserStmt createUserStmt = (CreateUserStmt) parseAndAnalyzeStmt("create user show_table_status"
|
||||
+ " identified by '123456'", root);
|
||||
auth.createUser(createUserStmt);
|
||||
GrantStmt grant = (GrantStmt) parseAndAnalyzeStmt(
|
||||
"grant select_priv on test2.*.* to show_table_status;", root);
|
||||
auth.grant(grant);
|
||||
|
||||
UserIdentity user = UserIdentity.createAnalyzedUserIdentWithIp("default_cluster:show_table_status", "%");
|
||||
ConnectContext userCtx = createCtx(user, "127.0.0.1");
|
||||
|
||||
ShowTableStatusStmt stmt = (ShowTableStatusStmt) parseAndAnalyzeStmt(
|
||||
"show table status from test2.db1 LIKE \"%tbl%\";");
|
||||
ShowExecutor executor = new ShowExecutor(userCtx, stmt);
|
||||
ShowResultSet resultSet = executor.execute();
|
||||
Assert.assertEquals(2, resultSet.getResultRows().size());
|
||||
}
|
||||
|
||||
private void testSql(ConnectContext ctx, String sql, String expectedMsg) throws Exception {
|
||||
String res = getSQLPlanOrErrorMsg(ctx, "explain " + sql, false);
|
||||
System.out.println(res);
|
||||
Assert.assertTrue(res.contains(expectedMsg));
|
||||
}
|
||||
|
||||
private void testShow(ConnectContext ctx, String sql, String expectedMsg) throws Exception {
|
||||
String res = getSQLPlanOrErrorMsg(ctx, "explain " + sql, false);
|
||||
System.out.println(res);
|
||||
Assert.assertTrue(res.contains(expectedMsg));
|
||||
}
|
||||
|
||||
public static class TestAccessControllerFactory implements AccessControllerFactory {
|
||||
@Override
|
||||
public CatalogAccessController createAccessController(Map<String, String> prop) {
|
||||
|
||||
Reference in New Issue
Block a user