1
0
Fork 0

Merge pull request #5723 from alcohol/user-password-mask-patch

User password masking patch
pull/5733/head
Jordi Boggiano 2016-09-27 15:56:47 +02:00 committed by GitHub
commit d7f821434d
2 changed files with 10 additions and 4 deletions

View File

@ -44,12 +44,12 @@ class ProcessExecutor
public function execute($command, &$output = null, $cwd = null) public function execute($command, &$output = null, $cwd = null)
{ {
if ($this->io && $this->io->isDebug()) { if ($this->io && $this->io->isDebug()) {
$safeCommand = preg_replace_callback('{(://)(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)}i', function ($m) { $safeCommand = preg_replace_callback('{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i', function ($m) {
if (preg_match('{^[a-f0-9]{12,}$}', $m['user'])) { if (preg_match('{^[a-f0-9]{12,}$}', $m['user'])) {
return '://***:***'; return '://***:***@';
} }
return '://'.$m['user'].':***'; return '://'.$m['user'].':***@';
}, $command); }, $command);
$this->io->writeError('Executing command ('.($cwd ?: 'CWD').'): '.$safeCommand); $this->io->writeError('Executing command ('.($cwd ?: 'CWD').'): '.$safeCommand);
} }

View File

@ -54,10 +54,16 @@ class ProcessExecutorTest extends TestCase
{ {
$process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG)); $process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG));
$process->execute('echo https://foo:bar@example.org/ && echo http://foo@example.org && echo http://abcdef1234567890234578:x-oauth-token@github.com/', $output); $process->execute('echo https://foo:bar@example.org/ && echo http://foo@example.org && echo http://abcdef1234567890234578:x-oauth-token@github.com/', $output);
$this->assertEquals('Executing command (CWD): echo https://foo:***@example.org/ && echo http://foo@example.org && echo http://***:***@github.com/', trim($buffer->getOutput())); $this->assertEquals('Executing command (CWD): echo https://foo:***@example.org/ && echo http://foo@example.org && echo http://***:***@github.com/', trim($buffer->getOutput()));
} }
public function testDoesntHidePorts()
{
$process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG));
$process->execute('echo https://localhost:1234/', $output);
$this->assertEquals('Executing command (CWD): echo https://localhost:1234/', trim($buffer->getOutput()));
}
public function testSplitLines() public function testSplitLines()
{ {
$process = new ProcessExecutor; $process = new ProcessExecutor;