mirror of https://github.com/apache/jclouds.git
add unit test for Filesystem BlobKey and ContainerName validator
This commit is contained in:
parent
03aeccffdf
commit
6670c556d7
|
@ -20,6 +20,9 @@ import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
|||
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Validates name for filesystem container blob keys implementation
|
||||
*
|
||||
|
@ -38,7 +41,7 @@ public class FilesystemBlobKeyValidatorImpl extends FilesystemBlobKeyValidator {
|
|||
//blobkey cannot start with / (or \ in Windows) character
|
||||
if (name.startsWith("\\") || name.startsWith("/"))
|
||||
throw new IllegalArgumentException("Blob key '" + name + "' cannot start with \\ or /");
|
||||
if (name.contains("../"))
|
||||
if (Arrays.asList(name.split(File.separator.equals("\\") ? "\\\\" : File.separator)).contains(".."))
|
||||
throw new IllegalArgumentException("Blob key '" + name + "' cannot contain ../");
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ public class FilesystemBlobKeyValidatorTest {
|
|||
|
||||
validator.validate("all.img");
|
||||
validator.validate("all" + File.separator + "is" + File.separator + "" + "ok");
|
||||
validator.validate("all" + File.separator + "is" + File.separator + ".." + "ok");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,6 +52,11 @@ public class FilesystemBlobKeyValidatorTest {
|
|||
validator.validate(File.separator + "is" + File.separator + "" + "ok");
|
||||
fail("Blob key value incorrect, but was not recognized");
|
||||
} catch (IllegalArgumentException e) {}
|
||||
|
||||
try {
|
||||
validator.validate("all" + File.separator + ".." + File.separator + "ok");
|
||||
fail("Blob key value incorrect, but was not recognized");
|
||||
} catch (IllegalArgumentException e) {}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -60,6 +60,16 @@ public class FilesystemContainerNameValidatorTest {
|
|||
validator.validate("all" + File.separator + "is" + File.separator);
|
||||
fail("Container name value incorrect, but was not recognized");
|
||||
} catch (IllegalArgumentException e) {}
|
||||
|
||||
try {
|
||||
validator.validate(".");
|
||||
fail("Container name value incorrect, but was not recognized");
|
||||
} catch (IllegalArgumentException e) {}
|
||||
|
||||
try {
|
||||
validator.validate("..");
|
||||
fail("Container name value incorrect, but was not recognized");
|
||||
} catch (IllegalArgumentException e) {}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue