Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 6670c55

Browse files
jixinchigaul
authored andcommitted
add unit test for Filesystem BlobKey and ContainerName validator
1 parent 03aeccf commit 6670c55

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

apis/filesystem/src/main/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import com.google.inject.Singleton;
2222

23+
import java.io.File;
24+
import java.util.Arrays;
25+
2326
/**
2427
* Validates name for filesystem container blob keys implementation
2528
*
@@ -38,7 +41,7 @@ public void validate(String name) throws IllegalArgumentException {
3841
//blobkey cannot start with / (or \ in Windows) character
3942
if (name.startsWith("\\") || name.startsWith("/"))
4043
throw new IllegalArgumentException("Blob key '" + name + "' cannot start with \\ or /");
41-
if (name.contains("../"))
44+
if (Arrays.asList(name.split(File.separator.equals("\\") ? "\\\\" : File.separator)).contains(".."))
4245
throw new IllegalArgumentException("Blob key '" + name + "' cannot contain ../");
4346
}
4447

apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public void testNamesValidity() {
3636

3737
validator.validate("all.img");
3838
validator.validate("all" + File.separator + "is" + File.separator + "" + "ok");
39+
validator.validate("all" + File.separator + "is" + File.separator + ".." + "ok");
3940
}
4041

4142
@Test
@@ -51,6 +52,11 @@ public void testInvalidNames() {
5152
validator.validate(File.separator + "is" + File.separator + "" + "ok");
5253
fail("Blob key value incorrect, but was not recognized");
5354
} catch (IllegalArgumentException e) {}
55+
56+
try {
57+
validator.validate("all" + File.separator + ".." + File.separator + "ok");
58+
fail("Blob key value incorrect, but was not recognized");
59+
} catch (IllegalArgumentException e) {}
5460
}
5561

5662

apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemContainerNameValidatorTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ public void testInvalidNames() {
6060
validator.validate("all" + File.separator + "is" + File.separator);
6161
fail("Container name value incorrect, but was not recognized");
6262
} catch (IllegalArgumentException e) {}
63+
64+
try {
65+
validator.validate(".");
66+
fail("Container name value incorrect, but was not recognized");
67+
} catch (IllegalArgumentException e) {}
68+
69+
try {
70+
validator.validate("..");
71+
fail("Container name value incorrect, but was not recognized");
72+
} catch (IllegalArgumentException e) {}
6373
}
6474

6575

0 commit comments

Comments
 (0)