From b132e4eae067e74c9149f747086a1b0dc45e5e4d Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Thu, 11 Sep 2014 11:48:24 +0200 Subject: [PATCH] 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 } } } --- src/Composer/Util/Svn.php | 4 +++ tests/Composer/Test/Util/SvnTest.php | 42 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/Composer/Util/Svn.php b/src/Composer/Util/Svn.php index 4ec13297f..69aa23ebe 100644 --- a/src/Composer/Util/Svn.php +++ b/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; } diff --git a/tests/Composer/Test/Util/SvnTest.php b/tests/Composer/Test/Util/SvnTest.php index 95bc6691e..d846bcb98 100644 --- a/tests/Composer/Test/Util/SvnTest.php +++ b/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')) {