]> source.dussan.org Git - jgit.git/commitdiff
Test advertised capabilities with protocol V0 and allow*Sha1InWant 80/1202480/6
authorLuca Milanesio <luca.milanesio@gmail.com>
Fri, 11 Oct 2024 21:40:16 +0000 (22:40 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 11 Oct 2024 23:21:50 +0000 (01:21 +0200)
The advertised capabilities with protocol V0 were untested
leading to potential regressions when advertising what
SHA1 should or should not be on the list of capabilities.

Verify that allow-tip-sha1-in-want and allow-reachable-sha1-in-want
are properly advertised with the allow*Sha1InWant is set in
jgit.config.

Change-Id: I99d062a5a630b02ca3d1fe83bf6cdf3c284ae941

org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java

index def73acaddaf3e8ce63172d0c3899a66bab37fa5..017104c527875400adb4ce4540fcb2b654b3d441 100644 (file)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -563,6 +564,47 @@ public class UploadPackTest {
                assertThat(lines, hasItems("ls-refs", "fetch", "server-option"));
        }
 
+       @Test
+       public void testV0CapabilitiesAllowAnySha1InWant() throws Exception {
+               checkAvertisedCapabilityProtocolV0IfAllowed("uploadpack",
+                               "allowanysha1inwant", "allow-reachable-sha1-in-want",
+                               "allow-tip-sha1-in-want");
+       }
+
+       @Test
+       public void testV0CapabilitiesAllowReachableSha1InWant() throws Exception {
+               checkAvertisedCapabilityProtocolV0IfAllowed("uploadpack",
+                               "allowreachablesha1inwant", "allow-reachable-sha1-in-want");
+       }
+
+       @Test
+       public void testV0CapabilitiesAllowTipSha1InWant() throws Exception {
+               checkAvertisedCapabilityProtocolV0IfAllowed("uploadpack",
+                               "allowtipsha1inwant", "allow-tip-sha1-in-want");
+       }
+
+       private void checkAvertisedCapabilityProtocolV0IfAllowed(
+                       String configSection, String configName, String... capabilities)
+                       throws Exception {
+               server.getConfig().setBoolean(configSection, null, configName, true);
+               ByteArrayInputStream recvStream = uploadPackSetup(
+                               TransferConfig.ProtocolVersion.V0.version(), null,
+                               PacketLineIn.end());
+               PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+               String line;
+               while (!PacketLineIn.isEnd((line = pckIn.readString()))) {
+                       if (line.contains("capabilities")) {
+                               List<String> linesCapabilities = Arrays.asList(line.substring(
+                                               line.indexOf(" ", line.indexOf("capabilities")) + 1)
+                                               .split(" "));
+                               assertThat(linesCapabilities, hasItems(capabilities));
+                               return;
+                       }
+               }
+               fail("Server side protocol did not contain any capabilities'");
+       }
+
        @Test
        public void testV2CapabilitiesAllowFilter() throws Exception {
                checkAdvertisedIfAllowed("uploadpack", "allowfilter", "filter");