roryqi commented on code in PR #13478:
URL: https://github.com/apache/gravitino/pull/13478#discussion_r4255369679
##########
core/src/main/java/org/apache/gravitino/policy/PolicyManager.java:
##########
@@ -341,6 +343,7 @@ private PolicyEntity updatePolicyEntity(PolicyEntity
policyEntity, PolicyChange.
}
newContent.validate();
+ validateReadRestrictionContent(policyEntity.policyType(), newContent);
Review Comment:
Fixed in d3952e83ec. `validateReadRestrictionContent` is back inside the
`UpdateContent` arm, while the generic `newContent.validate()` from upstream
remains outside the loop. Rename-only and comment-only alters therefore do not
reparse stored restricted Rego. I added a regression test that writes a legacy
row-filter expression directly to the entity store and verifies that both
rename and comment update succeed without changing its content.
##########
core/src/test/java/org/apache/gravitino/policy/rego/TestRestrictedRegoLexer.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.rego;
+
+import java.util.List;
+import org.apache.gravitino.policy.rego.RestrictedRegoLexer.Token;
+import org.apache.gravitino.policy.rego.RestrictedRegoLexer.TokenType;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link RestrictedRegoLexer}. */
+public class TestRestrictedRegoLexer {
+
+ @Test
+ void testTokenizesSourceWithOneBasedLocations() {
+ RestrictedRegoLexer lexer = new RestrictedRegoLexer("filter :=\n
col(\"x\") >= -1");
+
+ assertToken(lexer.nextToken(), TokenType.FILTER, "filter", 1, 1);
+ assertToken(lexer.nextToken(), TokenType.ASSIGN, ":=", 1, 8);
+ assertToken(lexer.nextToken(), TokenType.COL, "col", 2, 2);
+ assertToken(lexer.nextToken(), TokenType.LPAREN, "(", 2, 5);
+ assertToken(lexer.nextToken(), TokenType.STRING, "\"x\"", 2, 6);
+ assertToken(lexer.nextToken(), TokenType.RPAREN, ")", 2, 9);
+ assertToken(lexer.nextToken(), TokenType.GTE, ">=", 2, 11);
+ assertToken(lexer.nextToken(), TokenType.NUMBER, "-1", 2, 14);
+ assertToken(lexer.nextToken(), TokenType.EOF, "", 2, 16);
+ }
+
+ @Test
+ void testRejectsInvalidUnicodeEscapeDigits() {
+ List<String> invalidEscapes =
+ List.of(
+ RestrictedRegoTestUtils.unicodeEscape(0x0660, 0x0660, 0x0664,
0x0661),
+ RestrictedRegoTestUtils.unicodeEscape(0xFF10, 0xFF10, 0xFF14,
0xFF11),
+ RestrictedRegoTestUtils.unicodeEscape(0x0966, 0x0966, 0x096A,
0x0967),
+ RestrictedRegoTestUtils.unicodeEscape('0', '0', 0x0664, 0x0661));
+
+ for (String invalidEscape : invalidEscapes) {
+ IllegalArgumentException error =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> new RestrictedRegoLexer("\"" + invalidEscape +
"\"").nextToken());
Review Comment:
Fixed in d3952e83ec. The four non-ASCII Unicode-escape cases are now shared
by the lexer test and a facade-level test that calls `validateRowFilter`, so
both the lexical guard and the end-to-end rejection remain pinned.
--
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]