[improvement](auth) support show all properties (#25645)

support `show all properties`
This commit is contained in:
zhangdong
2023-10-24 17:27:59 +08:00
committed by GitHub
parent 091cb0ce37
commit 4cd0dae4b3
7 changed files with 177 additions and 18 deletions

View File

@ -17,8 +17,9 @@
package org.apache.doris.analysis;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.catalog.Column;
import org.apache.doris.common.UserException;
import org.apache.doris.common.proc.UserPropertyProcNode;
import org.apache.doris.mysql.privilege.AccessControllerManager;
import org.apache.doris.mysql.privilege.MockedAuth;
import org.apache.doris.qe.ConnectContext;
@ -28,6 +29,8 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class ShowUserPropertyStmtTest {
private Analyzer analyzer;
@ -44,9 +47,36 @@ public class ShowUserPropertyStmtTest {
}
@Test
public void testNormal() throws UserException, AnalysisException {
ShowUserPropertyStmt stmt = new ShowUserPropertyStmt("testUser", "%load_cluster%");
public void testNormal() throws UserException {
ShowUserPropertyStmt stmt = new ShowUserPropertyStmt("testUser", "%load_cluster%", false);
stmt.analyze(analyzer);
Assert.assertEquals("SHOW PROPERTY FOR 'testCluster:testUser' LIKE '%load_cluster%'", stmt.toString());
List<Column> columns = stmt.getMetaData().getColumns();
for (int i = 0; i < columns.size(); i++) {
Assert.assertEquals(columns.get(i).getName(), UserPropertyProcNode.TITLE_NAMES.get(i));
}
}
@Test
public void testAll() throws UserException {
ShowUserPropertyStmt stmt = new ShowUserPropertyStmt(null, "%load_cluster%", true);
stmt.analyze(analyzer);
Assert.assertEquals("SHOW ALL PROPERTIES LIKE '%load_cluster%'", stmt.toString());
List<Column> columns = stmt.getMetaData().getColumns();
for (int i = 0; i < columns.size(); i++) {
Assert.assertEquals(columns.get(i).getName(), UserPropertyProcNode.ALL_USER_TITLE_NAMES.get(i));
}
}
@Test
public void testError() {
ShowUserPropertyStmt stmt = new ShowUserPropertyStmt("testUser", "%load_cluster%", true);
try {
stmt.analyze(analyzer);
Assert.fail();
} catch (UserException e) {
Assert.assertTrue(e.getMessage().contains("ALL"));
}
}
}