浏览代码

Merge pull request #2008 from phansys/svn-auth

Allowed to 5 auth requests in svn before fail
Jordi Boggiano 12 年之前
父节点
当前提交
ca69917969
共有 2 个文件被更改,包括 11 次插入7 次删除
  1. 9 5
      src/Composer/Util/Svn.php
  2. 2 2
      tests/Composer/Test/Repository/Vcs/SvnDriverTest.php

+ 9 - 5
src/Composer/Util/Svn.php

@@ -20,6 +20,8 @@ use Composer\IO\IOInterface;
  */
 class Svn
 {
+    const MAX_QTY_AUTH_TRIES = 5;
+
     /**
      * @var array
      */
@@ -50,6 +52,11 @@ class Svn
      */
     protected $process;
 
+    /**
+     * @var integer
+     */
+    protected $qtyAuthTries = 0;
+
     /**
      * @param string                   $url
      * @param \Composer\IO\IOInterface $io
@@ -112,11 +119,8 @@ class Svn
             );
         }
 
-        // TODO keep a count of user auth attempts and ask 5 times before
-        // failing hard (currently it fails hard directly if the URL has credentials)
-
-        // try to authenticate
-        if (!$this->hasAuth()) {
+        // try to authenticate if maximum quantity of tries not reached
+        if ($this->qtyAuthTries++ < self::MAX_QTY_AUTH_TRIES || !$this->hasAuth()) {
             $this->doAuthDance();
 
             // restart the process

+ 2 - 2
tests/Composer/Test/Repository/Vcs/SvnDriverTest.php

@@ -23,7 +23,7 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase
     public function testWrongCredentialsInUrl()
     {
         $console = $this->getMock('Composer\IO\IOInterface');
-        $console->expects($this->once())
+        $console->expects($this->exactly(6))
             ->method('isInteractive')
             ->will($this->returnValue(true));
 
@@ -35,7 +35,7 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase
         $process->expects($this->at(1))
             ->method('execute')
             ->will($this->returnValue(1));
-        $process->expects($this->once())
+        $process->expects($this->exactly(7))
             ->method('getErrorOutput')
             ->will($this->returnValue($output));
         $process->expects($this->at(2))