Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
fixing reviews and adding unit test ZipsTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
rupalibehera committed Jun 7, 2018
1 parent c7d4db1 commit 836f276
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,9 @@ public static void unzip(InputStream in, File toDir) throws IOException {
if (!entry.isDirectory()) {
String entryName = entry.getName();
File toFile = new File(toDir, entryName);
String fileDestinationFullPath = toFile.getPath();
try{
if (!fileDestinationFullPath.startsWith(toDir.getPath())); throw new IOException("Extracting results to different directory");

}catch (IOException e){
System.out.println(e);
System.exit(1);
}
if (!toFile.getCanonicalPath().startsWith(toDir.getPath()))
throw new IOException("Extracting file to different directory");

toFile.getParentFile().mkdirs();
OutputStream os = new FileOutputStream(toFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2005-2016 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version
* 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package io.fabric8.utils;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;


public class ZipsTest {
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

@Test(expected = IOException.class)
public void unzip() throws Exception {
File zipFile = new File(getClass().getResource("/zip-test.zip").getFile());
File outDir = tempDir.newFolder("test").getAbsoluteFile();
Zips.unzip(new FileInputStream(zipFile),outDir);
}

}
Binary file not shown.

0 comments on commit 836f276

Please sign in to comment.