瀏覽代碼

Added cacheCredentials config flag for saved SVN credentials to control the --no-auth-cache flag

Example config:

{
    "http-basic": {
        "svn.example.com": {
            "username": "user",
            "password": "password",
            "cacheCredentials": false
        }
    }
}
Bastian Hofmann 10 年之前
父節點
當前提交
b132e4eae0
共有 2 個文件被更改,包括 46 次插入0 次删除
  1. 4 0
      src/Composer/Util/Svn.php
  2. 42 0
      tests/Composer/Test/Util/SvnTest.php

+ 4 - 0
src/Composer/Util/Svn.php

@@ -295,6 +295,10 @@ class Svn
             $this->credentials['username'] = $authConfig[$host]['username'];
             $this->credentials['password'] = $authConfig[$host]['password'];
 
+            if (array_key_exists('cacheCredentials', $authConfig[$host])) {
+                $this->cacheCredentials = (bool) $authConfig[$host]['cacheCredentials'];
+            }
+
             return $this->hasAuth = true;
         }
 

+ 42 - 0
tests/Composer/Test/Util/SvnTest.php

@@ -72,6 +72,48 @@ class SvnTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
     }
 
+    public function testCredentialsFromConfigWithCacheCredentialsTrue() {
+        $url = 'http://svn.apache.org';
+
+        $config = new Config();
+        $config->merge(
+            array(
+                'config' => array(
+                    'http-basic' => array(
+                        'svn.apache.org' => array('username' => 'foo', 'password' => 'bar', 'cacheCredentials' => true)
+                    )
+                )
+            )
+        );
+
+        $svn = new Svn($url, new NullIO, $config);
+        $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
+        $reflMethod->setAccessible(true);
+
+        $this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
+    }
+
+    public function testCredentialsFromConfigWithCacheCredentialsFalse() {
+        $url = 'http://svn.apache.org';
+
+        $config = new Config();
+        $config->merge(
+            array(
+                'config' => array(
+                    'http-basic' => array(
+                        'svn.apache.org' => array('username' => 'foo', 'password' => 'bar', 'cacheCredentials' => false)
+                    )
+                )
+            )
+        );
+
+        $svn = new Svn($url, new NullIO, $config);
+        $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
+        $reflMethod->setAccessible(true);
+
+        $this->assertEquals($this->getCmd(" --no-auth-cache --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
+    }
+
     private function getCmd($cmd)
     {
         if (defined('PHP_WINDOWS_VERSION_BUILD')) {