HonahX commented on code in PR #1529:
URL: https://github.com/apache/polaris/pull/1529#discussion_r2096165510


##########
integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisPolicyServiceIntegrationTest.java:
##########
@@ -427,6 +442,176 @@ NS2_T1, new Schema(Types.NestedField.optional(1, 
"string", Types.StringType.get(
     restCatalog.dropTable(NS2_T1);
   }
 
+  @Test
+  public void testGrantsOnPolicy() {
+    restCatalog.createNamespace(NS1);
+    try {
+      policyApi.createPolicy(
+          currentCatalogName,
+          NS1_P1,
+          PredefinedPolicyTypes.DATA_COMPACTION,
+          EXAMPLE_TABLE_MAINTENANCE_POLICY_CONTENT,
+          "test policy");
+      managementApi.createCatalogRole(currentCatalogName, CATALOG_ROLE_2);
+      Stream<PolicyGrant> policyGrants =
+          Arrays.stream(PolicyPrivilege.values())
+              .map(
+                  p ->
+                      new PolicyGrant(
+                          Arrays.asList(NS1.levels()),
+                          NS1_P1.getName(),
+                          p,
+                          GrantResource.TypeEnum.POLICY));
+      policyGrants.forEach(g -> managementApi.addGrant(currentCatalogName, 
CATALOG_ROLE_2, g));
+
+      Assertions.assertThat(managementApi.listGrants(currentCatalogName, 
CATALOG_ROLE_2))
+          .extracting(GrantResources::getGrants)
+          .asInstanceOf(InstanceOfAssertFactories.list(GrantResource.class))
+          .map(gr -> ((PolicyGrant) gr).getPrivilege())
+          .containsExactlyInAnyOrder(PolicyPrivilege.values());
+
+      PolicyGrant policyReadGrant =
+          new PolicyGrant(
+              Arrays.asList(NS1.levels()),
+              NS1_P1.getName(),
+              PolicyPrivilege.POLICY_READ,
+              GrantResource.TypeEnum.POLICY);
+      managementApi.revokeGrant(currentCatalogName, CATALOG_ROLE_2, 
policyReadGrant);
+
+      Assertions.assertThat(managementApi.listGrants(currentCatalogName, 
CATALOG_ROLE_2))
+          .extracting(GrantResources::getGrants)
+          .asInstanceOf(InstanceOfAssertFactories.list(GrantResource.class))
+          .map(gr -> ((PolicyGrant) gr).getPrivilege())
+          .doesNotContain(PolicyPrivilege.POLICY_READ);
+    } finally {
+      policyApi.purge(currentCatalogName, NS1);
+    }
+  }
+
+  @Test
+  public void testGrantsOnNonExistingPolicy() {
+    restCatalog.createNamespace(NS1);
+
+    try {
+      managementApi.createCatalogRole(currentCatalogName, CATALOG_ROLE_2);
+      Stream<PolicyGrant> policyGrants =
+          Arrays.stream(PolicyPrivilege.values())
+              .map(
+                  p ->
+                      new PolicyGrant(
+                          Arrays.asList(NS1.levels()),
+                          NS1_P1.getName(),
+                          p,
+                          GrantResource.TypeEnum.POLICY));
+      policyGrants.forEach(
+          g -> {
+            try (Response response =
+                managementApi
+                    .request(
+                        "v1/catalogs/{cat}/catalog-roles/{role}/grants",
+                        Map.of("cat", currentCatalogName, "role", 
"catalogrole2"))
+                    .put(Entity.json(g))) {
+
+              
assertThat(response.getStatus()).isEqualTo(NOT_FOUND.getStatusCode());
+            }
+          });
+    } finally {
+      policyApi.purge(currentCatalogName, NS1);
+    }
+  }
+
+  @Test
+  public void testGrantsOnNamespace() {
+    restCatalog.createNamespace(NS1);

Review Comment:
   Good suggestion! I think it may be a good test to add in 
`PolicyCatalogHandlerAuthzTest` where it test the actual 
authorization/inheritance resolution. This test is used to ensure the correct 
PolarisPrivilege is granted, the `listGrants` itself does not resolve the 
inheritance. I will add related ones later.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to