World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#10269] fix(core): prevent fileset privilege removal on failed drop (#12582)
Saravanan Kandaswamy29093d2ecd3d
diff --git a/core/src/test/java/org/apache/gravitino/hook/TestFilesetHookDispatcher.java b/core/src/test/java/org/apache/gravitino/hook/TestFilesetHookDispatcher.javaindex ae662040b3..1a47a83025 100644--- a/core/src/test/java/org/apache/gravitino/hook/TestFilesetHookDispatcher.java+++ b/core/src/test/java/org/apache/gravitino/hook/TestFilesetHookDispatcher.java@@ -43,9 +43,11 @@ import static org.mockito.ArgumentMatchers.eq;import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableMap;import com.google.common.collect.Lists;+import java.util.List;import java.util.Map;import org.apache.commons.lang3.reflect.FieldUtils;import org.apache.gravitino.Config;+import org.apache.gravitino.Entity;import org.apache.gravitino.GravitinoEnv;import org.apache.gravitino.MetadataObject;import org.apache.gravitino.NameIdentifier;@@ -260,6 +262,32 @@ public class TestFilesetHookDispatcher extends TestOperationDispatcher {});}+ @Test+ public void testDropFilesetShouldNotRemovePrivilegesWhenDropReturnsFalse() {+ NameIdentifier ident = NameIdentifier.of("metalake", "catalog", "schema", "fileset");+ FilesetDispatcher delegate = Mockito.mock(FilesetDispatcher.class);+ FilesetHookDispatcher hookDispatcher = new FilesetHookDispatcher(delegate);+ List<String> locations = Lists.newArrayList("/tmp/fileset");++ Mockito.when(delegate.dropFileset(ident)).thenReturn(false);++ try (MockedStatic<AuthorizationUtils> mockedAuthz =+ Mockito.mockStatic(AuthorizationUtils.class)) {+ mockedAuthz+ .when(+ () -> AuthorizationUtils.getMetadataObjectLocation(ident, Entity.EntityType.FILESET))+ .thenReturn(locations);++ Assertions.assertFalse(hookDispatcher.dropFileset(ident));++ mockedAuthz.verify(+ () ->+ AuthorizationUtils.authorizationPluginRemovePrivileges(+ ident, Entity.EntityType.FILESET, locations),+ Mockito.never());+ }+ }+@Testpublic void testRenameAuthorizationPrivilege() {Namespace filesetNs = Namespace.of(metalake, catalog, "schema1121");diff --git a/core/src/test/java/org/apache/gravitino/hook/TestSchemaHookDispatcher.java b/core/src/test/java/org/apache/gravitino/hook/TestSchemaHookDispatcher.javaindex 478ab3efd5..8c5cfa41c1 100644--- a/core/src/test/java/org/apache/gravitino/hook/TestSchemaHookDispatcher.java+++ b/core/src/test/java/org/apache/gravitino/hook/TestSchemaHookDispatcher.java@@ -260,6 +260,23 @@ public class TestSchemaHookDispatcher {}}+ @Test+ public void testDropSchemaDoesNotRemovePrivilegesWhenSchemaDoesNotExist() {+ NameIdentifier ident = NameIdentifier.of("test_metalake", "test_catalog", "A:B:C");+ when(mockDispatcher.dropSchema(eq(ident), eq(false))).thenReturn(false);++ try (MockedStatic<AuthorizationUtils> authz = Mockito.mockStatic(AuthorizationUtils.class)) {+ boolean dropped = hookDispatcher.dropSchema(ident, false);++ Assertions.assertFalse(dropped);+ authz.verify(+ () ->+ AuthorizationUtils.authorizationPluginRemovePrivileges(+ ident, Entity.EntityType.SCHEMA, null),+ Mockito.never());+ }+ }+@SuppressWarnings("unchecked")private List<MetadataObject> captureOwnedObjects() {ArgumentCaptor<List<MetadataObject>> captor = ArgumentCaptor.forClass(List.class);diff --git a/core/src/test/java/org/apache/gravitino/hook/TestTopicHookDispatcher.java b/core/src/test/java/org/apache/gravitino/hook/TestTopicHookDispatcher.javaindex 96c851aff7..240e3ec71d 100644--- a/core/src/test/java/org/apache/gravitino/hook/TestTopicHookDispatcher.java+++ b/core/src/test/java/org/apache/gravitino/hook/TestTopicHookDispatcher.java@@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableMap;import java.util.Map;import org.apache.commons.lang3.reflect.FieldUtils;+import org.apache.gravitino.Entity;import org.apache.gravitino.GravitinoEnv;import org.apache.gravitino.MetadataObject;import org.apache.gravitino.NameIdentifier;@@ -78,6 +79,23 @@ public class TestTopicHookDispatcher extends TestOperationDispatcher {Mockito.when(catalog.getAuthorizationPlugin()).thenReturn(authorizationPlugin);}+ @Test+ public void testDropTopicDoesNotRemovePrivilegesWhenTopicDoesNotExist() {+ TopicDispatcher dispatcher = Mockito.mock(TopicDispatcher.class);+ TopicHookDispatcher hook = new TopicHookDispatcher(dispatcher);+ NameIdentifier ident = NameIdentifier.of("test_metalake", "test_catalog", "topic");+ Mockito.when(dispatcher.dropTopic(ident)).thenReturn(false);++ try (MockedStatic<AuthorizationUtils> authz = Mockito.mockStatic(AuthorizationUtils.class)) {+ Assertions.assertFalse(hook.dropTopic(ident));+ authz.verify(+ () ->+ AuthorizationUtils.authorizationPluginRemovePrivileges(+ ident, Entity.EntityType.TOPIC, null),+ Mockito.never());+ }+ }+@Testpublic void testCreateTopicSetsOwnerWithNormalizedIdentifier() throws Exception {// Self-contained: use a fresh hook with a directly-mocked TopicDispatcher and a case-