From 957e1ccb476c0d0d75327f52d886d3a3b5433936 Mon Sep 17 00:00:00 2001 From: Nikolay Labinskiy Date: Sun, 28 Feb 2016 00:09:47 +0200 Subject: [PATCH] 4936: warn user about auth overwriting --- src/Composer/IO/BaseIO.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Composer/IO/BaseIO.php b/src/Composer/IO/BaseIO.php index ad7e32df4..f391f8968 100644 --- a/src/Composer/IO/BaseIO.php +++ b/src/Composer/IO/BaseIO.php @@ -55,6 +55,26 @@ abstract class BaseIO implements IOInterface $this->authentications[$repositoryName] = array('username' => $username, 'password' => $password); } + /** + * Check for overwrite and set the authentication information for the repository. + * + * @param string $repositoryName The unique name of repository + * @param string $username The username + * @param string $password The password + */ + protected function checkAndSetAuthentication($repositoryName, $username, $password = null) + { + if ($this->hasAuthentication($repositoryName)) { + $this->writeError( + sprintf( + "Warning: You should avoid overwriting already defined auth settings for %s.", + $repositoryName + ) + ); + } + $this->setAuthentication($repositoryName, $username, $password); + } + /** * {@inheritDoc} */ @@ -69,16 +89,16 @@ abstract class BaseIO implements IOInterface if (!preg_match('{^[a-z0-9]+$}', $token)) { throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"'); } - $this->setAuthentication($domain, $token, 'x-oauth-basic'); + $this->checkAndSetAuthentication($domain, $token, 'x-oauth-basic'); } foreach ($gitlabOauth as $domain => $token) { - $this->setAuthentication($domain, $token, 'oauth2'); + $this->checkAndSetAuthentication($domain, $token, 'oauth2'); } // reload http basic credentials from config if available foreach ($httpBasic as $domain => $cred) { - $this->setAuthentication($domain, $cred['username'], $cred['password']); + $this->checkAndSetAuthentication($domain, $cred['username'], $cred['password']); } // setup process timeout