-
Notifications
You must be signed in to change notification settings - Fork 589
HDDS-13444. Unify isValidKeyPath implementation #9521
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -19,10 +19,12 @@ | |
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.ozone.OzoneConfigKeys; | ||
| import org.apache.hadoop.ozone.om.exceptions.OMException; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
|
|
@@ -67,4 +69,40 @@ void testCanEnableHsync(boolean canEnableHsync, | |
|
|
||
| assertEquals(canEnableHsync, OzoneFSUtils.canEnableHsync(conf, isClient)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsValidKeyPath() throws OMException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add some tests like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no problem!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can add some more test cases for key paths like |
||
| // Valid paths | ||
| assertEquals("a/b/c", OzoneFSUtils.isValidKeyPath("a/b/c", true)); | ||
| assertEquals("a/b/c", OzoneFSUtils.isValidKeyPath("a/b/c", false)); | ||
| assertEquals("file", OzoneFSUtils.isValidKeyPath("file", true)); | ||
| assertEquals("dir/subdir/file", OzoneFSUtils.isValidKeyPath("dir/subdir/file", true)); | ||
|
|
||
| // Empty path - throwOnEmpty=true should throw exception | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("", true)); | ||
|
|
||
| // Empty path - throwOnEmpty=false should return empty string | ||
| assertEquals("", OzoneFSUtils.isValidKeyPath("", false)); | ||
|
|
||
| // Invalid paths - leading slash | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("/a/b", true)); | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("/a/b", false)); | ||
|
|
||
| // Invalid paths - contains ".." | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("a/../b", true)); | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("../a/b", true)); | ||
|
|
||
| // Invalid paths - contains "." | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("a/./b", true)); | ||
|
|
||
| // Invalid paths - contains ":" | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("a:b", true)); | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("a/b:c", true)); | ||
|
|
||
| // Invalid paths - contains "//" in the middle | ||
| assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("a//b", true)); | ||
|
|
||
| // Valid path ending with "/" | ||
| assertEquals("a/b/", OzoneFSUtils.isValidKeyPath("a/b/", true)); | ||
| } | ||
| } | ||
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.
or we could instead remove path from the message as it is empty and the message already says empty KeyName.