Search in sources :

Example 16 with ZipResource

use of org.mule.tck.ZipUtils.ZipResource in project mule by mulesoft.

the class FileUtilsTestCase method doesNotUnzipExternalPaths.

@Test
public void doesNotUnzipExternalPaths() throws Exception {
    final String resourceName = "dummy.xml";
    final String resourceAlias = Paths.get("folder", "..", "..", resourceName).toString();
    final File compressedFile = new File(toDir, "test.zip");
    compress(compressedFile, new ZipResource[] { new ZipResource(resourceName, resourceName), new ZipResource(resourceName, resourceAlias) });
    thrownException.expect(InvalidZipFileException.class);
    thrownException.expectMessage("External paths are not allowed: " + resourceAlias);
    unzip(compressedFile, toDir);
    // make sure it did not extract other archive files
    assertThat(new File(toDir, resourceName).exists(), is(false));
}
Also used : ZipResource(org.mule.tck.ZipUtils.ZipResource) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) File(java.io.File) Test(org.junit.Test)

Example 17 with ZipResource

use of org.mule.tck.ZipUtils.ZipResource in project mule by mulesoft.

the class FileUtilsTestCase method doesNotUnzipAbsolutePaths.

@Test
public void doesNotUnzipAbsolutePaths() throws Exception {
    final String resourceName = "dummy.xml";
    final String resourceAlias = new File(resourceName).getAbsolutePath();
    final File compressedFile = new File(toDir, "test.zip");
    compress(compressedFile, new ZipResource[] { new ZipResource(resourceName, resourceName), new ZipResource(resourceName, resourceAlias) });
    thrownException.expect(InvalidZipFileException.class);
    thrownException.expectMessage("Absolute paths are not allowed: " + resourceAlias);
    unzip(compressedFile, toDir);
    // make sure it did not extract other archive files
    assertThat(new File(toDir, resourceName).exists(), is(false));
}
Also used : ZipResource(org.mule.tck.ZipUtils.ZipResource) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) File(java.io.File) Test(org.junit.Test)

Aggregations

ZipResource (org.mule.tck.ZipUtils.ZipResource)17 File (java.io.File)10 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)4 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)3 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)3 IOException (java.io.IOException)2 MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)1 MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)1 MulePluginModel (org.mule.runtime.api.deployment.meta.MulePluginModel)1 MulePluginModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer)1 MulePolicyModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePolicyModelJsonSerializer)1