yuqi1129 commented on code in PR #13693:
URL: https://github.com/apache/gravitino/pull/13693#discussion_r4218513584
##########
common/src/main/java/org/apache/gravitino/dto/requests/PolicyCreateRequest.java:
##########
@@ -64,7 +64,13 @@ public class PolicyCreateRequest implements RESTRequest {
name = "system_iceberg_compaction"),
@JsonSubTypes.Type(
value = PolicyContentDTO.IcebergOrphanFileRemovalContentDTO.class,
- name = "system_iceberg_orphan_file_removal")
+ name = "system_iceberg_orphan_file_removal"),
+ @JsonSubTypes.Type(
Review Comment:
[Important] Please add these two types to the public OpenAPI contract as
well. `docs/open-api/policies.yaml` still only lists custom and the two
maintenance types in the `Policy`, `PolicyCreateRequest`, and
`UpdatePolicyContentRequest` oneOf/discriminator definitions. Consequently, the
server accepts the new expression payloads while schema-based validators reject
them and generated clients lack the corresponding models/mappings.
I validated create, update, and policy-response payloads for both new types
against the existing schemas: all six were rejected; equivalent custom-policy
controls passed. Please add the typed content and response/create/update
schemas, update the discriminator mappings and custom-type exclusions, document
the nonblank/16 KiB UTF-8 limit, and run `./gradlew :docs:build`. This
observation is about the published schema; I did not run a generated SDK or
HTTP gateway.
##########
api/src/test/java/org/apache/gravitino/policy/TestReadRestrictionContent.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.policy;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Map;
+import org.apache.gravitino.MetadataObject;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestReadRestrictionContent {
+
+ @Test
+ void testCreatesReadRestrictionContent() {
+ String rowFilterExpression =
+ "filter := col(\"region\") == \"US\" if is_group_member(\"analysts\")
else := false";
+ String columnMaskExpression =
+ "mask := action(\"show-last-4\") if is_group_member(\"analysts\") "
+ + "else := action(\"replace-with-null\")";
+
+ RowFilterContent rowFilter = PolicyContents.rowFilter(rowFilterExpression);
+ ColumnMaskContent columnMask =
PolicyContents.columnMask(columnMaskExpression);
+
+ Assertions.assertEquals(rowFilterExpression, rowFilter.expression());
+ Assertions.assertEquals(columnMaskExpression, columnMask.expression());
+ Assertions.assertEquals(Map.of("expression", rowFilterExpression),
rowFilter.rules());
+ Assertions.assertEquals(Map.of("expression", columnMaskExpression),
columnMask.rules());
+ Assertions.assertEquals(
+ ImmutableSet.of(MetadataObject.Type.TAG),
rowFilter.supportedObjectTypes());
+ Assertions.assertEquals(
+ ImmutableSet.of(MetadataObject.Type.TAG),
columnMask.supportedObjectTypes());
+ Assertions.assertTrue(rowFilter.properties().isEmpty());
+ Assertions.assertTrue(columnMask.properties().isEmpty());
+ Assertions.assertDoesNotThrow(rowFilter::validate);
+ Assertions.assertDoesNotThrow(columnMask::validate);
+ }
+
+ @Test
+ void testEqualityUsesPolicyTypeAndExpression() {
+ String expression = "filter := col(\"region\") == \"US\"";
+
+ Assertions.assertEquals(
+ PolicyContents.rowFilter(expression),
PolicyContents.rowFilter(expression));
+ Assertions.assertNotEquals(
+ PolicyContents.rowFilter(expression), PolicyContents.rowFilter("filter
:= true"));
+ Assertions.assertNotEquals(
+ PolicyContents.rowFilter(expression),
PolicyContents.columnMask(expression));
+ }
+
+ @Test
+ void testRejectsMissingOrBlankExpressions() {
+ Assertions.assertThrows(IllegalArgumentException.class, () ->
PolicyContents.rowFilter(null));
+ Assertions.assertThrows(IllegalArgumentException.class, () ->
PolicyContents.columnMask(null));
+ Assertions.assertThrows(IllegalArgumentException.class, () ->
PolicyContents.rowFilter(" \t"));
+ Assertions.assertThrows(IllegalArgumentException.class, () ->
PolicyContents.columnMask("\n"));
+ }
+
+ @Test
+ void testValidatesUtf8ExpressionLength() {
+ String maximumLength =
"é".repeat(ReadRestrictionContent.MAX_SOURCE_LENGTH_BYTES / 2);
Review Comment:
[Nit] Could we also pin the promised 16 KiB limit independently of the
production constant? Both boundary inputs currently follow
`MAX_SOURCE_LENGTH_BYTES`, so accidentally changing the constant changes the
expected boundary too. I mutated the constant from 16 KiB to 32 KiB and all
four tests in this class still passed.
An `assertEquals(16 * 1024, ReadRestrictionContent.MAX_SOURCE_LENGTH_BYTES)`
or fixed 16 KiB acceptance/rejection inputs would protect the contract. Please
retain the multibyte character case: with the constant unchanged, relaxing the
validation guard correctly makes this test fail. The production limit is
correct today, so this is non-blocking.
--
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]