Skip to content

Commit

Permalink
add unit test and use old function
Browse files Browse the repository at this point in the history
  • Loading branch information
flaming-archer committed Apr 10, 2024
1 parent 892d9c4 commit 66926c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1341,16 +1341,8 @@ public GrantRevokePrivilegeResponse grant_revoke_privileges(GrantRevokePrivilege
public GrantRevokePrivilegeResponse refresh_privileges(HiveObjectRef hiveObjectRef, String authorizer,
GrantRevokePrivilegeRequest grantRevokePrivilegeRequest) throws MetaException, TException {
DatabaseMapping databaseMapping = checkWritePermissions(hiveObjectRef.getDbName());
PrivilegeBag privilegeBag = grantRevokePrivilegeRequest.getPrivileges();
if (privilegeBag != null && privilegeBag.getPrivileges() != null) {
for (HiveObjectPrivilege hiveObjectPrivilege : privilegeBag.getPrivileges()) {
if (hiveObjectPrivilege.getHiveObject() != null) {
databaseMapping.transformInboundHiveObjectRef(hiveObjectPrivilege.getHiveObject());
}
}
}
return databaseMapping.getClient().refresh_privileges(databaseMapping.transformInboundHiveObjectRef(hiveObjectRef),
authorizer, grantRevokePrivilegeRequest);
authorizer, databaseMapping.transformInboundGrantRevokePrivilegesRequest(grantRevokePrivilegeRequest));
}

private DatabaseMapping checkWritePermissionsForPrivileges(PrivilegeBag privileges) throws NoSuchObjectException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
import org.apache.hadoop.hive.metastore.api.HeartbeatTxnRangeResponse;
import org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege;
import org.apache.hadoop.hive.metastore.api.HiveObjectRef;
import org.apache.hadoop.hive.metastore.api.HiveObjectType;
import org.apache.hadoop.hive.metastore.api.ISchema;
import org.apache.hadoop.hive.metastore.api.ISchemaName;
import org.apache.hadoop.hive.metastore.api.LockComponent;
Expand Down Expand Up @@ -1990,9 +1991,21 @@ public void refresh_privileges() throws TException {
GrantRevokePrivilegeRequest grantRevokePrivilegeRequest = new GrantRevokePrivilegeRequest();
HiveObjectRef hiveObjectRef = new HiveObjectRef();
hiveObjectRef.setDbName(DB_P);
PrivilegeBag privileges = new PrivilegeBag();
List<HiveObjectPrivilege> privilegesList = new ArrayList<>();
HiveObjectPrivilege hiveObjectPrivilege = new HiveObjectPrivilege();
HiveObjectRef hor = new HiveObjectRef();
hor.setDbName(DB_P);
hor.setObjectType(HiveObjectType.DATABASE);
hor.setObjectName(DB_P);
hiveObjectPrivilege.setHiveObject(hor);
privilegesList.add(hiveObjectPrivilege);
privileges.setPrivileges(privilegesList);
grantRevokePrivilegeRequest.setPrivileges(privileges);
GrantRevokePrivilegeResponse grantRevokePrivilegeResponse = new GrantRevokePrivilegeResponse();

when(primaryMapping.transformInboundHiveObjectRef(hiveObjectRef)).thenReturn(hiveObjectRef);
when(primaryMapping.transformInboundGrantRevokePrivilegesRequest(grantRevokePrivilegeRequest)).thenReturn(grantRevokePrivilegeRequest);
when(primaryClient.refresh_privileges(hiveObjectRef, "dummy", grantRevokePrivilegeRequest)).thenReturn(grantRevokePrivilegeResponse);
GrantRevokePrivilegeResponse result = handler.refresh_privileges(hiveObjectRef, "dummy", grantRevokePrivilegeRequest);
assertThat(result, is(grantRevokePrivilegeResponse));
Expand Down

0 comments on commit 66926c4

Please sign in to comment.