From 1aa31caec571722644590cfd1a3f5e535970dda2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 May 2016 00:28:45 +0100 Subject: [PATCH 1/2] Clean up ApplicationTest --- tests/Composer/Test/ApplicationTest.php | 33 ++++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/Composer/Test/ApplicationTest.php b/tests/Composer/Test/ApplicationTest.php index b977b78e0..deb763c62 100644 --- a/tests/Composer/Test/ApplicationTest.php +++ b/tests/Composer/Test/ApplicationTest.php @@ -25,15 +25,21 @@ class ApplicationTest extends TestCase $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $inputMock->expects($this->any()) - ->method('hasParameterOption') - ->with($this->equalTo('--no-plugins')) - ->will($this->returnValue(true)); + $index = 0; + $inputMock->expects($this->at($index++)) + ->method('getParameterOption') + ->with($this->equalTo(array('--working-dir', '-d'))) + ->will($this->returnValue(false)); - $inputMock->expects($this->any()) + $inputMock->expects($this->at($index++)) ->method('getFirstArgument') ->will($this->returnValue('list')); + $inputMock->expects($this->at($index++)) + ->method('hasParameterOption') + ->with($this->equalTo('--no-plugins')) + ->will($this->returnValue(true)); + $index = 0; $outputMock->expects($this->at($index++)) ->method("writeError"); @@ -60,7 +66,6 @@ class ApplicationTest extends TestCase define('COMPOSER_DEV_WARNING_TIME', time() - 1); } - $this->setExpectedException('RuntimeException'); $application->doRun($inputMock, $outputMock); } @@ -73,9 +78,20 @@ class ApplicationTest extends TestCase $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $inputMock->expects($this->any()) + $index = 0; + $inputMock->expects($this->at($index++)) + ->method('getParameterOption') + ->with($this->equalTo(array('--working-dir', '-d'))) + ->will($this->returnValue(false)); + + $inputMock->expects($this->at($index++)) ->method('getFirstArgument') - ->will($this->returnValue($command)); + ->will($this->returnValue('list')); + + $inputMock->expects($this->at($index++)) + ->method('hasParameterOption') + ->with($this->equalTo('--no-plugins')) + ->will($this->returnValue(true)); $outputMock->expects($this->never()) ->method("writeln"); @@ -84,7 +100,6 @@ class ApplicationTest extends TestCase define('COMPOSER_DEV_WARNING_TIME', time() - 1); } - $this->setExpectedException('RuntimeException'); $application->doRun($inputMock, $outputMock); } From e3ae45fa12e1791888f22af6ae1693a51c63918c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 8 May 2016 17:22:25 +0100 Subject: [PATCH 2/2] Replace username as well if it looks like a github oauth token --- src/Composer/Util/Git.php | 8 +++++++- src/Composer/Util/ProcessExecutor.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index 54abcb1b8..51e1b0a5a 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -251,7 +251,13 @@ class Git public static function sanitizeUrl($message) { - return preg_replace('{://([^@]+?):.+?@}', '://$1:***@', $message); + return preg_replace_callback('{://(?P[^@]+?):(?P.+?)@}', function ($m) { + if (preg_match('{^[a-f0-9]{12,}$}', $m[1])) { + return '://***:***@'; + } + + return '://'.$m[1].':***@'; + }, $message); } private function throwException($message, $url) diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index 6b778e5eb..adad1c3fc 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -44,7 +44,13 @@ class ProcessExecutor public function execute($command, &$output = null, $cwd = null) { if ($this->io && $this->io->isDebug()) { - $safeCommand = preg_replace('{(://[^:/\s]+:)[^@\s/]+}i', '$1****', $command); + $safeCommand = preg_replace('{(://)(?P[^:/\s]+):(?P[^@\s/]+)}i', function ($m) { + if (preg_match('{^[a-f0-9]{12,}$}', $m[1])) { + return '://***:***'; + } + + return '://'.$m[1].':***'; + }, $command); $this->io->writeError('Executing command ('.($cwd ?: 'CWD').'): '.$safeCommand); }