Copilot commented on code in PR #4629:
URL: https://github.com/apache/polaris/pull/4629#discussion_r3367169210


##########
spec/polaris-management-service.yml:
##########
@@ -84,7 +84,7 @@ paths:
           type: string
           minLength: 1
           maxLength: 256
-          pattern: '^(?!\s*[s|S][y|Y][s|S][t|T][e|E][m|M]\$).*$'
+          pattern: '^(?!\s*[sS][yY][sS][tT][eE][mM]$).*$'

Review Comment:
   The negative-lookahead only rejects strings that end exactly at `system` 
(after optional leading whitespace). Inputs like `system ` (trailing 
whitespace) or ` system ` will still pass. If the intent is to reserve the name 
regardless of surrounding whitespace, update the lookahead to allow trailing 
whitespace before the end-anchor (e.g., add `\s*` before `$`). Apply 
consistently to all repeated occurrences of this pattern in the spec.



##########
api/management-model/src/test/java/org/apache/polaris/core/admin/model/PrincipalRoleValidationTest.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.polaris.core.admin.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import jakarta.validation.ConstraintViolation;
+import jakarta.validation.Validation;
+import jakarta.validation.Validator;
+import jakarta.validation.ValidatorFactory;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Pattern;
+import jakarta.validation.constraints.Size;
+import java.util.Set;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class PrincipalRoleValidationTest {
+
+  private static ValidatorFactory factory;
+  private static Validator validator;
+
+  @BeforeAll
+  public static void setUp() {
+    factory = Validation.buildDefaultValidatorFactory();
+    validator = factory.getValidator();
+  }
+
+  @AfterAll
+  public static void tearDown() {
+    if (factory != null) {
+      factory.close();
+    }
+  }
+
+  private static boolean hasViolationOf(
+      Set<ConstraintViolation<PrincipalRole>> violations, Class<?> 
annotationType) {
+    return violations.stream()
+        .anyMatch(v -> 
v.getConstraintDescriptor().getAnnotation().annotationType() == annotationType);
+  }
+
+  @Test
+  public void nullNameFailsNotNull() {
+    PrincipalRole role = new PrincipalRole(null);
+    Set<ConstraintViolation<PrincipalRole>> violations = 
validator.validate(role);
+    assertThat(hasViolationOf(violations, NotNull.class)).isTrue();
+  }
+
+  @Test
+  public void emptyNameFailsSize() {
+    PrincipalRole role = new PrincipalRole("");
+    Set<ConstraintViolation<PrincipalRole>> violations = 
validator.validate(role);
+    assertThat(hasViolationOf(violations, Size.class)).isTrue();
+  }
+
+  @Test
+  public void validNamePasses() {
+    PrincipalRole role = new PrincipalRole("data-engineering");
+    Set<ConstraintViolation<PrincipalRole>> violations = 
validator.validate(role);
+    assertThat(violations).isEmpty();
+  }
+
+  @Test
+  public void reservedSystemNameFailsPattern() {
+    PrincipalRole role = new PrincipalRole("system");
+    Set<ConstraintViolation<PrincipalRole>> violations = 
validator.validate(role);
+    assertThat(hasViolationOf(violations, Pattern.class)).isTrue();
+  }

Review Comment:
   The reserved-name test only covers the exact lowercase string `system`. 
Since the regex is intended to be case-insensitive and allows leading 
whitespace, add assertions for key variants (e.g., `System`, `SYSTEM`, ` 
system`) and (if intended to be blocked) trailing-whitespace cases like `system 
` / ` system ` to ensure the spec + model constraints match the desired 
behavior.



##########
spec/polaris-management-service.yml:
##########
@@ -854,7 +854,7 @@ components:
           type: string
           minLength: 1
           maxLength: 256
-          pattern: '^(?!\s*[s|S][y|Y][s|S][t|T][e|E][m|M]\$).*$'
+          pattern: '^(?!\s*[sS][yY][sS][tT][eE][mM]$).*$'

Review Comment:
   The same reserved-name regex is duplicated across many parameters/schemas in 
this spec. Consider extracting a reusable schema (e.g., a shared `name` schema 
under `components/schemas` or `components/parameters`) and referencing it via 
`$ref` to avoid future inconsistencies when the validation rules change.



##########
api/management-model/build.gradle.kts:
##########
@@ -36,6 +36,10 @@ dependencies {
   testImplementation("org.junit.jupiter:junit-jupiter")
   testImplementation(platform(libs.jackson.bom))
   testImplementation("com.fasterxml.jackson.core:jackson-databind")
+  testImplementation(libs.jakarta.validation.api)
+  testImplementation("org.hibernate.validator:hibernate-validator:8.0.1.Final")
+  testImplementation("org.glassfish.expressly:expressly:5.0.0")
+  testImplementation(libs.assertj.core)

Review Comment:
   These new test dependencies hardcode versions for Hibernate Validator and 
Expressly while other deps appear to use the version catalog (`libs.*`). To 
keep dependency management consistent and reduce drift/conflicts, prefer moving 
these coordinates into the version catalog (or applying existing BOM/alignment 
if the project uses one) and referencing them via `libs` entries.



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