2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2012-06-24 11:03:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test;
|
|
|
|
|
2024-02-07 21:13:36 +00:00
|
|
|
use Composer\Advisory\Auditor;
|
2012-06-24 11:03:55 +00:00
|
|
|
use Composer\Config;
|
2022-04-13 10:21:08 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2022-02-08 13:54:46 +00:00
|
|
|
use Composer\Util\Platform;
|
2012-06-24 11:03:55 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class ConfigTest extends TestCase
|
2012-06-24 11:03:55 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider dataAddPackagistRepository
|
2021-11-02 13:32:09 +00:00
|
|
|
* @param mixed[] $expected
|
|
|
|
* @param mixed[] $localConfig
|
2022-02-22 15:47:09 +00:00
|
|
|
* @param ?array<mixed> $systemConfig
|
2012-06-24 11:03:55 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testAddPackagistRepository(array $expected, array $localConfig, ?array $systemConfig = null): void
|
2012-06-24 11:03:55 +00:00
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2012-06-24 11:03:55 +00:00
|
|
|
if ($systemConfig) {
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['repositories' => $systemConfig]);
|
2012-06-24 11:03:55 +00:00
|
|
|
}
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['repositories' => $localConfig]);
|
2012-06-24 11:03:55 +00:00
|
|
|
|
|
|
|
$this->assertEquals($expected, $config->getRepositories());
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function dataAddPackagistRepository(): array
|
2012-06-24 11:03:55 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$data = [];
|
|
|
|
$data['local config inherits system defaults'] = [
|
|
|
|
[
|
|
|
|
'packagist.org' => ['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
];
|
2012-06-24 11:03:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['local config can disable system config by name'] = [
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
['packagist.org' => false],
|
|
|
|
],
|
|
|
|
];
|
2016-11-03 10:30:35 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['local config can disable system config by name bc'] = [
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
['packagist' => false],
|
|
|
|
],
|
|
|
|
];
|
2012-06-24 11:03:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['local config adds above defaults'] = [
|
|
|
|
[
|
|
|
|
1 => ['type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'],
|
|
|
|
0 => ['type' => 'pear', 'url' => 'http://pear.composer.org'],
|
|
|
|
'packagist.org' => ['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'],
|
|
|
|
['type' => 'pear', 'url' => 'http://pear.composer.org'],
|
|
|
|
],
|
|
|
|
];
|
2012-06-24 11:03:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['system config adds above core defaults'] = [
|
|
|
|
[
|
|
|
|
'example.com' => ['type' => 'composer', 'url' => 'http://example.com'],
|
|
|
|
'packagist.org' => ['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'example.com' => ['type' => 'composer', 'url' => 'http://example.com'],
|
|
|
|
],
|
|
|
|
];
|
2012-06-24 11:03:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['local config can disable repos by name and re-add them anonymously to bring them above system config'] = [
|
|
|
|
[
|
|
|
|
0 => ['type' => 'composer', 'url' => 'http://packagist.org'],
|
|
|
|
'example.com' => ['type' => 'composer', 'url' => 'http://example.com'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['packagist.org' => false],
|
|
|
|
['type' => 'composer', 'url' => 'http://packagist.org'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'example.com' => ['type' => 'composer', 'url' => 'http://example.com'],
|
|
|
|
],
|
|
|
|
];
|
2012-06-24 11:03:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['local config can override by name to bring a repo above system config'] = [
|
|
|
|
[
|
|
|
|
'packagist.org' => ['type' => 'composer', 'url' => 'http://packagistnew.org'],
|
|
|
|
'example.com' => ['type' => 'composer', 'url' => 'http://example.com'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'packagist.org' => ['type' => 'composer', 'url' => 'http://packagistnew.org'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'example.com' => ['type' => 'composer', 'url' => 'http://example.com'],
|
|
|
|
],
|
|
|
|
];
|
2012-06-24 11:03:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['local config redefining packagist.org by URL override it if no named keys are used'] = [
|
|
|
|
[
|
|
|
|
['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
|
|
|
],
|
|
|
|
];
|
2021-02-11 10:13:58 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['local config redefining packagist.org by URL override it also with named keys'] = [
|
|
|
|
[
|
|
|
|
'example' => ['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'example' => ['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
|
|
|
],
|
|
|
|
];
|
2021-02-11 10:13:58 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$data['incorrect local config does not cause ErrorException'] = [
|
|
|
|
[
|
|
|
|
'packagist.org' => ['type' => 'composer', 'url' => 'https://repo.packagist.org'],
|
2015-01-20 10:03:55 +00:00
|
|
|
'type' => 'vcs',
|
|
|
|
'url' => 'http://example.com',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2015-01-20 10:03:55 +00:00
|
|
|
'type' => 'vcs',
|
|
|
|
'url' => 'http://example.com',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
];
|
2015-01-20 10:03:55 +00:00
|
|
|
|
2012-06-24 11:03:55 +00:00
|
|
|
return $data;
|
|
|
|
}
|
2012-12-08 20:45:21 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPreferredInstallAsString(): void
|
2015-04-18 22:25:59 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['preferred-install' => 'source']]);
|
|
|
|
$config->merge(['config' => ['preferred-install' => 'dist']]);
|
2015-04-18 22:25:59 +00:00
|
|
|
|
2015-04-18 22:31:16 +00:00
|
|
|
$this->assertEquals('dist', $config->get('preferred-install'));
|
2015-04-18 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testMergePreferredInstall(): void
|
2015-04-18 22:25:59 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['preferred-install' => 'dist']]);
|
|
|
|
$config->merge(['config' => ['preferred-install' => ['foo/*' => 'source']]]);
|
2015-04-18 22:25:59 +00:00
|
|
|
|
|
|
|
// This assertion needs to make sure full wildcard preferences are placed last
|
|
|
|
// Handled by composer because we convert string preferences for BC, all other
|
|
|
|
// care for ordering and collision prevention is up to the user
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals(['foo/*' => 'source', '*' => 'dist'], $config->get('preferred-install'));
|
2015-04-18 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testMergeGithubOauth(): void
|
2012-12-08 20:45:21 +00:00
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['github-oauth' => ['foo' => 'bar']]]);
|
|
|
|
$config->merge(['config' => ['github-oauth' => ['bar' => 'baz']]]);
|
2012-12-08 20:45:21 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals(['foo' => 'bar', 'bar' => 'baz'], $config->get('github-oauth'));
|
2012-12-08 20:45:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testVarReplacement(): void
|
2014-06-29 12:47:43 +00:00
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['a' => 'b', 'c' => '{$a}']]);
|
|
|
|
$config->merge(['config' => ['bin-dir' => '$HOME', 'cache-dir' => '~/foo/']]);
|
2014-06-29 12:47:43 +00:00
|
|
|
|
2014-09-30 14:17:53 +00:00
|
|
|
$home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '\\/');
|
2014-06-29 12:47:43 +00:00
|
|
|
$this->assertEquals('b', $config->get('c'));
|
2016-04-13 00:02:50 +00:00
|
|
|
$this->assertEquals($home, $config->get('bin-dir'));
|
2014-06-29 12:47:43 +00:00
|
|
|
$this->assertEquals($home.'/foo', $config->get('cache-dir'));
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRealpathReplacement(): void
|
2014-12-16 11:12:13 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false, '/foo/bar');
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => [
|
2014-12-16 11:12:13 +00:00
|
|
|
'bin-dir' => '$HOME/foo',
|
|
|
|
'cache-dir' => '/baz/',
|
2015-09-28 09:51:14 +00:00
|
|
|
'vendor-dir' => 'vendor',
|
2022-08-17 12:20:07 +00:00
|
|
|
]]);
|
2014-12-16 11:12:13 +00:00
|
|
|
|
|
|
|
$home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '\\/');
|
|
|
|
$this->assertEquals('/foo/bar/vendor', $config->get('vendor-dir'));
|
|
|
|
$this->assertEquals($home.'/foo', $config->get('bin-dir'));
|
|
|
|
$this->assertEquals('/baz', $config->get('cache-dir'));
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testStreamWrapperDirs(): void
|
2016-01-25 23:40:16 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false, '/foo/bar');
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => [
|
2016-01-25 23:40:16 +00:00
|
|
|
'cache-dir' => 's3://baz/',
|
2022-08-17 12:20:07 +00:00
|
|
|
]]);
|
2016-01-25 23:40:16 +00:00
|
|
|
|
|
|
|
$this->assertEquals('s3://baz', $config->get('cache-dir'));
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testFetchingRelativePaths(): void
|
2014-12-17 21:57:27 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false, '/foo/bar');
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => [
|
2014-12-17 21:57:27 +00:00
|
|
|
'bin-dir' => '{$vendor-dir}/foo',
|
2015-09-28 09:51:14 +00:00
|
|
|
'vendor-dir' => 'vendor',
|
2022-08-17 12:20:07 +00:00
|
|
|
]]);
|
2014-12-17 21:57:27 +00:00
|
|
|
|
|
|
|
$this->assertEquals('/foo/bar/vendor', $config->get('vendor-dir'));
|
|
|
|
$this->assertEquals('/foo/bar/vendor/foo', $config->get('bin-dir'));
|
|
|
|
$this->assertEquals('vendor', $config->get('vendor-dir', Config::RELATIVE_PATHS));
|
|
|
|
$this->assertEquals('vendor/foo', $config->get('bin-dir', Config::RELATIVE_PATHS));
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testOverrideGithubProtocols(): void
|
2012-12-08 20:45:21 +00:00
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['github-protocols' => ['https', 'ssh']]]);
|
|
|
|
$config->merge(['config' => ['github-protocols' => ['https']]]);
|
2012-12-08 20:45:21 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals(['https'], $config->get('github-protocols'));
|
2012-12-08 20:45:21 +00:00
|
|
|
}
|
2014-02-23 10:20:48 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGitDisabledByDefaultInGithubProtocols(): void
|
2016-03-01 13:19:44 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['github-protocols' => ['https', 'git']]]);
|
|
|
|
$this->assertEquals(['https'], $config->get('github-protocols'));
|
2016-03-01 13:19:44 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['secure-http' => false]]);
|
|
|
|
$this->assertEquals(['https', 'git'], $config->get('github-protocols'));
|
2016-03-01 13:19:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 23:19:52 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider allowedUrlProvider
|
2020-02-07 06:35:07 +00:00
|
|
|
* @doesNotPerformAssertions
|
2016-03-09 23:19:52 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testAllowedUrlsPass(string $url): void
|
2016-03-09 23:19:52 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false);
|
|
|
|
$config->prohibitUrlByConfig($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider prohibitedUrlProvider
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testProhibitedUrlsThrowException(string $url): void
|
2016-03-09 23:19:52 +00:00
|
|
|
{
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('Composer\Downloader\TransportException');
|
|
|
|
self::expectExceptionMessage('Your configuration does not allow connections to ' . $url);
|
2016-03-09 23:19:52 +00:00
|
|
|
$config = new Config(false);
|
|
|
|
$config->prohibitUrlByConfig($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-02 13:32:09 +00:00
|
|
|
* @return string[][] List of test URLs that should pass strict security
|
2016-03-09 23:19:52 +00:00
|
|
|
*/
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function allowedUrlProvider(): array
|
2016-03-09 23:19:52 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$urls = [
|
2016-03-09 23:19:52 +00:00
|
|
|
'https://packagist.org',
|
|
|
|
'git@github.com:composer/composer.git',
|
|
|
|
'hg://user:pass@my.satis/satis',
|
|
|
|
'\\myserver\myplace.git',
|
|
|
|
'file://myserver.localhost/mygit.git',
|
|
|
|
'file://example.org/mygit.git',
|
2016-04-15 22:13:07 +00:00
|
|
|
'git:Department/Repo.git',
|
|
|
|
'ssh://[user@]host.xz[:port]/path/to/repo.git/',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2016-04-11 14:06:57 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
return array_combine($urls, array_map(static function ($e): array {
|
|
|
|
return [$e];
|
2017-03-08 14:07:29 +00:00
|
|
|
}, $urls));
|
2016-03-09 23:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-02 13:32:09 +00:00
|
|
|
* @return string[][] List of test URLs that should not pass strict security
|
2016-03-09 23:19:52 +00:00
|
|
|
*/
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function prohibitedUrlProvider(): array
|
2016-03-09 23:19:52 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$urls = [
|
2016-03-09 23:19:52 +00:00
|
|
|
'http://packagist.org',
|
|
|
|
'http://10.1.0.1/satis',
|
|
|
|
'http://127.0.0.1/satis',
|
|
|
|
'svn://localhost/trunk',
|
|
|
|
'svn://will.not.resolve/trunk',
|
|
|
|
'svn://192.168.0.1/trunk',
|
|
|
|
'svn://1.2.3.4/trunk',
|
|
|
|
'git://5.6.7.8/git.git',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2016-04-11 14:06:57 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
return array_combine($urls, array_map(static function ($e): array {
|
|
|
|
return [$e];
|
2017-03-08 14:07:29 +00:00
|
|
|
}, $urls));
|
2016-03-09 23:19:52 +00:00
|
|
|
}
|
2016-04-11 14:06:57 +00:00
|
|
|
|
2022-04-13 10:21:08 +00:00
|
|
|
public function testProhibitedUrlsWarningVerifyPeer(): void
|
|
|
|
{
|
2023-06-07 12:35:16 +00:00
|
|
|
$io = $this->getIOMock();
|
2022-04-13 10:21:08 +00:00
|
|
|
|
2023-06-07 12:35:16 +00:00
|
|
|
$io->expects([['text' => '<warning>Warning: Accessing example.org with verify_peer and verify_peer_name disabled.</warning>']], true);
|
2022-04-13 10:21:08 +00:00
|
|
|
|
|
|
|
$config = new Config(false);
|
|
|
|
$config->prohibitUrlByConfig('https://example.org', $io, [
|
|
|
|
'ssl' => [
|
|
|
|
'verify_peer' => false,
|
|
|
|
'verify_peer_name' => false,
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2022-04-13 10:21:08 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2014-02-23 10:20:48 +00:00
|
|
|
/**
|
|
|
|
* @group TLS
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testDisableTlsCanBeOverridden(): void
|
2014-02-23 10:20:48 +00:00
|
|
|
{
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(
|
2022-08-17 12:20:07 +00:00
|
|
|
['config' => ['disable-tls' => 'false']]
|
2014-02-23 10:20:48 +00:00
|
|
|
);
|
|
|
|
$this->assertFalse($config->get('disable-tls'));
|
|
|
|
$config->merge(
|
2022-08-17 12:20:07 +00:00
|
|
|
['config' => ['disable-tls' => 'true']]
|
2014-02-23 10:20:48 +00:00
|
|
|
);
|
|
|
|
$this->assertTrue($config->get('disable-tls'));
|
|
|
|
}
|
2016-09-21 01:13:22 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testProcessTimeout(): void
|
2016-09-21 01:13:22 +00:00
|
|
|
{
|
2022-02-08 13:54:46 +00:00
|
|
|
Platform::putEnv('COMPOSER_PROCESS_TIMEOUT', '0');
|
2016-09-21 01:13:22 +00:00
|
|
|
$config = new Config(true);
|
2022-02-15 15:42:50 +00:00
|
|
|
$result = $config->get('process-timeout');
|
2022-02-08 13:54:46 +00:00
|
|
|
Platform::clearEnv('COMPOSER_PROCESS_TIMEOUT');
|
2022-02-15 15:42:50 +00:00
|
|
|
|
|
|
|
$this->assertEquals(0, $result);
|
2016-09-21 01:13:22 +00:00
|
|
|
}
|
2017-06-15 15:06:13 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testHtaccessProtect(): void
|
2017-06-15 15:06:13 +00:00
|
|
|
{
|
2022-02-08 13:54:46 +00:00
|
|
|
Platform::putEnv('COMPOSER_HTACCESS_PROTECT', '0');
|
2017-06-15 15:06:13 +00:00
|
|
|
$config = new Config(true);
|
2022-02-15 15:42:50 +00:00
|
|
|
$result = $config->get('htaccess-protect');
|
2022-02-08 13:54:46 +00:00
|
|
|
Platform::clearEnv('COMPOSER_HTACCESS_PROTECT');
|
2022-02-15 15:42:50 +00:00
|
|
|
|
|
|
|
$this->assertEquals(0, $result);
|
2017-06-15 15:06:13 +00:00
|
|
|
}
|
2021-11-11 14:17:58 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetSourceOfValue(): void
|
2021-11-11 14:17:58 +00:00
|
|
|
{
|
2022-02-08 13:54:46 +00:00
|
|
|
Platform::clearEnv('COMPOSER_PROCESS_TIMEOUT');
|
|
|
|
|
2021-11-11 14:17:58 +00:00
|
|
|
$config = new Config;
|
|
|
|
|
|
|
|
$this->assertSame(Config::SOURCE_DEFAULT, $config->getSourceOfValue('process-timeout'));
|
|
|
|
|
|
|
|
$config->merge(
|
2022-08-17 12:20:07 +00:00
|
|
|
['config' => ['process-timeout' => 1]],
|
2021-11-11 14:17:58 +00:00
|
|
|
'phpunit-test'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame('phpunit-test', $config->getSourceOfValue('process-timeout'));
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetSourceOfValueEnvVariables(): void
|
2021-11-11 14:17:58 +00:00
|
|
|
{
|
2022-02-08 13:54:46 +00:00
|
|
|
Platform::putEnv('COMPOSER_HTACCESS_PROTECT', '0');
|
2021-11-11 14:17:58 +00:00
|
|
|
$config = new Config;
|
2022-02-15 15:42:50 +00:00
|
|
|
$result = $config->getSourceOfValue('htaccess-protect');
|
2022-02-08 13:54:46 +00:00
|
|
|
Platform::clearEnv('COMPOSER_HTACCESS_PROTECT');
|
2022-02-15 15:42:50 +00:00
|
|
|
|
|
|
|
$this->assertEquals('COMPOSER_HTACCESS_PROTECT', $result);
|
2021-11-11 14:17:58 +00:00
|
|
|
}
|
2022-06-03 05:43:37 +00:00
|
|
|
|
2024-02-07 21:13:36 +00:00
|
|
|
public function testAudit(): void
|
|
|
|
{
|
|
|
|
$config = new Config(true);
|
|
|
|
$result = $config->get('audit');
|
|
|
|
self::assertArrayHasKey('abandoned', $result);
|
|
|
|
self::assertArrayHasKey('ignore', $result);
|
|
|
|
self::assertSame(Auditor::ABANDONED_FAIL, $result['abandoned']);
|
|
|
|
self::assertSame([], $result['ignore']);
|
|
|
|
|
|
|
|
Platform::putEnv('COMPOSER_AUDIT_ABANDONED', Auditor::ABANDONED_IGNORE);
|
|
|
|
$result = $config->get('audit');
|
|
|
|
Platform::clearEnv('COMPOSER_AUDIT_ABANDONED');
|
|
|
|
self::assertArrayHasKey('abandoned', $result);
|
|
|
|
self::assertArrayHasKey('ignore', $result);
|
|
|
|
self::assertSame(Auditor::ABANDONED_IGNORE, $result['abandoned']);
|
|
|
|
self::assertSame([], $result['ignore']);
|
|
|
|
|
|
|
|
$config->merge(['config' => ['audit' => ['ignore' => ['A', 'B']]]]);
|
|
|
|
$config->merge(['config' => ['audit' => ['ignore' => ['A', 'C']]]]);
|
|
|
|
$result = $config->get('audit');
|
|
|
|
self::assertArrayHasKey('ignore', $result);
|
|
|
|
self::assertSame(['A', 'B', 'A', 'C'], $result['ignore']);
|
|
|
|
}
|
|
|
|
|
2022-06-03 05:43:37 +00:00
|
|
|
public function testGetDefaultsToAnEmptyArray(): void
|
|
|
|
{
|
|
|
|
$config = new Config;
|
|
|
|
$keys = [
|
|
|
|
'bitbucket-oauth',
|
|
|
|
'github-oauth',
|
|
|
|
'gitlab-oauth',
|
|
|
|
'gitlab-token',
|
|
|
|
'http-basic',
|
|
|
|
'bearer',
|
|
|
|
];
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$value = $config->get($key);
|
2023-02-10 13:00:33 +00:00
|
|
|
$this->assertIsArray($value); // @phpstan-ignore-line - PHPStan knows that its an array for all given keys
|
2022-06-03 05:43:37 +00:00
|
|
|
$this->assertCount(0, $value);
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 10:05:18 +00:00
|
|
|
|
2022-07-01 10:24:54 +00:00
|
|
|
public function testMergesPluginConfig(): void
|
2022-07-01 09:08:35 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['allow-plugins' => ['some/plugin' => true]]]);
|
|
|
|
$this->assertEquals(['some/plugin' => true], $config->get('allow-plugins'));
|
2022-07-01 09:08:35 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['allow-plugins' => ['another/plugin' => true]]]);
|
|
|
|
$this->assertEquals(['some/plugin' => true, 'another/plugin' => true], $config->get('allow-plugins'));
|
2022-07-01 09:08:35 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 10:24:54 +00:00
|
|
|
public function testOverridesGlobalBooleanPluginsConfig(): void
|
2022-07-01 09:08:35 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['allow-plugins' => true]]);
|
2022-07-01 09:08:35 +00:00
|
|
|
$this->assertEquals(true, $config->get('allow-plugins'));
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['allow-plugins' => ['another/plugin' => true]]]);
|
|
|
|
$this->assertEquals(['another/plugin' => true], $config->get('allow-plugins'));
|
2022-07-01 09:08:35 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 10:24:54 +00:00
|
|
|
public function testAllowsAllPluginsFromLocalBoolean(): void
|
2022-07-01 09:08:35 +00:00
|
|
|
{
|
|
|
|
$config = new Config(false);
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['allow-plugins' => ['some/plugin' => true]]]);
|
|
|
|
$this->assertEquals(['some/plugin' => true], $config->get('allow-plugins'));
|
2022-07-01 09:08:35 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['allow-plugins' => true]]);
|
2022-07-01 09:08:35 +00:00
|
|
|
$this->assertEquals(true, $config->get('allow-plugins'));
|
|
|
|
}
|
2012-06-24 11:03:55 +00:00
|
|
|
}
|