1
0
Fork 0

Removed last password/username from IOInterface

pull/659/head
Jordi Boggiano 2012-05-06 17:17:36 +02:00
parent 6967ec16b3
commit c754f96677
7 changed files with 4 additions and 130 deletions

View File

@ -22,6 +22,7 @@ use Symfony\Component\Console\Helper\HelperSet;
* The Input/Output helper.
*
* @author François Pluchino <francois.pluchino@opendisplay.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
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);
}
}

View File

@ -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.
*

View File

@ -89,22 +89,6 @@ class NullIO implements IOInterface
return null;
}
/**
* {@inheritDoc}
*/
public function getLastUsername()
{
return null;
}
/**
* {@inheritDoc}
*/
public function getLastPassword()
{
return null;
}
/**
* {@inheritDoc}
*/

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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();

View File

@ -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'));