diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 95aed6a29..0865fab29 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -22,6 +22,7 @@ use Symfony\Component\Console\Helper\HelperSet; * The Input/Output helper. * * @author François Pluchino + * @author Jordi Boggiano */ class ConsoleIO implements IOInterface { @@ -29,8 +30,6 @@ class ConsoleIO implements IOInterface protected $output; protected $helperSet; protected $authorizations = array(); - protected $lastUsername; - protected $lastPassword; protected $lastMessage; /** @@ -179,22 +178,6 @@ class ConsoleIO implements IOInterface return $this->ask($question); } - /** - * {@inheritDoc} - */ - public function getLastUsername() - { - return $this->lastUsername; - } - - /** - * {@inheritDoc} - */ - public function getLastPassword() - { - return $this->lastPassword; - } - /** * {@inheritDoc} */ @@ -209,6 +192,7 @@ class ConsoleIO implements IOInterface public function hasAuthorization($repositoryName) { $auths = $this->getAuthorizations(); + return isset($auths[$repositoryName]); } @@ -218,6 +202,7 @@ class ConsoleIO implements IOInterface public function getAuthorization($repositoryName) { $auths = $this->getAuthorizations(); + return isset($auths[$repositoryName]) ? $auths[$repositoryName] : array('username' => null, 'password' => null); } @@ -226,11 +211,6 @@ class ConsoleIO implements IOInterface */ public function setAuthorization($repositoryName, $username, $password = null) { - $auths = $this->getAuthorizations(); - $auths[$repositoryName] = array('username' => $username, 'password' => $password); - - $this->authorizations = $auths; - $this->lastUsername = $username; - $this->lastPassword = $password; + $this->authorizations[$repositoryName] = array('username' => $username, 'password' => $password); } } diff --git a/src/Composer/IO/IOInterface.php b/src/Composer/IO/IOInterface.php index 583800424..79e0d7e8e 100644 --- a/src/Composer/IO/IOInterface.php +++ b/src/Composer/IO/IOInterface.php @@ -108,20 +108,6 @@ interface IOInterface */ function askAndHideAnswer($question); - /** - * Get the last username entered. - * - * @return string The username - */ - function getLastUsername(); - - /** - * Get the last password entered. - * - * @return string The password - */ - function getLastPassword(); - /** * Get all authorization informations entered. * diff --git a/src/Composer/IO/NullIO.php b/src/Composer/IO/NullIO.php index 78688f6d5..b5ee190b3 100644 --- a/src/Composer/IO/NullIO.php +++ b/src/Composer/IO/NullIO.php @@ -89,22 +89,6 @@ class NullIO implements IOInterface return null; } - /** - * {@inheritDoc} - */ - public function getLastUsername() - { - return null; - } - - /** - * {@inheritDoc} - */ - public function getLastPassword() - { - return null; - } - /** * {@inheritDoc} */ diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index f6cfa67da..695e765f3 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -223,10 +223,6 @@ class RemoteFilesystem $auth = $this->io->getAuthorization($originUrl); $authStr = base64_encode($auth['username'] . ':' . $auth['password']); $options['http']['header'] .= "Authorization: Basic $authStr\r\n"; - } elseif (null !== $this->io->getLastUsername()) { - $authStr = base64_encode($this->io->getLastUsername() . ':' . $this->io->getLastPassword()); - $options['http']['header'] .= "Authorization: Basic $authStr\r\n"; - $this->io->setAuthorization($originUrl, $this->io->getLastUsername(), $this->io->getLastPassword()); } return $options; diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index 73f0faedb..f3ea6b15d 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -190,30 +190,4 @@ class ConsoleIOTest extends TestCase $this->assertTrue($consoleIO->hasAuthorization('repoName')); $this->assertFalse($consoleIO->hasAuthorization('repoName2')); } - - public function testGetLastUsername() - { - $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); - $consoleIO->setAuthorization('repoName', 'l3l0', 'passwd'); - $consoleIO->setAuthorization('repoName2', 'l3l02', 'passwd2'); - - $this->assertEquals('l3l02', $consoleIO->getLastUsername()); - } - - public function testGetLastPassword() - { - $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); - $consoleIO->setAuthorization('repoName', 'l3l0', 'passwd'); - $consoleIO->setAuthorization('repoName2', 'l3l02', 'passwd2'); - - $this->assertEquals('passwd2', $consoleIO->getLastPassword()); - } } diff --git a/tests/Composer/Test/IO/NullIOTest.php b/tests/Composer/Test/IO/NullIOTest.php index 854f27862..e0e07dd76 100644 --- a/tests/Composer/Test/IO/NullIOTest.php +++ b/tests/Composer/Test/IO/NullIOTest.php @@ -31,20 +31,6 @@ class NullIOTest extends TestCase $this->assertFalse($io->hasAuthorization('foo')); } - public function testGetLastPassword() - { - $io = new NullIO(); - - $this->assertNull($io->getLastPassword()); - } - - public function testGetLastUsername() - { - $io = new NullIO(); - - $this->assertNull($io->getLastUsername()); - } - public function testAskAndHideAnswer() { $io = new NullIO(); diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index 6fdb565eb..93e42153d 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -25,11 +25,6 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase ->method('hasAuthorization') ->will($this->returnValue(false)) ; - $io - ->expects($this->once()) - ->method('getLastUsername') - ->will($this->returnValue(null)) - ; $res = $this->callGetOptionsForUrl($io, array('http://example.org')); $this->assertTrue(isset($res['http']['header']) && false !== strpos($res['http']['header'], 'User-Agent'), 'getOptions must return an array with a header containing a User-Agent'); @@ -53,33 +48,6 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase $this->assertContains('Authorization: Basic', $options['http']['header']); } - public function testGetOptionsForUrlWithLastUsername() - { - $io = $this->getMock('Composer\IO\IOInterface'); - $io - ->expects($this->once()) - ->method('hasAuthorization') - ->will($this->returnValue(false)) - ; - $io - ->expects($this->any()) - ->method('getLastUsername') - ->will($this->returnValue('login')) - ; - $io - ->expects($this->any()) - ->method('getLastPassword') - ->will($this->returnValue('password')) - ; - $io - ->expects($this->once()) - ->method('setAuthorization') - ; - - $options = $this->callGetOptionsForUrl($io, array('http://example.org')); - $this->assertContains('Authorization: Basic', $options['http']['header']); - } - public function testCallbackGetFileSize() { $fs = new RemoteFilesystem($this->getMock('Composer\IO\IOInterface'));