Skip to content

Commit

Permalink
Fix the db prefix not being removed from request parameters in method…
Browse files Browse the repository at this point in the history
… refresh_privileges (#312)

* fix refresh_privileges

* add unit test and use old function
  • Loading branch information
flaming-archer authored Apr 11, 2024
1 parent 1b9a36e commit 61dd787
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ public GrantRevokePrivilegeResponse refresh_privileges(HiveObjectRef hiveObjectR
GrantRevokePrivilegeRequest grantRevokePrivilegeRequest) throws MetaException, TException {
DatabaseMapping databaseMapping = checkWritePermissions(hiveObjectRef.getDbName());
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 61dd787

Please sign in to comment.