|
21 | 21 | import static org.apache.polaris.service.it.env.PolarisClient.polarisClient; |
22 | 22 |
|
23 | 23 | import com.google.common.collect.ImmutableMap; |
| 24 | +import jakarta.ws.rs.client.Entity; |
| 25 | +import jakarta.ws.rs.core.Response; |
24 | 26 | import java.lang.annotation.Retention; |
25 | 27 | import java.lang.annotation.RetentionPolicy; |
26 | 28 | import java.lang.reflect.Method; |
|
35 | 37 | import org.apache.iceberg.catalog.Namespace; |
36 | 38 | import org.apache.iceberg.catalog.TableIdentifier; |
37 | 39 | import org.apache.iceberg.rest.RESTCatalog; |
| 40 | +import org.apache.iceberg.rest.RESTUtil; |
38 | 41 | import org.apache.iceberg.types.Types; |
39 | 42 | import org.apache.polaris.core.admin.model.AwsStorageConfigInfo; |
40 | 43 | import org.apache.polaris.core.admin.model.Catalog; |
|
60 | 63 | import org.apache.polaris.service.it.env.PolicyApi; |
61 | 64 | import org.apache.polaris.service.it.ext.PolarisIntegrationTestExtension; |
62 | 65 | import org.apache.polaris.service.types.ApplicablePolicy; |
| 66 | +import org.apache.polaris.service.types.CreatePolicyRequest; |
63 | 67 | import org.apache.polaris.service.types.Policy; |
64 | 68 | import org.apache.polaris.service.types.PolicyAttachmentTarget; |
65 | 69 | import org.apache.polaris.service.types.PolicyIdentifier; |
|
72 | 76 | import org.junit.jupiter.api.TestInfo; |
73 | 77 | import org.junit.jupiter.api.extension.ExtendWith; |
74 | 78 | import org.junit.jupiter.api.io.TempDir; |
| 79 | +import org.junit.jupiter.params.ParameterizedTest; |
| 80 | +import org.junit.jupiter.params.provider.ValueSource; |
75 | 81 |
|
76 | 82 | @ExtendWith(PolarisIntegrationTestExtension.class) |
77 | 83 | public class PolarisPolicyServiceIntegrationTest { |
@@ -260,6 +266,60 @@ public void testCreatePolicy() { |
260 | 266 | policyApi.dropPolicy(currentCatalogName, NS1_P1); |
261 | 267 | } |
262 | 268 |
|
| 269 | + @ParameterizedTest |
| 270 | + @ValueSource( |
| 271 | + strings = { |
| 272 | + " invalid", |
| 273 | + "invalid ", |
| 274 | + " invalid ", |
| 275 | + "", |
| 276 | + "policy name", |
| 277 | + "policy@name", |
| 278 | + "policy#name", |
| 279 | + "policy$name", |
| 280 | + "policy!name", |
| 281 | + "policy name with space", |
| 282 | + "policy.name", |
| 283 | + "policy,name", |
| 284 | + "policy~name", |
| 285 | + "policy`name", |
| 286 | + "policy;name", |
| 287 | + "policy:name", |
| 288 | + "policy<>name", |
| 289 | + "policy[]name", |
| 290 | + "policy{}name", |
| 291 | + "policy|name", |
| 292 | + "policy\\name", |
| 293 | + "policy/name", |
| 294 | + "policy*name", |
| 295 | + "policy^name", |
| 296 | + "policy%name", |
| 297 | + }) |
| 298 | + public void testCreatePolicyWithInvalidName(String policyName) { |
| 299 | + restCatalog.createNamespace(NS1); |
| 300 | + PolicyIdentifier policyIdentifier = new PolicyIdentifier(NS1, policyName); |
| 301 | + |
| 302 | + String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace()); |
| 303 | + CreatePolicyRequest request = |
| 304 | + CreatePolicyRequest.builder() |
| 305 | + .setType(PredefinedPolicyTypes.DATA_COMPACTION.getName()) |
| 306 | + .setName(policyIdentifier.getName()) |
| 307 | + .setDescription("test policy") |
| 308 | + .setContent(EXAMPLE_TABLE_MAINTENANCE_POLICY_CONTENT) |
| 309 | + .build(); |
| 310 | + try (Response res = |
| 311 | + policyApi |
| 312 | + .request( |
| 313 | + "polaris/v1/{cat}/namespaces/{ns}/policies", |
| 314 | + Map.of("cat", currentCatalogName, "ns", ns)) |
| 315 | + .post(Entity.json(request))) { |
| 316 | + Assertions.assertThat(res.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode()); |
| 317 | + Assertions.assertThat(res.readEntity(String.class)) |
| 318 | + .contains( |
| 319 | + "{\"error\":{\"message\":\"Invalid value: createPolicy.arg2.name: must match \\\"^[A-Za-z0-9\\\\-_]+$\\\"\",\"type\":\"ResteasyReactiveViolationException\",\"code\":400}}"); |
| 320 | + } |
| 321 | + } |
| 322 | + |
263 | 323 | @Test |
264 | 324 | public void testDropPolicy() { |
265 | 325 | restCatalog.createNamespace(NS1); |
|
0 commit comments