visit2rahul commented on code in PR #4422:
URL: https://github.com/apache/polaris/pull/4422#discussion_r3253305507


##########
regtests/t_cli/src/test_cli.py:
##########
@@ -437,6 +442,62 @@ def test_update_catalog():
         sys.path.pop(0)
     pass
 
+def test_update_catalog_base_location_validation():
+    """
+    Updating only the default-base-location to a value outside the catalog's 
allowed
+    locations must be rejected, to prevent the catalog from being left in a 
state

Review Comment:
   Agreed — removed in `a3167bcba`. Kept the existing-test fix (passing 
`--allowed-location` alongside `--default-base-location`) since you flagged 
that as good; the server-side rejection path is already covered by 
`BaseLocationValidationTest`.



##########
runtime/service/src/test/java/org/apache/polaris/service/admin/BaseLocationValidationTest.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.service.admin;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import org.apache.iceberg.exceptions.BadRequestException;
+import org.apache.polaris.core.entity.CatalogEntity;
+import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link 
PolarisAdminService#validateBaseLocationAgainstStorageConfig}, the validation
+ * invoked by {@code updateCatalog} to reject catalog updates whose new 
default-base-location is not
+ * within any allowed location in the existing storage configuration.
+ */
+public class BaseLocationValidationTest {
+
+  private static final String CATALOG = "myCatalog";
+
+  private static CatalogEntity catalogWithAllowedLocations(List<String> 
allowedLocations) {
+    PolarisStorageConfigurationInfo storageConfig = 
mock(PolarisStorageConfigurationInfo.class);
+    when(storageConfig.getAllowedLocations()).thenReturn(allowedLocations);
+    CatalogEntity catalogEntity = mock(CatalogEntity.class);
+    
when(catalogEntity.getStorageConfigurationInfo()).thenReturn(storageConfig);
+    return catalogEntity;
+  }
+
+  @Test
+  public void testChildLocationIsAccepted() {
+    CatalogEntity catalog = 
catalogWithAllowedLocations(List.of("s3://bucket/"));
+    assertThatCode(
+            () ->
+                PolarisAdminService.validateBaseLocationAgainstStorageConfig(
+                    catalog, "s3://bucket/path/to/data", CATALOG))
+        .doesNotThrowAnyException();
+  }
+
+  @Test
+  public void testExactMatchIsAccepted() {
+    CatalogEntity catalog = 
catalogWithAllowedLocations(List.of("s3://bucket/"));
+    assertThatCode(
+            () ->
+                PolarisAdminService.validateBaseLocationAgainstStorageConfig(
+                    catalog, "s3://bucket/", CATALOG))

Review Comment:
   Combined into `testLocationWithinAllowedIsAccepted` using 
`@ParameterizedTest` + `@CsvSource` in `a3167bcba`. Two rows cover the 
child-path and exact-match cases.



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