aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2018-10-06 16:56:12 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2018-10-06 16:56:12 +0200
commitdff99a272a96777a445cf4e822ffc22067222ce9 (patch)
tree06349d3a7eff369372dd15e41f9575805faa8da0 /org.eclipse.jgit.test/tst
parent9dbb18291fc680ec9326b866f133b233093d800f (diff)
parent23ebbe5662f10a4b8ad47b1fb1cfe115e03d2ddd (diff)
downloadjgit-dff99a272a96777a445cf4e822ffc22067222ce9.tar.gz
jgit-dff99a272a96777a445cf4e822ffc22067222ce9.zip
Merge branch 'stable-5.0' into stable-5.1
* stable-5.0: Prepare 4.11.5-SNAPSHOT builds JGit v4.11.4.201810060650-r Fix configuration of maven-javadoc-plugin Prepare 4.9.7-SNAPSHOT builds JGit v4.9.6.201810051924-r Prepare 4.7.6-SNAPSHOT builds JGit v4.7.5.201810051826-r BaseReceivePack: Validate incoming .gitmodules files ObjectChecker: Report .gitmodules files found in the pack SubmoduleAddCommand: Reject submodule URIs that look like cli options * Fix todos in SubmoduleAddTest Change-Id: I53272081094b8948a40a1ce409af08b6ef330c1e Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java119
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java65
3 files changed, 210 insertions, 2 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 7ea504374c..531c918e9b 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
@@ -837,6 +837,112 @@ public class ObjectCheckerTest {
}
@Test
+ public void testValidTreeWithGitmodules() throws CorruptObjectException {
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ ObjectId blobId = entry(b, "100644 .gitmodules");
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ assertEquals(1, checker.getGitsubmodules().size());
+ assertEquals(treeId, checker.getGitsubmodules().get(0).getTreeId());
+ assertEquals(blobId, checker.getGitsubmodules().get(0).getBlobId());
+ }
+
+ /*
+ * Windows case insensitivity and long file name handling
+ * means that .gitmodules has many synonyms.
+ *
+ * Examples inspired by git.git's t/t0060-path-utils.sh, by
+ * Johannes Schindelin and Congyi Wu.
+ */
+ @Test
+ public void testNTFSGitmodules() throws CorruptObjectException {
+ for (String gitmodules : new String[] {
+ ".GITMODULES",
+ ".gitmodules",
+ ".Gitmodules",
+ ".gitmoduleS",
+ "gitmod~1",
+ "GITMOD~1",
+ "gitmod~4",
+ "GI7EBA~1",
+ "gi7eba~9",
+ "GI7EB~10",
+ "GI7E~123",
+ "~1000000",
+ "~9999999"
+ }) {
+ checker = new ObjectChecker(); // Reset the ObjectChecker state.
+ checker.setSafeForWindows(true);
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ ObjectId blobId = entry(b, "100644 " + gitmodules);
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ assertEquals(1, checker.getGitsubmodules().size());
+ assertEquals(treeId, checker.getGitsubmodules().get(0).getTreeId());
+ assertEquals(blobId, checker.getGitsubmodules().get(0).getBlobId());
+ }
+ }
+
+ @Test
+ public void testNotGitmodules() throws CorruptObjectException {
+ for (String notGitmodules : new String[] {
+ ".gitmodu",
+ ".gitmodules oh never mind",
+ }) {
+ checker = new ObjectChecker(); // Reset the ObjectChecker state.
+ checker.setSafeForWindows(true);
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 " + notGitmodules);
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ assertEquals(0, checker.getGitsubmodules().size());
+ }
+ }
+
+ /*
+ * TODO HFS: match ".gitmodules" case-insensitively, after stripping out
+ * certain zero-length Unicode code points that HFS+ strips out
+ */
+
+ @Test
+ public void testValidTreeWithGitmodulesUppercase()
+ throws CorruptObjectException {
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ ObjectId blobId = entry(b, "100644 .GITMODULES");
+
+ byte[] data = encodeASCII(b.toString());
+ checker.setSafeForWindows(true);
+ checker.checkTree(treeId, data);
+ assertEquals(1, checker.getGitsubmodules().size());
+ assertEquals(treeId, checker.getGitsubmodules().get(0).getTreeId());
+ assertEquals(blobId, checker.getGitsubmodules().get(0).getBlobId());
+ }
+
+ @Test
+ public void testTreeWithInvalidGitmodules() throws CorruptObjectException {
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .gitmodulez");
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ checker.setSafeForWindows(true);
+ assertEquals(0, checker.getGitsubmodules().size());
+ }
+
+ @Test
public void testNullSha1InTreeEntry() throws CorruptObjectException {
byte[] data = concat(
encodeASCII("100644 A"), new byte[] { '\0' },
@@ -1607,11 +1713,20 @@ public class ObjectCheckerTest {
checker.checkTree(encodeASCII(b.toString()));
}
- private static void entry(StringBuilder b, String modeName) {
+ /*
+ * Returns the id generated for the entry
+ */
+ private static ObjectId entry(StringBuilder b, String modeName) {
+ byte[] id = new byte[OBJECT_ID_LENGTH];
+
b.append(modeName);
b.append('\0');
- for (int i = 0; i < OBJECT_ID_LENGTH; i++)
+ for (int i = 0; i < OBJECT_ID_LENGTH; i++) {
b.append((char) i);
+ id[i] = (byte) i;
+ }
+
+ return ObjectId.fromRaw(id);
}
private void assertCorrupt(String msg, int type, StringBuilder b) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
index 0676eab2d6..1ff64a2e28 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
@@ -226,6 +226,34 @@ public class SubmoduleAddTest extends RepositoryTestCase {
}
@Test
+ public void addSubmoduleWithInvalidPath() throws Exception {
+ SubmoduleAddCommand command = new SubmoduleAddCommand(db);
+ command.setPath("-invalid-path");
+ command.setName("sub");
+ command.setURI("http://example.com/repo/x.git");
+ try {
+ command.call().close();
+ fail("Exception not thrown");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Invalid submodule path '-invalid-path'",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void addSubmoduleWithInvalidUri() throws Exception {
+ SubmoduleAddCommand command = new SubmoduleAddCommand(db);
+ command.setPath("valid-path");
+ command.setURI("-upstream");
+ try {
+ command.call().close();
+ fail("Exception not thrown");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Invalid submodule URL '-upstream'", e.getMessage());
+ }
+ }
+
+ @Test
public void addSubmoduleWithRelativeUri() throws Exception {
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
index 9cc6cfd393..c959f6c497 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
@@ -469,6 +469,71 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
}
@Test
+ public void testIncludesInvalidGitmodules() throws Exception {
+ final TemporaryBuffer.Heap inBuf = setupSourceRepoInvalidGitmodules();
+ final TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
+ final ReceivePack rp = new ReceivePack(dst);
+ rp.setCheckReceivedObjects(true);
+ rp.setCheckReferencedObjectsAreReachable(true);
+ rp.setAdvertiseRefsHook(new HidePrivateHook());
+ try {
+ receive(rp, inBuf, outBuf);
+ fail("Expected UnpackException");
+ } catch (UnpackException failed) {
+ Throwable err = failed.getCause();
+ assertTrue(err instanceof IOException);
+ }
+
+ final PacketLineIn r = asPacketLineIn(outBuf);
+ String master = r.readString();
+ int nul = master.indexOf('\0');
+ assertTrue("has capability list", nul > 0);
+ assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
+ assertSame(PacketLineIn.END, r.readString());
+
+ String errorLine = r.readString();
+ System.out.println(errorLine);
+ assertTrue(errorLine.startsWith(
+ "unpack error Invalid submodule URL '-"));
+ assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString());
+ assertSame(PacketLineIn.END, r.readString());
+ }
+
+ private TemporaryBuffer.Heap setupSourceRepoInvalidGitmodules()
+ throws IOException, Exception, MissingObjectException {
+ String fakeGitmodules = new StringBuilder()
+ .append("[submodule \"test\"]\n")
+ .append(" path = xlib\n")
+ .append(" url = https://example.com/repo/xlib.git\n\n")
+ .append("[submodule \"test2\"]\n")
+ .append(" path = zlib\n")
+ .append(" url = -upayload.sh\n")
+ .toString();
+
+ TestRepository<Repository> s = new TestRepository<>(src);
+ RevBlob blob = s.blob(fakeGitmodules);
+ RevCommit N = s.commit().parent(B)
+ .add(".gitmodules", blob).create();
+ RevTree t = s.parseBody(N).getTree();
+
+ final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
+ packHeader(pack, 3);
+ copy(pack, src.open(N));
+ copy(pack, src.open(t));
+ copy(pack, src.open(blob));
+ digest(pack);
+
+ final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
+ final PacketLineOut inPckLine = new PacketLineOut(inBuf);
+ inPckLine.writeString(ObjectId.zeroId().name() + ' ' + N.name() + ' '
+ + "refs/heads/s" + '\0'
+ + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
+ inPckLine.end();
+ pack.writeTo(inBuf, PM);
+ return inBuf;
+ }
+
+ @Test
public void testUsingUnknownTreeFails() throws Exception {
TestRepository<Repository> s = new TestRepository<>(src);
RevCommit N = s.commit().parent(B).add("q", s.blob("a")).create();