summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2014-03-12 23:18:32 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2014-03-12 23:18:32 -0400
commit088e80315b1289a108254354328ff06cff8b8080 (patch)
tree51bb9e67c1510a39426ba402a08b102aae5f2164 /org.eclipse.jgit.test/tst
parent351aa430e2c01844ee1653dc32e6e8c923420a1d (diff)
parent3d412827e55fb43bdc2ae7475a3e54c92a55ad5e (diff)
downloadjgit-088e80315b1289a108254354328ff06cff8b8080.tar.gz
jgit-088e80315b1289a108254354328ff06cff8b8080.zip
Merge changes I1a225c1b,Ie4d5f082,I41f24363,I9440dd25,I170b6f64,I02e964d1,Iec6ce9e6,Ic700ea8f,Ic3042444,I90a1eaf2,I66eaee5c,Ib921dfd7
* changes: Allow configuration of receive pack's ObjectChecker through fsck.* Correct fetch to use fetch.fsckObjects and transfer.fsckObjects Default receive.fsckObjects to transfer.fsckObjects Allow ReceivePack callers to configure their own ObjectChecker Check for duplicate names after folding case in ObjectChecker Change DirCacheCheckout to verify path using ObjectChecker Reject mixed case .git on Mac OS in ObjectChecker Reject special Windows device names in ObjectChecker Allow an ObjectChecker to reject special characters for Windows Reject '.git' as a tree name in ObjectChecker Extract path segment check function in ObjectChecker Permit ObjectChecker to optionally accept leading '0' in trees
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java210
1 files changed, 210 insertions, 0 deletions
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 380defaa08..3f58b7501f 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
@@ -49,6 +49,7 @@ import static java.lang.Long.valueOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import org.eclipse.jgit.errors.CorruptObjectException;
@@ -1035,6 +1036,14 @@ public class ObjectCheckerTest {
}
@Test
+ public void testValidPosixTree() throws CorruptObjectException {
+ checkOneName("a<b>c:d|e");
+ checkOneName("test ");
+ checkOneName("test.");
+ checkOneName("NUL");
+ }
+
+ @Test
public void testValidTreeSorting1() throws CorruptObjectException {
final StringBuilder b = new StringBuilder();
entry(b, "100644 fooaaa");
@@ -1109,6 +1118,14 @@ public class ObjectCheckerTest {
}
@Test
+ public void testAcceptTreeModeWithZero() throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "040000 a");
+ checker.setAllowLeadingZeroFileMode(true);
+ checker.checkTree(Constants.encodeASCII(b.toString()));
+ }
+
+ @Test
public void testInvalidTreeModeStartsWithZero1() {
final StringBuilder b = new StringBuilder();
entry(b, "0 a");
@@ -1265,6 +1282,47 @@ public class ObjectCheckerTest {
}
@Test
+ public void testInvalidTreeNameIsGit() {
+ 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 testInvalidTreeNameIsMixedCaseGitWindows() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .GiT");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.setSafeForWindows(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name '.GiT'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMixedCaseGitMacOS() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .GiT");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.setSafeForMacOS(true);
+ 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");
@@ -1392,6 +1450,158 @@ public class ObjectCheckerTest {
}
}
+ @Test
+ public void testInvalidTreeDuplicateNames5()
+ throws UnsupportedEncodingException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 a");
+ entry(b, "100644 A");
+ byte[] data = b.toString().getBytes("UTF-8");
+ try {
+ checker.setSafeForWindows(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("duplicate entry names", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeDuplicateNames6()
+ throws UnsupportedEncodingException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 a");
+ entry(b, "100644 A");
+ byte[] data = b.toString().getBytes("UTF-8");
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("duplicate entry names", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeDuplicateNames7()
+ throws UnsupportedEncodingException {
+ try {
+ Class.forName("java.text.Normalizer");
+ } catch (ClassNotFoundException e) {
+ // Ignore this test on Java 5 platform.
+ return;
+ }
+
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 \u00C1");
+ entry(b, "100644 \u004a\u0301");
+ byte[] data = b.toString().getBytes("UTF-8");
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("duplicate entry names", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testRejectNulInPathSegment() {
+ try {
+ checker.checkPathSegment(Constants.encodeASCII("a\u0000b"), 0, 3);
+ fail("incorrectly accepted NUL in middle of name");
+ } catch (CorruptObjectException e) {
+ assertEquals("name contains byte 0x00", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testRejectSpaceAtEndOnWindows() {
+ checker.setSafeForWindows(true);
+ try {
+ checkOneName("test ");
+ fail("incorrectly accepted space at end");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name ends with ' '", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testRejectDotAtEndOnWindows() {
+ checker.setSafeForWindows(true);
+ try {
+ checkOneName("test.");
+ fail("incorrectly accepted dot at end");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name ends with '.'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testRejectDevicesOnWindows() {
+ checker.setSafeForWindows(true);
+
+ String[] bad = { "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3",
+ "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2",
+ "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };
+ for (String b : bad) {
+ try {
+ checkOneName(b);
+ fail("incorrectly accepted " + b);
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name '" + b + "'", e.getMessage());
+ }
+ try {
+ checkOneName(b + ".txt");
+ fail("incorrectly accepted " + b + ".txt");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name '" + b + "'", e.getMessage());
+ }
+ }
+ }
+
+ @Test
+ public void testRejectInvalidWindowsCharacters() {
+ checker.setSafeForWindows(true);
+ rejectName('<');
+ rejectName('>');
+ rejectName(':');
+ rejectName('"');
+ rejectName('/');
+ rejectName('\\');
+ rejectName('|');
+ rejectName('?');
+ rejectName('*');
+
+ for (int i = 1; i <= 31; i++)
+ rejectName((byte) i);
+ }
+
+ private void rejectName(char c) {
+ try {
+ checkOneName("te" + c + "st");
+ fail("incorrectly accepted with " + c);
+ } catch (CorruptObjectException e) {
+ assertEquals("name contains '" + c + "'", e.getMessage());
+ }
+ }
+
+ private void rejectName(byte c) {
+ String h = Integer.toHexString(c);
+ try {
+ checkOneName("te" + ((char) c) + "st");
+ fail("incorrectly accepted with 0x" + h);
+ } catch (CorruptObjectException e) {
+ assertEquals("name contains byte 0x" + h, e.getMessage());
+ }
+ }
+
+ private void checkOneName(String name) throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 " + name);
+ checker.checkTree(Constants.encodeASCII(b.toString()));
+ }
+
private static void entry(final StringBuilder b, final String modeName) {
b.append(modeName);
b.append('\0');