Browse Source

Merge pull request #3909 from frederikbosch/auth-fix-mirror

Fix #3903
Jordi Boggiano 10 years ago
parent
commit
213d4803ac
1 changed files with 16 additions and 2 deletions
  1. 16 2
      src/Composer/Util/Git.php

+ 16 - 2
src/Composer/Util/Git.php

@@ -106,8 +106,7 @@ class Git
                     }
                 }
             } elseif ( // private non-github repo that failed to authenticate
-                preg_match('{(https?://)([^/]+)(.*)$}i', $url, $match) &&
-                strpos($this->process->getErrorOutput(), 'fatal: Authentication failed') !== false
+                $this->isAuthenticationFailure($url, $match)
             ) {
                 if (strpos($match[2], '@')) {
                     list($authParts, $match[2]) = explode('@', $match[2], 2);
@@ -155,6 +154,21 @@ class Git
         }
     }
 
+    private function isAuthenticationFailure ($url, &$match) {
+        if (!preg_match('{(https?://)([^/]+)(.*)$}i', $url, $match)) {
+            return false;
+        }
+
+        $authFailures = array('fatal: Authentication failed', 'remote error: Invalid username or password.');
+        foreach ($authFailures as $authFailure) {
+            if (strpos($this->process->getErrorOutput(), $authFailure) !== false) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     public static function cleanEnv()
     {
         if (ini_get('safe_mode') && false === strpos(ini_get('safe_mode_allowed_env_vars'), 'GIT_ASKPASS')) {