3 final class DiffusionCommandEngineTestCase
extends PhabricatorTestCase
{
5 public function testCommandEngine() {
6 $type_git = PhabricatorRepositoryType
::REPOSITORY_TYPE_GIT
;
7 $type_hg = PhabricatorRepositoryType
::REPOSITORY_TYPE_MERCURIAL
;
8 $type_svn = PhabricatorRepositoryType
::REPOSITORY_TYPE_SVN
;
10 $root = dirname(phutil_get_library_root('phabricator'));
11 $ssh_wrapper = $root.'/bin/ssh-connect';
12 $home = $root.'/support/empty/';
17 $this->assertCommandEngineFormat(
20 'LANG' => 'en_US.UTF-8',
28 $this->assertCommandEngineFormat(
29 (string)csprintf('hg --config ui.ssh=%s xyz', $ssh_wrapper),
31 'LANG' => 'en_US.UTF-8',
39 $this->assertCommandEngineFormat(
40 'svn --non-interactive xyz',
42 'LANG' => 'en_US.UTF-8',
52 $this->assertCommandEngineFormat(
55 'LANG' => 'en_US.UTF-8',
57 'GIT_SSH' => $ssh_wrapper,
65 $this->assertCommandEngineFormat(
66 (string)csprintf('hg --config ui.ssh=%s xyz', $ssh_wrapper),
68 'LANG' => 'en_US.UTF-8',
77 $this->assertCommandEngineFormat(
78 'svn --non-interactive xyz',
80 'LANG' => 'en_US.UTF-8',
81 'SVN_SSH' => $ssh_wrapper,
90 // Commands with HTTP.
92 $this->assertCommandEngineFormat(
95 'LANG' => 'en_US.UTF-8',
101 'protocol' => 'https',
104 $this->assertCommandEngineFormat(
105 (string)csprintf('hg --config ui.ssh=%s xyz', $ssh_wrapper),
107 'LANG' => 'en_US.UTF-8',
113 'protocol' => 'https',
116 $this->assertCommandEngineFormat(
117 'svn --non-interactive --no-auth-cache --trust-server-cert xyz',
119 'LANG' => 'en_US.UTF-8',
124 'protocol' => 'https',
127 // Test that filtering defenses for "--config" and "--debugger" flag
128 // injections in Mercurial are functional. See T13012.
132 $this->assertCommandEngineFormat(
137 'argv' => '--debugger',
139 } catch (DiffusionMercurialFlagInjectionException
$ex) {
144 ($caught instanceof DiffusionMercurialFlagInjectionException
),
145 pht('Expected "--debugger" injection in Mercurial to throw.'));
150 $this->assertCommandEngineFormat(
155 'argv' => '--config=x',
157 } catch (DiffusionMercurialFlagInjectionException
$ex) {
162 ($caught instanceof DiffusionMercurialFlagInjectionException
),
163 pht('Expected "--config" injection in Mercurial to throw.'));
167 $this->assertCommandEngineFormat(
172 'argv' => (string)csprintf('%s', '--config=x'),
174 } catch (DiffusionMercurialFlagInjectionException
$ex) {
179 ($caught instanceof DiffusionMercurialFlagInjectionException
),
180 pht('Expected quoted "--config" injection in Mercurial to throw.'));
184 private function assertCommandEngineFormat(
189 $repository = id(new PhabricatorRepository())
190 ->setVersionControlSystem($inputs['vcs']);
192 $future = DiffusionCommandEngine
::newCommandEngine($repository)
193 ->setArgv((array)$inputs['argv'])
194 ->setProtocol(idx($inputs, 'protocol'))
197 $command_string = $future->getCommand();
199 $actual_command = $command_string->getUnmaskedString();
200 $this->assertEqual($command, $actual_command);
202 $actual_environment = $future->getEnv();
204 $compare_environment = array_select_keys(
208 $this->assertEqual($env, $compare_environment);