Page MenuHomePhabricator

D14241.id34385.diff
No OneTemporary

D14241.id34385.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -711,6 +711,7 @@
'DiffusionSSHWorkflow' => 'applications/diffusion/ssh/DiffusionSSHWorkflow.php',
'DiffusionSearchQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php',
'DiffusionServeController' => 'applications/diffusion/controller/DiffusionServeController.php',
+ 'DiffusionServeControllerTests' => 'applications/diffusion/controller/__tests__/DiffusionServeControllerTests.php',
'DiffusionSetPasswordSettingsPanel' => 'applications/diffusion/panel/DiffusionSetPasswordSettingsPanel.php',
'DiffusionSetupException' => 'applications/diffusion/exception/DiffusionSetupException.php',
'DiffusionSubversionSSHWorkflow' => 'applications/diffusion/ssh/DiffusionSubversionSSHWorkflow.php',
@@ -4434,6 +4435,7 @@
'DiffusionSSHWorkflow' => 'PhabricatorSSHWorkflow',
'DiffusionSearchQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
'DiffusionServeController' => 'DiffusionController',
+ 'DiffusionServeControllerTests' => 'PhabricatorTestCase',
'DiffusionSetPasswordSettingsPanel' => 'PhabricatorSettingsPanel',
'DiffusionSetupException' => 'Exception',
'DiffusionSubversionSSHWorkflow' => 'DiffusionSSHWorkflow',
diff --git a/src/applications/diffusion/controller/DiffusionServeController.php b/src/applications/diffusion/controller/DiffusionServeController.php
--- a/src/applications/diffusion/controller/DiffusionServeController.php
+++ b/src/applications/diffusion/controller/DiffusionServeController.php
@@ -536,11 +536,52 @@
$body = strlen($stderr)."\n".$stderr;
} else {
list($length, $body) = explode("\n", $stdout, 2);
+ if ($cmd == 'capabilities') {
+ $body = $this->removeMercurialBundle2Capability($body);
+ }
}
return id(new DiffusionMercurialResponse())->setContent($body);
}
+ /** If the server version is running 3.4+ it will respond
+ * with 'bundle2' capabilit in the format of "bundle2=(url-encoding)".
+ * Until we maange to properly package up bundles to send back we
+ * disallow the client from knowing we speak bundle2 by removing it
+ * from the capabilities listing.
+ *
+ * The format of the capabilties string is: "a space separated list
+ * of strings representing what commands the server supports"
+ * @link https://www.mercurial-scm.org/wiki/CommandServer#Protocol
+ *
+ * @param string $capabilities - The string of capabilities to
+ * strip the bundle2 capability from. This is expected to be
+ * the space-separated list of strings resulting from the
+ * querying the 'capabilties' command.
+ *
+ * @return string The resulting space-separated list of capabilities
+ * which no longer contains the 'bundle2' capability. This is meant
+ * to replace the original $body to send back to client.
+ */
+ public function removeMercurialBundle2Capability($capabilities) {
+ $bundle2_arg = 'bundle2=';
+ $bundle2_arg_len = strlen($bundle2_arg);
+ $capabilities_arr = explode(' ', $capabilities);
+ $arrindex = -1;
+ $found_bundle2 = false;
+ foreach ($capabilities_arr as $capability) {
+ $arrindex++;
+ if (substr($capability, 0, $bundle2_arg_len) == $bundle2_arg) {
+ $found_bundle2 = true;
+ break;
+ }
+ }
+ if ($found_bundle2 && $arrindex > -1) {
+ unset($capabilities_arr[$arrindex]);
+ }
+ $capabilities_without_bundle2 = implode(' ', $capabilities_arr);
+ return $capabilities_without_bundle2;
+ }
private function getMercurialArguments() {
// Mercurial sends arguments in HTTP headers. "Why?", you might wonder,
diff --git a/src/applications/diffusion/controller/__tests__/DiffusionServeControllerTests.php b/src/applications/diffusion/controller/__tests__/DiffusionServeControllerTests.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diffusion/controller/__tests__/DiffusionServeControllerTests.php
@@ -0,0 +1,28 @@
+<?php
+
+final class DiffusionServeControllerTests extends PhabricatorTestCase {
+ // this was the result of running 'capabilities' over
+ // `hg serve --stdio` on my systems with Mercurial 3.5.1, 2.6.2
+ private static $hgCapabilitiesWithBundle2_351 =
+ 'lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream bundle2=HG20%0Achangegroup%3D01%2C02%0Adigests%3Dmd5%2Csha1%2Csha512%0Aerror%3Dabort%2Cunsupportedcontent%2Cpushraced%2Cpushkey%0Ahgtagsfnodes%0Alistkeys%0Apushkey%0Aremote-changegroup%3Dhttp%2Chttps unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024';
+
+ private static $hgCapabilitiesWithoutBundle2_351 =
+ 'lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024';
+
+ private static $hgCapabilities_262 =
+ 'lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024 largefiles=serve';
+
+ public function testRemovingBundle2Capability() {
+ $controller = new DiffusionServeController();
+ $test_case = self::$hgCapabilitiesWithBundle2_351;
+ $expected = self::$hgCapabilitiesWithoutBundle2_351;
+ $actual = $controller->removeMercurialBundle2Capability($test_case);
+ $this->assertEqual($expected, $actual,
+ 'Removal of bundle2 capabilty removes from list');
+
+ $test_case = self::$hgCapabilities_262;
+ $expected = self::$hgCapabilities_262;
+ $actual = $controller->removeMercurialBundle2Capability($test_case);
+ $this->assertEqual($expected, $actual, 'Removing does not modify legacy capabilities');
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 12:43 PM (17 h, 59 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6914038
Default Alt Text
D14241.id34385.diff (5 KB)

Event Timeline