|
24 | 24 | import com.google.common.collect.ImmutableSet; |
25 | 25 | import com.google.common.collect.Maps; |
26 | 26 | import java.io.IOException; |
| 27 | +import java.lang.reflect.Method; |
27 | 28 | import java.util.ArrayList; |
28 | 29 | import java.util.Arrays; |
29 | 30 | import java.util.HashMap; |
|
39 | 40 | import org.apache.gravitino.authorization.SecurableObject; |
40 | 41 | import org.apache.gravitino.authorization.SecurableObjects; |
41 | 42 | import org.apache.gravitino.client.GravitinoMetalake; |
| 43 | +import org.apache.gravitino.client.RESTClient; |
| 44 | +import org.apache.gravitino.dto.responses.MetadataObjectPolicyListResponse; |
| 45 | +import org.apache.gravitino.dto.responses.PolicyNameListResponse; |
42 | 46 | import org.apache.gravitino.exceptions.ForbiddenException; |
43 | 47 | import org.apache.gravitino.integration.test.container.ContainerSuite; |
44 | 48 | import org.apache.gravitino.integration.test.container.HiveContainer; |
@@ -321,6 +325,38 @@ public void testListPolicyForTable() { |
321 | 325 | .supportsPolicies() |
322 | 326 | .listPolicies(); |
323 | 327 | Assertions.assertArrayEquals(new String[] {"policy2"}, policies); |
| 328 | + |
| 329 | + RESTClient restClient = getNormalUserRestClient(); |
| 330 | + String path = |
| 331 | + "api/metalakes/" |
| 332 | + + METALAKE |
| 333 | + + "/objects/table/" |
| 334 | + + CATALOG |
| 335 | + + "." |
| 336 | + + SCHEMA |
| 337 | + + ".table1/policies"; |
| 338 | + PolicyNameListResponse nameListResponse = |
| 339 | + restClient.get( |
| 340 | + path, |
| 341 | + PolicyNameListResponse.class, |
| 342 | + Map.of(), |
| 343 | + error -> { |
| 344 | + throw new AssertionError(error); |
| 345 | + }); |
| 346 | + Assertions.assertEquals(0, nameListResponse.getNames().length); |
| 347 | + Assertions.assertTrue(nameListResponse.hasInaccessiblePolicies()); |
| 348 | + |
| 349 | + MetadataObjectPolicyListResponse listResponse = |
| 350 | + restClient.get( |
| 351 | + path, |
| 352 | + Map.of("details", "true"), |
| 353 | + MetadataObjectPolicyListResponse.class, |
| 354 | + Map.of(), |
| 355 | + error -> { |
| 356 | + throw new AssertionError(error); |
| 357 | + }); |
| 358 | + Assertions.assertEquals(0, listResponse.getPolicies().length); |
| 359 | + Assertions.assertTrue(listResponse.hasInaccessiblePolicies()); |
324 | 360 | } |
325 | 361 |
|
326 | 362 | @Test |
@@ -433,4 +469,15 @@ public void testDropPolicy() { |
433 | 469 | gravitinoMetalake.deletePolicy("policy1"); |
434 | 470 | metalakeLoadByNormalUser.deletePolicy("policy2"); |
435 | 471 | } |
| 472 | + |
| 473 | + private RESTClient getNormalUserRestClient() { |
| 474 | + try { |
| 475 | + Method restClientMethod = |
| 476 | + normalUserClient.getClass().getSuperclass().getDeclaredMethod("restClient"); |
| 477 | + restClientMethod.setAccessible(true); |
| 478 | + return (RESTClient) restClientMethod.invoke(normalUserClient); |
| 479 | + } catch (ReflectiveOperationException e) { |
| 480 | + throw new RuntimeException("Failed to access the normal user's REST client", e); |
| 481 | + } |
| 482 | + } |
436 | 483 | } |
0 commit comments