dengzhhu653 commented on code in PR #5766: URL: https://github.com/apache/hive/pull/5766#discussion_r2167944893
########## ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java: ########## @@ -696,6 +700,107 @@ public void testU_DropDataConnector_authorizedUser() { } } + + /** + * Captures and returns the privilege objects for Alter Partition + */ + private Pair<List<HivePrivilegeObject>, List<HivePrivilegeObject>> getHivePrivilegeObjectsForAlterPartition() + throws HiveAuthzPluginException, HiveAccessControlException { + @SuppressWarnings("unchecked") + Class<List<HivePrivilegeObject>> class_listPrivObjects = (Class) List.class; + ArgumentCaptor<List<HivePrivilegeObject>> inputsCapturer = ArgumentCaptor + .forClass(class_listPrivObjects); + ArgumentCaptor<List<HivePrivilegeObject>> outputsCapturer = ArgumentCaptor + .forClass(class_listPrivObjects); + + verify(mockHiveAuthorizer).checkPrivileges(eq(HiveOperationType.ALTERPARTITION_FILEFORMAT), + inputsCapturer.capture(), outputsCapturer.capture(), + any(HiveAuthzContext.class)); + + return new ImmutablePair<>(inputsCapturer.getValue(), outputsCapturer.getValue()); + } + @Test + public void testV_AlterPartition_DFSUriPrivObject() { + UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser(authorizedUser)); + try { + List<List<String>> testValues = createTable4PartColsParts(); + List<Partition> oldParts = hmsHandler.get_partitions(dbName, tblName, (short) -1); + Partition oldPart = oldParts.get(3); + Partition newPart = makeTestChangesOnPartition(oldPart); + + hmsHandler.rename_partition(dbName, tblName,oldPart.getValues(),newPart); + + Pair<List<HivePrivilegeObject>, List<HivePrivilegeObject>> io = getHivePrivilegeObjectsForAlterPartition(); + List<HivePrivilegeObject> outputs = io.getRight(); + + List<HivePrivilegeObject> tableOutputs = outputs.stream() + .filter(o -> o.getType() == HivePrivilegeObject.HivePrivilegeObjectType.DFS_URI) + .collect(Collectors.toList()); + + assertEquals("Should have one DFS_URI privilege object", 1, tableOutputs.size()); + HivePrivilegeObject DFSUriObj = tableOutputs.get(0); + + assertEquals("Output object should be a table", + HivePrivilegeObject.HivePrivilegeObjectType.DFS_URI, + DFSUriObj.getType()); Review Comment: this should always be a `DFS_URI` obj, can we validate the real location instead? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org