Skip to content

Commit 8fbe16b

Browse files
authored
HDDS-14795. Allow non-S3-compliant bucket name length if strict S3 is disabled (#10014)
1 parent b111e00 commit 8fbe16b

2 files changed

Lines changed: 51 additions & 26 deletions

File tree

hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,35 @@ public final class HddsClientUtils {
7171
private HddsClientUtils() {
7272
}
7373

74-
private static void doNameChecks(String resName, String resType) {
74+
private static void doNameChecks(String resName, String resType, boolean isStrictS3) {
7575
if (resName == null) {
7676
throw new IllegalArgumentException(resType + " name is null");
7777
}
7878

79-
if (resName.length() < OzoneConsts.OZONE_MIN_BUCKET_NAME_LENGTH) {
80-
throw new IllegalArgumentException(resType +
81-
" name '" + resName + "' is too short, " +
82-
VALID_LENGTH_MESSAGE);
83-
}
84-
85-
if (resName.length() > OzoneConsts.OZONE_MAX_BUCKET_NAME_LENGTH) {
86-
String nameToReport;
79+
boolean applyS3LengthConstraint = !resType.equals("bucket") || isStrictS3;
8780

88-
if (resName.length() > MAX_BUCKET_NAME_LENGTH_IN_LOG) {
89-
nameToReport = String.format(
90-
"%s...",
91-
resName.substring(0, MAX_BUCKET_NAME_LENGTH_IN_LOG));
92-
} else {
93-
nameToReport = resName;
81+
if (applyS3LengthConstraint) {
82+
if (resName.length() < OzoneConsts.OZONE_MIN_BUCKET_NAME_LENGTH) {
83+
throw new IllegalArgumentException(resType +
84+
" name '" + resName + "' is too short, " +
85+
VALID_LENGTH_MESSAGE);
9486
}
9587

96-
throw new IllegalArgumentException(resType +
97-
" name '" + nameToReport + "' is too long, " +
98-
VALID_LENGTH_MESSAGE);
88+
if (resName.length() > OzoneConsts.OZONE_MAX_BUCKET_NAME_LENGTH) {
89+
String nameToReport;
90+
91+
if (resName.length() > MAX_BUCKET_NAME_LENGTH_IN_LOG) {
92+
nameToReport = String.format(
93+
"%s...",
94+
resName.substring(0, MAX_BUCKET_NAME_LENGTH_IN_LOG));
95+
} else {
96+
nameToReport = resName;
97+
}
98+
99+
throw new IllegalArgumentException(resType +
100+
" name '" + nameToReport + "' is too long, " +
101+
VALID_LENGTH_MESSAGE);
102+
}
99103
}
100104

101105
if (resName.charAt(0) == '.' || resName.charAt(0) == '-') {
@@ -191,7 +195,7 @@ public static void verifyResourceName(String resName, String resType, boolean is
191195
" name cannot be an IPv4 address or all numeric");
192196
}
193197

194-
doNameChecks(resName, resType);
198+
doNameChecks(resName, resType, isStrictS3);
195199
}
196200

197201
/**

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/bucket/TestOMBucketCreateRequest.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.apache.hadoop.ozone.om.request.OMRequestTestUtils.newBucketInfoBuilder;
2121
import static org.apache.hadoop.ozone.om.request.OMRequestTestUtils.newCreateBucketRequest;
22+
import static org.assertj.core.api.Assertions.assertThat;
2223
import static org.junit.jupiter.api.Assertions.assertEquals;
2324
import static org.junit.jupiter.api.Assertions.assertFalse;
2425
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -67,14 +68,34 @@ public void testPreExecute() throws Exception {
6768
doPreExecute(volumeName, bucketName);
6869
}
6970

70-
@Test
71-
public void preExecuteRejectsInvalidBucketName() {
72-
// Verify invalid bucket name throws exception
71+
@ParameterizedTest
72+
@ValueSource(strings = {
73+
"b1",
74+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
75+
})
76+
public void preExecuteRejectsInvalidBucketNameLengthWhenStrictS3Enabled(
77+
String bucketName) {
78+
when(ozoneManager.isStrictS3()).thenReturn(true);
79+
7380
OMException omException = assertThrows(OMException.class,
74-
() -> doPreExecute("volume1", "b1"));
75-
assertEquals(
76-
"bucket name 'b1' is too short, valid length is 3-63 characters",
77-
omException.getMessage());
81+
() -> doPreExecute("volume1", bucketName));
82+
83+
assertThat(omException.getMessage())
84+
.contains("bucket name")
85+
.contains("valid length is 3-63 characters");
86+
}
87+
88+
@ParameterizedTest
89+
@ValueSource(strings = {
90+
"b1",
91+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
92+
})
93+
public void preExecuteAllowsInvalidLengthBucketNameWhenStrictS3Disabled(
94+
String bucketName) throws Exception {
95+
96+
when(ozoneManager.isStrictS3()).thenReturn(false);
97+
98+
doPreExecute("volume1", bucketName);
7899
}
79100

80101
@Test

0 commit comments

Comments
 (0)