Copilot commented on code in PR #13843:
URL: https://github.com/apache/gravitino/pull/13843#discussion_r4267970632


##########
server/src/test/java/org/apache/gravitino/server/web/rest/authorization/TestMetadataObjectTagAuthorizationExpression.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.server.web.rest.authorization;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.google.common.collect.ImmutableSet;
+import java.lang.reflect.Method;
+import 
org.apache.gravitino.server.authorization.annotations.AuthorizationExpression;
+import 
org.apache.gravitino.server.authorization.expression.AuthorizationExpressionConverter;
+import org.apache.gravitino.server.web.rest.MetadataObjectTagOperations;
+import org.apache.gravitino.server.web.rest.TagOperations;
+import org.junit.jupiter.api.Test;
+
+/** Tests that metadata access cannot bypass tag read authorization. */
+public class TestMetadataObjectTagAuthorizationExpression {
+
+  /** Verify tag reads require both metadata access and tag permission on both 
REST routes. */
+  @Test
+  public void testGetTagRequiresTagPermission() throws Exception {
+    for (Class<?> resource :
+        new Class<?>[] {MetadataObjectTagOperations.class, 
TagOperations.class}) {
+      Method method =
+          resource.getMethod(
+              "getTagForObject", String.class, String.class, String.class, 
String.class);
+      String expression = 
method.getAnnotation(AuthorizationExpression.class).expression();
+      for (String type : new String[] {"TABLE", "VIEW"}) {
+        MockAuthorizationExpressionEvaluator evaluator =
+            new MockAuthorizationExpressionEvaluator(
+                
AuthorizationExpressionConverter.replaceCanAccessMetadataPrivilege(expression)
+                    .replace("entityType", "'" + type + "'"));

Review Comment:
   This test mutates the authorization expression by doing a plain string 
`.replace(\"entityType\", ...)`, which can unintentionally replace occurrences 
beyond the intended variable token (e.g., inside other identifiers or string 
literals), making the test brittle to unrelated expression changes. Prefer a 
token-safe replacement (e.g., word-boundary regex) or (if supported by 
`MockAuthorizationExpressionEvaluator`) passing `entityType` as an evaluated 
variable/context value rather than rewriting the expression text.



-- 
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