[Pick]Fix show role stmt missing grouo info (#37920)
## Proposed changes pick #36032
This commit is contained in:
@ -41,6 +41,7 @@ public class ShowRolesStmt extends ShowStmt {
|
||||
builder.addColumn(new Column("DatabasePrivs", ScalarType.createVarchar(300)));
|
||||
builder.addColumn(new Column("TablePrivs", ScalarType.createVarchar(300)));
|
||||
builder.addColumn(new Column("ResourcePrivs", ScalarType.createVarchar(300)));
|
||||
builder.addColumn(new Column("WorkloadGroupPrivs", ScalarType.createVarchar(300)));
|
||||
|
||||
META_DATA = builder.build();
|
||||
}
|
||||
|
||||
@ -174,7 +174,8 @@ public class RoleManager implements Writable, GsonPostProcessable {
|
||||
}
|
||||
}, (s1, s2) -> s1 + " " + s2
|
||||
));
|
||||
Stream.of(PrivLevel.GLOBAL, PrivLevel.CATALOG, PrivLevel.DATABASE, PrivLevel.TABLE, PrivLevel.RESOURCE)
|
||||
Stream.of(PrivLevel.GLOBAL, PrivLevel.CATALOG, PrivLevel.DATABASE, PrivLevel.TABLE, PrivLevel.RESOURCE,
|
||||
PrivLevel.WORKLOAD_GROUP)
|
||||
.forEach(level -> {
|
||||
String infoItem = infoMap.get(level);
|
||||
if (Strings.isNullOrEmpty(infoItem)) {
|
||||
|
||||
@ -54,6 +54,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -2439,4 +2440,45 @@ public class AuthTest {
|
||||
Assert.assertTrue(
|
||||
auth.checkPlainPasswordForTest("root", "192.168.0.1", "validRootPassword", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowRoles() {
|
||||
String role = "test_wg_role";
|
||||
CreateRoleStmt roleStmt = new CreateRoleStmt(role);
|
||||
try {
|
||||
roleStmt.analyze(analyzer);
|
||||
auth.createRole(roleStmt);
|
||||
} catch (UserException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
AccessPrivilege accessPrivilege = AccessPrivilege.fromName("USAGE_PRIV");
|
||||
AccessPrivilegeWithCols apwc = new AccessPrivilegeWithCols(accessPrivilege);
|
||||
List<AccessPrivilegeWithCols> list = new ArrayList<>();
|
||||
list.add(apwc);
|
||||
WorkloadGroupPattern wgp = new WorkloadGroupPattern("test_wg");
|
||||
GrantStmt grantStmt = new GrantStmt(null, role, wgp, list);
|
||||
try {
|
||||
grantStmt.analyze(analyzer);
|
||||
auth.grant(grantStmt);
|
||||
} catch (UserException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
List<List<String>> showInfo = auth.getRoleInfo();
|
||||
boolean findWgPriv = false;
|
||||
for (int i = 0; i < showInfo.size(); i++) {
|
||||
List<String> row = showInfo.get(i);
|
||||
String name = row.get(0);
|
||||
if (role.equals(name)) {
|
||||
findWgPriv = true;
|
||||
String wgPriv = row.get(row.size() - 1);
|
||||
Assert.assertTrue("test_wg: Usage_priv".equals(wgPriv));
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(findWgPriv);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user