Merge pull request #4971 from e-moe/bugfix/4936-check-auth-overwrite

fix #4936: warn user about auth overwriting
main
Jordi Boggiano 8 years ago
commit fff71e5dde

@ -55,6 +55,26 @@ abstract class BaseIO implements IOInterface
$this->authentications[$repositoryName] = array('username' => $username, 'password' => $password); $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>Warning: You should avoid overwriting already defined auth settings for %s.</warning>",
$repositoryName
)
);
}
$this->setAuthentication($repositoryName, $username, $password);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -69,16 +89,16 @@ abstract class BaseIO implements IOInterface
if (!preg_match('{^[a-z0-9]+$}', $token)) { if (!preg_match('{^[a-z0-9]+$}', $token)) {
throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$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) { foreach ($gitlabOauth as $domain => $token) {
$this->setAuthentication($domain, $token, 'oauth2'); $this->checkAndSetAuthentication($domain, $token, 'oauth2');
} }
// reload http basic credentials from config if available // reload http basic credentials from config if available
foreach ($httpBasic as $domain => $cred) { foreach ($httpBasic as $domain => $cred) {
$this->setAuthentication($domain, $cred['username'], $cred['password']); $this->checkAndSetAuthentication($domain, $cred['username'], $cred['password']);
} }
// setup process timeout // setup process timeout

Loading…
Cancel
Save