Path: blob/master/src/applications/diffusion/request/__tests__/DiffusionURITestCase.php
13401 views
<?php12final class DiffusionURITestCase extends PhutilTestCase {34public function testBlobDecode() {5$map = array(6// This is a basic blob.7'branch/path.ext;abc$3' => array(8'branch' => 'branch',9'path' => 'path.ext',10'commit' => 'abc',11'line' => '3',12),13'branch/path.ext$3' => array(14'branch' => 'branch',15'path' => 'path.ext',16'line' => '3',17),18'branch/money;;/$$100' => array(19'branch' => 'branch',20'path' => 'money;/$100',21),22'a%252Fb/' => array(23'branch' => 'a/b',24),25'branch/path/;Version-1_0_0' => array(26'branch' => 'branch',27'path' => 'path/',28'commit' => 'Version-1_0_0',29),30'branch/path/;$$moneytag$$' => array(31'branch' => 'branch',32'path' => 'path/',33'commit' => '$moneytag$',34),35'branch/path/semicolon;;;;;$$;;semicolon;;$$$$$100' => array(36'branch' => 'branch',37'path' => 'path/semicolon;;',38'commit' => '$;;semicolon;;$$',39'line' => '100',40),41'branch/path.ext;abc$3-5,7-12,14' => array(42'branch' => 'branch',43'path' => 'path.ext',44'commit' => 'abc',45'line' => '3-5,7-12,14',46),47);4849foreach ($map as $input => $expect) {5051// Simulate decode effect of the webserver.52$input = rawurldecode($input);5354$expect = $expect + array(55'branch' => null,56'path' => null,57'commit' => null,58'line' => null,59);60$expect = array_select_keys(61$expect,62array('branch', 'path', 'commit', 'line'));6364$actual = $this->parseBlob($input);6566$this->assertEqual(67$expect,68$actual,69pht("Parsing '%s'", $input));70}71}7273public function testBlobDecodeFail() {74$this->tryTestCaseMap(75array(76'branch/path/../../../secrets/secrets.key' => false,77),78array($this, 'parseBlob'));79}8081public function parseBlob($blob) {82return DiffusionRequest::parseRequestBlob(83$blob,84$supports_branches = true);85}8687public function testURIGeneration() {88$actor = PhabricatorUser::getOmnipotentUser();8990$repository = PhabricatorRepository::initializeNewRepository($actor)91->setCallsign('A')92->makeEphemeral();9394$map = array(95'/diffusion/A/browse/branch/path.ext;abc$1' => array(96'action' => 'browse',97'branch' => 'branch',98'path' => 'path.ext',99'commit' => 'abc',100'line' => '1',101),102'/diffusion/A/browse/a%252Fb/path.ext' => array(103'action' => 'browse',104'branch' => 'a/b',105'path' => 'path.ext',106),107'/diffusion/A/browse/%2B/%20%21' => array(108'action' => 'browse',109'path' => '+/ !',110),111'/diffusion/A/browse/money/%24%24100$2' => array(112'action' => 'browse',113'path' => 'money/$100',114'line' => '2',115),116'/diffusion/A/browse/path/to/file.ext?view=things' => array(117'action' => 'browse',118'path' => 'path/to/file.ext',119'params' => array(120'view' => 'things',121),122),123'/diffusion/A/repository/master/' => array(124'action' => 'branch',125'branch' => 'master',126),127'path/to/file.ext;abc' => array(128'action' => 'rendering-ref',129'path' => 'path/to/file.ext',130'commit' => 'abc',131),132'/diffusion/A/browse/branch/path.ext$3-5%2C7-12%2C14' => array(133'action' => 'browse',134'branch' => 'branch',135'path' => 'path.ext',136'line' => '3-5,7-12,14',137),138);139140foreach ($map as $expect => $input) {141$actual = $repository->generateURI($input);142$this->assertEqual($expect, (string)$actual);143}144}145146}147148149