From b132e4eae067e74c9149f747086a1b0dc45e5e4d Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Thu, 11 Sep 2014 11:48:24 +0200 Subject: [PATCH 1/5] 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')) { From 0d0ed59e5ce07857557924efd14d8ce2d996d3f4 Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Mon, 15 Sep 2014 13:21:33 +0200 Subject: [PATCH 2/5] Codestyle fix --- tests/Composer/Test/Util/SvnTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Composer/Test/Util/SvnTest.php b/tests/Composer/Test/Util/SvnTest.php index d846bcb98..9ee5d1271 100644 --- a/tests/Composer/Test/Util/SvnTest.php +++ b/tests/Composer/Test/Util/SvnTest.php @@ -72,7 +72,8 @@ class SvnTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn)); } - public function testCredentialsFromConfigWithCacheCredentialsTrue() { + public function testCredentialsFromConfigWithCacheCredentialsTrue() + { $url = 'http://svn.apache.org'; $config = new Config(); @@ -93,7 +94,8 @@ class SvnTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn)); } - public function testCredentialsFromConfigWithCacheCredentialsFalse() { + public function testCredentialsFromConfigWithCacheCredentialsFalse() + { $url = 'http://svn.apache.org'; $config = new Config(); From 204fc207faa0fddf9e69a6e958242a266d02540b Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Tue, 16 Sep 2014 15:16:55 +0200 Subject: [PATCH 3/5] Moved config option to not save subversion credentials to repository configuration, added documentation. --- doc/05-repositories.md | 33 ++++++++++++++++++++++- src/Composer/Repository/Vcs/SvnDriver.php | 9 +++++++ src/Composer/Util/Svn.php | 12 ++++++--- tests/Composer/Test/Util/SvnTest.php | 6 +++-- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/doc/05-repositories.md b/doc/05-repositories.md index 049a05170..1e6128f0e 100644 --- a/doc/05-repositories.md +++ b/doc/05-repositories.md @@ -345,6 +345,37 @@ If the package is in a sub-directory, e.g. `/trunk/foo/bar/composer.json` and setting the `"package-path"` option to the sub-directory, in this example it would be `"package-path": "foo/bar/"`. +If you have a private Subversion repository you can safe credentials in the +http-basic section of your config (See [Schema](04-schema.md)): + +```json +{ + "http-basic": { + "svn.example.org": { + "username": "username", + "password": "password" + } + } +} +``` + +If your Subversion client is configured to store credentials by default these +credentials will be saved for the current user and existing saved credentials +for this server will be overwritten. To change this behavior by setting the +`"cache-credentials"` option in your repository configuration: + +```json +{ + "repositories": [ + { + "type": "vcs", + "url": "http://svn.example.org/projectA/", + "cache-credentials": false + } + ] +} +``` + ### PEAR It is possible to install packages from any PEAR channel by using the `pear` @@ -494,7 +525,7 @@ there are some use cases for hosting your own repository. might want to keep them separate to packagist. An example of this would be wordpress plugins. -For hosting your own packages, a native `composer` type of repository is +For hosting your own packages, a native `composer` type of repository is recommended, which provides the best performance. There are a few tools that can help you create a `composer` repository. diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index 2bddbe15d..f2a9e1de0 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -27,6 +27,10 @@ use Composer\Downloader\TransportException; */ class SvnDriver extends VcsDriver { + + /** + * @var Cache + */ protected $cache; protected $baseUrl; protected $tags; @@ -38,6 +42,7 @@ class SvnDriver extends VcsDriver protected $branchesPath = 'branches'; protected $tagsPath = 'tags'; protected $packagePath = ''; + protected $cacheCredentials = true; /** * @var \Composer\Util\Svn @@ -62,6 +67,9 @@ class SvnDriver extends VcsDriver if (isset($this->repoConfig['tags-path'])) { $this->tagsPath = $this->repoConfig['tags-path']; } + if (array_key_exists('cache-credentials', $this->repoConfig)) { + $this->cacheCredentials = (bool) $this->repoConfig['cache-credentials']; + } if (isset($this->repoConfig['package-path'])) { $this->packagePath = '/' . trim($this->repoConfig['package-path'], '/'); } @@ -307,6 +315,7 @@ class SvnDriver extends VcsDriver { if (null === $this->util) { $this->util = new SvnUtil($this->baseUrl, $this->io, $this->config, $this->process); + $this->util->setCacheCredentials($this->cacheCredentials); } try { diff --git a/src/Composer/Util/Svn.php b/src/Composer/Util/Svn.php index 69aa23ebe..6d659a7f1 100644 --- a/src/Composer/Util/Svn.php +++ b/src/Composer/Util/Svn.php @@ -147,6 +147,14 @@ class Svn ); } + /** + * @param boolean $cacheCredentials + */ + public function setCacheCredentials($cacheCredentials) + { + $this->cacheCredentials = $cacheCredentials; + } + /** * Repositories requests credentials, let's put them in. * @@ -295,10 +303,6 @@ 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 9ee5d1271..b1f19ca1a 100644 --- a/tests/Composer/Test/Util/SvnTest.php +++ b/tests/Composer/Test/Util/SvnTest.php @@ -81,13 +81,14 @@ class SvnTest extends \PHPUnit_Framework_TestCase array( 'config' => array( 'http-basic' => array( - 'svn.apache.org' => array('username' => 'foo', 'password' => 'bar', 'cacheCredentials' => true) + 'svn.apache.org' => array('username' => 'foo', 'password' => 'bar') ) ) ) ); $svn = new Svn($url, new NullIO, $config); + $svn->setCacheCredentials(true); $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString'); $reflMethod->setAccessible(true); @@ -103,13 +104,14 @@ class SvnTest extends \PHPUnit_Framework_TestCase array( 'config' => array( 'http-basic' => array( - 'svn.apache.org' => array('username' => 'foo', 'password' => 'bar', 'cacheCredentials' => false) + 'svn.apache.org' => array('username' => 'foo', 'password' => 'bar') ) ) ) ); $svn = new Svn($url, new NullIO, $config); + $svn->setCacheCredentials(false); $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString'); $reflMethod->setAccessible(true); From f8023cffdf7f23a12eeefef73ff7a77f476c0bdc Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Wed, 24 Sep 2014 13:24:54 +0200 Subject: [PATCH 4/5] renamed cache-credentials to svn-cache-credentials --- doc/05-repositories.md | 4 ++-- src/Composer/Repository/Vcs/SvnDriver.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/05-repositories.md b/doc/05-repositories.md index 1e6128f0e..318ea65bb 100644 --- a/doc/05-repositories.md +++ b/doc/05-repositories.md @@ -362,7 +362,7 @@ http-basic section of your config (See [Schema](04-schema.md)): If your Subversion client is configured to store credentials by default these credentials will be saved for the current user and existing saved credentials for this server will be overwritten. To change this behavior by setting the -`"cache-credentials"` option in your repository configuration: +`"svn-cache-credentials"` option in your repository configuration: ```json { @@ -370,7 +370,7 @@ for this server will be overwritten. To change this behavior by setting the { "type": "vcs", "url": "http://svn.example.org/projectA/", - "cache-credentials": false + "svn-cache-credentials": false } ] } diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index f2a9e1de0..729bda94e 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -67,8 +67,8 @@ class SvnDriver extends VcsDriver if (isset($this->repoConfig['tags-path'])) { $this->tagsPath = $this->repoConfig['tags-path']; } - if (array_key_exists('cache-credentials', $this->repoConfig)) { - $this->cacheCredentials = (bool) $this->repoConfig['cache-credentials']; + if (array_key_exists('svn-cache-credentials', $this->repoConfig)) { + $this->cacheCredentials = (bool) $this->repoConfig['svn-cache-credentials']; } if (isset($this->repoConfig['package-path'])) { $this->packagePath = '/' . trim($this->repoConfig['package-path'], '/'); From 2612dc7c15ae6ec2bb678577516c5b567d653a5a Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Wed, 24 Sep 2014 15:30:48 +0200 Subject: [PATCH 5/5] fixed typo --- doc/05-repositories.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/05-repositories.md b/doc/05-repositories.md index 318ea65bb..975b473e5 100644 --- a/doc/05-repositories.md +++ b/doc/05-repositories.md @@ -345,7 +345,7 @@ If the package is in a sub-directory, e.g. `/trunk/foo/bar/composer.json` and setting the `"package-path"` option to the sub-directory, in this example it would be `"package-path": "foo/bar/"`. -If you have a private Subversion repository you can safe credentials in the +If you have a private Subversion repository you can save credentials in the http-basic section of your config (See [Schema](04-schema.md)): ```json