aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2014-12-19 00:17:54 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2014-12-19 00:17:54 +0100
commit75272ccdfc705a2e7c42cd5c27c4665c398b1b5d (patch)
tree330cb3ae8308e9f09ea918e32b0751f20901dba5 /org.eclipse.jgit.test/tst/org/eclipse/jgit/lib
parent53ff0529988ae8ec6f75a1f3d1b7b75de7dc304f (diff)
parent8899006c09058934074100ea8921b3175100412e (diff)
downloadjgit-75272ccdfc705a2e7c42cd5c27c4665c398b1b5d.tar.gz
jgit-75272ccdfc705a2e7c42cd5c27c4665c398b1b5d.zip
Merge branch 'stable-3.5' into stable-3.6
* stable-3.5: JGit v3.5.3.201412180710-r JGit v3.4.2.201412180340-r ObjectChecker: Disallow names potentially mapping to ".git" on HFS+ ObjectChecker: Disallow Windows shortname "GIT~1" ObjectChecker: Disallow ".git." and ".git<space>" Always ignore case when forbidding .git in ObjectChecker DirCache: Refuse to read files with invalid paths DirCache: Replace isValidPath with DirCacheCheckout.checkValidPath Replace "a." with "a-" in unit tests Apache HttpClientConnection: replace calls to deprecated LocalFile() Fix two nits about DirCacheEntry constructors Detect buffering failures while writing rebase todo file Deprecate TemporaryBuffer.LocalFile without parent directory Switch FileHeader.extractFileLines to TemporaryBuffer.Heap AmazonS3: Buffer pushed pack content under $GIT_DIR DirCache: Buffer TREE extension to $GIT_DIR Change-Id: Iee8acbaa9d4d9047b550641db1b8845d64530785 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib')
-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.java247
2 files changed, 243 insertions, 14 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 9fc7fca987..c6578ccfae 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
@@ -1295,12 +1295,11 @@ public class ObjectCheckerTest {
}
@Test
- public void testInvalidTreeNameIsMixedCaseGitWindows() {
+ public void testInvalidTreeNameIsMixedCaseGit() {
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) {
@@ -1309,20 +1308,256 @@ public class ObjectCheckerTest {
}
@Test
- public void testInvalidTreeNameIsMixedCaseGitMacOS() {
+ public void testInvalidTreeNameIsMacHFSGit() {
StringBuilder b = new StringBuilder();
- entry(b, "100644 .GiT");
- byte[] data = Constants.encodeASCII(b.toString());
+ entry(b, "100644 .gi\u200Ct");
+ byte[] data = Constants.encode(b.toString());
try {
checker.setSafeForMacOS(true);
checker.checkTree(data);
fail("incorrectly accepted an invalid tree");
} catch (CorruptObjectException e) {
- assertEquals("invalid name '.GiT'", e.getMessage());
+ assertEquals(
+ "invalid name '.gi\u200Ct' contains ignorable Unicode characters",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGit2() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 \u206B.git");
+ byte[] data = Constants.encode(b.toString());
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name '\u206B.git' contains ignorable Unicode characters",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGit3() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git\uFEFF");
+ byte[] data = Constants.encode(b.toString());
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name '.git\uFEFF' contains ignorable Unicode characters",
+ e.getMessage());
+ }
+ }
+
+ private static byte[] concat(byte[] b1, byte[] b2) {
+ byte[] data = new byte[b1.length + b2.length];
+ System.arraycopy(b1, 0, data, 0, b1.length);
+ System.arraycopy(b2, 0, data, b1.length, b2.length);
+ return data;
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGitCorruptUTF8AtEnd() {
+ byte[] data = concat(Constants.encode("100644 .git"),
+ new byte[] { (byte) 0xef });
+ StringBuilder b = new StringBuilder();
+ entry(b, "");
+ data = concat(data, Constants.encode(b.toString()));
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name contains byte sequence '0xef' which is not a valid UTF-8 character",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGitCorruptUTF8AtEnd2() {
+ byte[] data = concat(Constants.encode("100644 .git"), new byte[] {
+ (byte) 0xe2, (byte) 0xab });
+ StringBuilder b = new StringBuilder();
+ entry(b, "");
+ data = concat(data, Constants.encode(b.toString()));
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name contains byte sequence '0xe2ab' which is not a valid UTF-8 character",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsNotMacHFSGit()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git\u200Cx");
+ byte[] data = Constants.encode(b.toString());
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsNotMacHFSGit2()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .kit\u200C");
+ byte[] data = Constants.encode(b.toString());
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsNotMacHFSGitOtherPlatform()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git\u200C");
+ byte[] data = Constants.encode(b.toString());
+ checker.checkTree(data);
+ }
+
+ @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 testInvalidTreeNameIsGITTilde1() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 GIT~1");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name 'GIT~1'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsGiTTilde1() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 GiT~1");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name 'GiT~1'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testValidTreeNameIsGitTilde11() throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 GIT~11");
+ byte[] data = Constants.encodeASCII(b.toString());
+ checker.checkTree(data);
+ }
+
+ @Test
public void testInvalidTreeTruncatedInName() {
final StringBuilder b = new StringBuilder();
b.append("100644 b");