summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java96
2 files changed, 98 insertions, 8 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
index d29a75ef71..ca3e0666ea 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
@@ -186,10 +186,7 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
@Test
public void testMaliciousGitPathEndSpaceUnixOk() throws Exception {
- if (File.separatorChar == '\\')
- return; // cannot emulate Unix on Windows for this test
- ((MockSystemReader) SystemReader.getInstance()).setUnix();
- testMaliciousPathGoodFirstCheckout(".git ", "konfig");
+ testMaliciousPathBadFirstCheckout(".git ", "konfig");
}
@Test
@@ -212,10 +209,7 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
@Test
public void testMaliciousGitPathEndDotUnixOk() throws Exception {
- if (File.separatorChar == '\\')
- return; // cannot emulate Unix on Windows for this test
- ((MockSystemReader) SystemReader.getInstance()).setUnix();
- testMaliciousPathGoodFirstCheckout(".git.", "konfig");
+ testMaliciousPathBadFirstCheckout(".git.", "konfig");
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
index f3db2f65da..aa17ac32cf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
@@ -1308,6 +1308,102 @@ public class ObjectCheckerTest {
}
@Test
+ public void testInvalidTreeNameIsDotGitDot() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git.");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name '.git.'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testValidTreeNameIsDotGitDotDot()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git..");
+ checker.checkTree(Constants.encodeASCII(b.toString()));
+ }
+
+ @Test
+ public void testInvalidTreeNameIsDotGitSpace() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git ");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name '.git '", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsDotGitSomething()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .gitfoobar");
+ byte[] data = Constants.encodeASCII(b.toString());
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsDotGitSomethingSpaceSomething()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .gitfoo bar");
+ byte[] data = Constants.encodeASCII(b.toString());
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsDotGitSomethingDot()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .gitfoobar.");
+ byte[] data = Constants.encodeASCII(b.toString());
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsDotGitSomethingDotDot()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .gitfoobar..");
+ byte[] data = Constants.encodeASCII(b.toString());
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsDotGitDotSpace() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git. ");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name '.git. '", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsDotGitSpaceDot() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git . ");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name '.git . '", e.getMessage());
+ }
+ }
+
+ @Test
public void testInvalidTreeTruncatedInName() {
final StringBuilder b = new StringBuilder();
b.append("100644 b");