-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-12649. Include name in length validation error #8322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,14 @@ | |
| import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_PORT_KEY; | ||
| import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NAMES; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import java.io.IOException; | ||
| import java.net.ConnectException; | ||
| import java.net.InetSocketAddress; | ||
|
|
@@ -191,6 +194,10 @@ public void testBlockClientFallbackToClientWithPort() { | |
| assertEquals(OZONE_SCM_BLOCK_CLIENT_PORT_DEFAULT, address.getPort()); | ||
| } | ||
|
|
||
| private String getInvalidNameMessage(String invalidString) { | ||
| return "Did not reject invalid string [" + invalidString + "] as a name"; | ||
| } | ||
|
|
||
| @Test | ||
| public void testVerifyResourceName() { | ||
| final String validName = "my-bucket.01"; | ||
|
|
@@ -225,8 +232,38 @@ public void testVerifyResourceName() { | |
|
|
||
| for (String name : invalidNames) { | ||
| assertThrows(IllegalArgumentException.class, () -> HddsClientUtils.verifyResourceName(name), | ||
| "Did not reject invalid string [" + name + "] as a name"); | ||
| getInvalidNameMessage(name)); | ||
| } | ||
|
|
||
| // Message should include the name and resource type, if the name is of | ||
| // illegal length. | ||
| List<String> resourceTypes = ImmutableList.of("bucket", "volume"); | ||
| for (int i = 0; i < 2; i++) { | ||
| String resType = resourceTypes.get(i); | ||
| String otherResType = resourceTypes.get(1 - i); | ||
| Throwable thrown = assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> HddsClientUtils.verifyResourceName(tooShort, resType, true), | ||
| getInvalidNameMessage(tooShort)); | ||
|
|
||
| String message = thrown.getMessage(); | ||
| assertNotNull(message); | ||
| assertTrue(message.contains(resType)); | ||
| assertFalse(message.contains(otherResType)); | ||
| assertTrue(thrown.getMessage().contains(tooShort)); | ||
|
||
| } | ||
|
|
||
| // However, such names also containing unsupported characters should not be | ||
| // logged verbatim. This is to avoid vulnerabilities like Log4Shell. | ||
| final String tooShortInvalidChar = "$a"; | ||
| Throwable thrown = assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> HddsClientUtils.verifyResourceName(tooShortInvalidChar), | ||
| getInvalidNameMessage(tooShortInvalidChar)); | ||
|
|
||
| String message = thrown.getMessage(); | ||
| assertNotNull(message); | ||
| assertFalse(message.contains(tooShortInvalidChar)); | ||
|
||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -250,7 +287,7 @@ void testVerifyKeyName() throws IllegalArgumentException { | |
|
|
||
| for (String name : invalidNames) { | ||
| assertThrows(IllegalArgumentException.class, () -> HddsClientUtils.verifyKeyName(name), | ||
| "Did not reject invalid string [" + name + "] as a name"); | ||
| getInvalidNameMessage(name)); | ||
| } | ||
|
|
||
| List<String> validNames = new ArrayList<>(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, added both.