diff options
Diffstat (limited to 'src/test/java/com/gitblit/tests/GitBlitSuite.java')
-rw-r--r-- | src/test/java/com/gitblit/tests/GitBlitSuite.java | 94 |
1 files changed, 89 insertions, 5 deletions
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java index 133be77f..3292d090 100644 --- a/src/test/java/com/gitblit/tests/GitBlitSuite.java +++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java @@ -16,10 +16,15 @@ package com.gitblit.tests;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.lang.reflect.Field;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
@@ -27,12 +32,14 @@ import org.eclipse.jgit.lib.RepositoryCache; import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
+import com.gitblit.FileSettings;
import com.gitblit.GitBlitException;
import com.gitblit.GitBlitServer;
import com.gitblit.manager.IRepositoryManager;
@@ -77,6 +84,18 @@ public class GitBlitSuite { public static final File USERSCONF = new File("src/test/config/test-users.conf");
+ private static final File AMBITION_REPO_SOURCE = new File("src/test/data/ambition.git");
+
+ private static final File TICGIT_REPO_SOURCE = new File("src/test/data/ticgit.git");
+
+ private static final File GITECTIVE_REPO_SOURCE = new File("src/test/data/gitective.git");
+
+ private static final File HELLOWORLD_REPO_SOURCE = new File("src/test/data/hello-world.git");
+
+ private static final File HELLOWORLD_REPO_PROPERTIES = new File("src/test/data/hello-world.properties");
+
+ public static final FileSettings helloworldSettings = new FileSettings(HELLOWORLD_REPO_PROPERTIES.getAbsolutePath());
+
static int port = 8280;
static int gitPort = 8300;
static int shutdownPort = 8281;
@@ -167,17 +186,39 @@ public class GitBlitSuite { Thread.sleep(5000);
}
+ public static void deleteRefChecksFolder() throws IOException {
+ File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks");
+ if (refChecks.exists()) {
+ FileUtils.delete(refChecks, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
+ }
+
@BeforeClass
public static void setUp() throws Exception {
+ //"refchecks" folder is used in GitServletTest;
+ //need be deleted before Gitblit server instance is started
+ deleteRefChecksFolder();
startGitblit();
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
- cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
- cloneOrFetch("ticgit.git", "https://github.com/schacon/ticgit.git");
+ if (!HELLOWORLD_REPO_SOURCE.exists()) {
+ unzipRepository(HELLOWORLD_REPO_SOURCE.getPath() + ".zip", HELLOWORLD_REPO_SOURCE.getParentFile());
+ }
+ if (!TICGIT_REPO_SOURCE.exists()) {
+ unzipRepository(TICGIT_REPO_SOURCE.getPath() + ".zip", TICGIT_REPO_SOURCE.getParentFile());
+ }
+ if (!AMBITION_REPO_SOURCE.exists()) {
+ unzipRepository(AMBITION_REPO_SOURCE.getPath() + ".zip", AMBITION_REPO_SOURCE.getParentFile());
+ }
+ if (!GITECTIVE_REPO_SOURCE.exists()) {
+ unzipRepository(GITECTIVE_REPO_SOURCE.getPath() + ".zip", GITECTIVE_REPO_SOURCE.getParentFile());
+ }
+ cloneOrFetch("helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
+ cloneOrFetch("ticgit.git", TICGIT_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
- cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
- cloneOrFetch("test/ambition.git", "https://github.com/defunkt/ambition.git");
- cloneOrFetch("test/gitective.git", "https://github.com/kevinsawicki/gitective.git");
+ cloneOrFetch("test/helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
+ cloneOrFetch("test/ambition.git", AMBITION_REPO_SOURCE.getAbsolutePath());
+ cloneOrFetch("test/gitective.git", GITECTIVE_REPO_SOURCE.getAbsolutePath());
showRemoteBranches("ticgit.git");
automaticallyTagBranchTips("ticgit.git");
@@ -254,4 +295,47 @@ public class GitBlitSuite { r.close();
}
}
+
+ private static void unzipRepository(String zippedRepo, File destDir) throws IOException {
+ System.out.print("Unzipping " + zippedRepo + "... ");
+ if (!destDir.exists()) {
+ destDir.mkdir();
+ }
+ byte[] buffer = new byte[1024];
+ ZipInputStream zis = new ZipInputStream(new FileInputStream(zippedRepo));
+ ZipEntry zipEntry = zis.getNextEntry();
+ while (zipEntry != null) {
+ File newFile = newFile(destDir, zipEntry);
+ if (zipEntry.isDirectory()) {
+ newFile.mkdirs();
+ }
+ else {
+ FileOutputStream fos = new FileOutputStream(newFile);
+ int len;
+ while ((len = zis.read(buffer)) > 0) {
+ fos.write(buffer, 0, len);
+ }
+ fos.close();
+ }
+ zipEntry = zis.getNextEntry();
+ }
+ zis.closeEntry();
+ zis.close();
+ System.out.println("done.");
+ }
+
+ private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
+ File destFile = new File(destinationDir, zipEntry.getName());
+
+ String destDirPath = destinationDir.getCanonicalPath();
+ String destFilePath = destFile.getCanonicalPath();
+ //guards against writing files to the file system outside of the target folder
+ //to prevent Zip Slip exploit
+ if (!destFilePath.startsWith(destDirPath + File.separator)) {
+ throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
+ }
+
+ return destFile;
+ }
+
}
|