Browse Source

Removed last password/username from IOInterface

Jordi Boggiano 13 years ago
parent
commit
c754f96677

+ 4 - 24
src/Composer/IO/ConsoleIO.php

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

+ 0 - 14
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.
      *

+ 0 - 16
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}
      */

+ 0 - 4
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;

+ 0 - 26
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());
-    }
 }

+ 0 - 14
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();

+ 0 - 32
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'));