From d1ce9f6246f797b4c65f47e4c156fdb064b9f8b0 Mon Sep 17 00:00:00 2001 From: Arnout Boks Date: Wed, 30 Jan 2019 14:18:06 +0100 Subject: [PATCH 1/3] Fix defaultRepos fallback does not use auth config When a full 'composer' cannot be constructed (because there is no local composer.json and no global composer.json), some commands (e.g. `show -a`) fall back to the default repositories from the `$COMPOSER_HOME/config.json` file. Without this fix, any auth configuration from `$COMPOSER_HOME/auth.json` is not used for these repositories in such a fallback scenario. Steps to reproduce: * Configure a password-protected composer repository in `$COMPOSER_HOME/config.json`. * Configure valid credentials for that repository in `$COMPOSER_HOME/auth.json`. * Make sure there is no file `$COMPOSER_HOME/composer.json`. * Ensure the current working directory has no `composer.json`. * Run `composer show -a some/package`. Expected: Information about `some/package` is shown without needing to enter credentials. Actual: A prompt "Authentication required" is shown for the private repository. When running the same command in a dir that has a `composer.json`, or when `$COMPOSER_HOME/composer.json` exists, things work as expected. --- src/Composer/Repository/RepositoryFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index ca479a7fd..3c7e837c3 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -93,6 +93,7 @@ class RepositoryFactory { if (!$config) { $config = Factory::createConfig($io); + $io->loadConfiguration($config); } if (!$rm) { if (!$io) { From e151a6c51c08e638d271c64b5384cbbd5ecc6333 Mon Sep 17 00:00:00 2001 From: Arnout Boks Date: Thu, 31 Jan 2019 09:37:28 +0100 Subject: [PATCH 2/3] Only load configuration into IO if IO is available --- src/Composer/Repository/RepositoryFactory.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index 3c7e837c3..d8e917147 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -93,7 +93,9 @@ class RepositoryFactory { if (!$config) { $config = Factory::createConfig($io); - $io->loadConfiguration($config); + if ($io) { + $io->loadConfiguration($config); + } } if (!$rm) { if (!$io) { From 82b010782d1c1a3553862621d4eae83e31cdb3d1 Mon Sep 17 00:00:00 2001 From: Arnout Boks Date: Thu, 31 Jan 2019 13:38:20 +0100 Subject: [PATCH 3/3] Also load config into IO if not freshly created --- src/Composer/Repository/RepositoryFactory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index d8e917147..5d3a2a61f 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -93,9 +93,9 @@ class RepositoryFactory { if (!$config) { $config = Factory::createConfig($io); - if ($io) { - $io->loadConfiguration($config); - } + } + if ($io) { + $io->loadConfiguration($config); } if (!$rm) { if (!$io) {