summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2014-03-12 13:59:29 -0700
committerShawn Pearce <spearce@spearce.org>2014-03-12 16:06:10 -0700
commit0aa682fc68a80704160102fc07dea5611c010746 (patch)
treee662f76dd4e0fe75549376eca9b3d033cc2d5b9f /org.eclipse.jgit.test
parente2f63788470a1cdd2d591505a00dd13ff1bf6a34 (diff)
downloadjgit-0aa682fc68a80704160102fc07dea5611c010746.tar.gz
jgit-0aa682fc68a80704160102fc07dea5611c010746.zip
Check for duplicate names after folding case in ObjectChecker
Mac OS X and Windows filesystems are generally case insensitive and will fold 'a' and 'A' to the same directory entry. If the checker is enforcing safe semantics for these platforms, track all names and look for duplicates after folding case and normalizing to NFC. Change-Id: I170b6f649a72d6ef322b7254943d4c604a8d25b9
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java56
1 files changed, 56 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 06745650ca..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;
@@ -1450,6 +1451,61 @@ 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);