This is an automated email from the ASF dual-hosted git repository. kturner pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new f75a62701a adds test for illegal resource group ids (#5764) f75a62701a is described below commit f75a62701a30f1fff8d87037272a19efe39914fb Author: Keith Turner <ktur...@apache.org> AuthorDate: Mon Jul 28 12:10:52 2025 -0400 adds test for illegal resource group ids (#5764) Co-authored-by: Daniel Roberts <ddani...@gmail.com> --- .../core/conf/cluster/ClusterConfigParser.java | 5 ++- .../core/conf/cluster/ClusterConfigParserTest.java | 3 +- .../accumulo/core/data/ResourceGroupIdTest.java | 41 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParser.java b/core/src/main/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParser.java index b876c12b1c..db57b0f80b 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParser.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParser.java @@ -44,12 +44,11 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; public class ClusterConfigParser { - private static final Pattern GROUP_NAME_PATTERN = - Pattern.compile("^[a-zA-Z_]{1,}[a-zA-Z0-9_]{0,}$"); + private static final Pattern GROUP_NAME_PATTERN = Pattern.compile("^[a-zA-Z]+(_?[a-zA-Z0-9])*$"); public static void validateGroupName(ResourceGroupId rgid) { if (!GROUP_NAME_PATTERN.matcher(rgid.canonical()).matches()) { - throw new RuntimeException( + throw new IllegalArgumentException( "Group name: " + rgid.canonical() + " contains invalid characters"); } } diff --git a/core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java b/core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java index f5ef080818..f142d743dd 100644 --- a/core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java +++ b/core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java @@ -305,7 +305,8 @@ public class ClusterConfigParserTest extends WithTestNames { ClusterConfigParser.validateGroupNames(List.of("a")); ClusterConfigParser.validateGroupNames(List.of("a", "b")); ClusterConfigParser.validateGroupNames(List.of("default", "reg_ular")); - ClusterConfigParser.validateGroupNames(List.of("a1b2c3d4__")); + assertThrows(RuntimeException.class, + () -> ClusterConfigParser.validateGroupNames(List.of("a1b2c3d4__"))); assertThrows(RuntimeException.class, () -> ClusterConfigParser.validateGroupNames(List.of("0abcde"))); assertThrows(RuntimeException.class, diff --git a/core/src/test/java/org/apache/accumulo/core/data/ResourceGroupIdTest.java b/core/src/test/java/org/apache/accumulo/core/data/ResourceGroupIdTest.java new file mode 100644 index 0000000000..03cde2150b --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/data/ResourceGroupIdTest.java @@ -0,0 +1,41 @@ +/* + * 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 + * + * https://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.accumulo.core.data; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class ResourceGroupIdTest { + @Test + public void testIllegalIds() { + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of(" ")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("\t")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("_")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("9")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("9group1")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("$")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("$group1")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("group1 ")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("group 1")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("gro$up1")); + assertThrows(IllegalArgumentException.class, () -> ResourceGroupId.of("invalid_Group_")); + } +}