2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2015-10-13 09:34:02 +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.
|
|
|
|
*/
|
|
|
|
|
2012-03-22 16:16:41 +00:00
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
2014-05-30 15:14:43 +00:00
|
|
|
use Composer\Config;
|
2012-03-22 16:16:41 +00:00
|
|
|
use Composer\IO\NullIO;
|
|
|
|
use Composer\Util\Svn;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2012-03-22 16:16:41 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class SvnTest extends TestCase
|
2012-03-22 16:16:41 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test the credential string.
|
|
|
|
*
|
|
|
|
* @param string $url The SVN url.
|
2024-11-06 12:49:06 +00:00
|
|
|
* @param non-empty-list<string> $expect The expectation for the test.
|
2012-03-22 16:16:41 +00:00
|
|
|
*
|
|
|
|
* @dataProvider urlProvider
|
|
|
|
*/
|
2024-11-06 12:49:06 +00:00
|
|
|
public function testCredentials(string $url, array $expect): void
|
2012-03-22 16:16:41 +00:00
|
|
|
{
|
2014-05-30 15:14:43 +00:00
|
|
|
$svn = new Svn($url, new NullIO, new Config());
|
2024-11-06 12:49:06 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialArgs');
|
2013-02-20 15:50:26 +00:00
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expect, $reflMethod->invoke($svn));
|
2013-02-20 15:50:26 +00:00
|
|
|
}
|
2012-03-22 16:16:41 +00:00
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function urlProvider(): array
|
2013-02-20 15:50:26 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
2024-11-06 12:49:06 +00:00
|
|
|
['http://till:test@svn.example.org/', ['--username', 'till', '--password', 'test']],
|
|
|
|
['http://svn.apache.org/', []],
|
|
|
|
['svn://johndoe@example.org', ['--username', 'johndoe', '--password', '']],
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2012-03-22 16:16:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInteractiveString(): void
|
2012-03-22 16:16:41 +00:00
|
|
|
{
|
|
|
|
$url = 'http://svn.example.org';
|
|
|
|
|
2014-05-30 15:14:43 +00:00
|
|
|
$svn = new Svn($url, new NullIO(), new Config());
|
2013-02-20 15:50:26 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCommand');
|
|
|
|
$reflMethod->setAccessible(true);
|
2012-03-22 16:16:41 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals(
|
2024-11-06 12:49:06 +00:00
|
|
|
['svn', 'ls', '--non-interactive', '--', 'http://svn.example.org'],
|
|
|
|
$reflMethod->invokeArgs($svn, [['svn', 'ls'], $url])
|
2012-03-22 16:16:41 +00:00
|
|
|
);
|
|
|
|
}
|
2013-02-20 15:50:26 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCredentialsFromConfig(): void
|
2014-05-30 15:14:43 +00:00
|
|
|
{
|
|
|
|
$url = 'http://svn.apache.org';
|
|
|
|
|
|
|
|
$config = new Config();
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge([
|
|
|
|
'config' => [
|
|
|
|
'http-basic' => [
|
|
|
|
'svn.apache.org' => ['username' => 'foo', 'password' => 'bar'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
2014-05-30 15:14:43 +00:00
|
|
|
|
|
|
|
$svn = new Svn($url, new NullIO, $config);
|
2024-11-06 12:49:06 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialArgs');
|
2014-05-30 15:14:43 +00:00
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
2024-11-06 12:49:06 +00:00
|
|
|
self::assertEquals(['--username', 'foo', '--password', 'bar'], $reflMethod->invoke($svn));
|
2014-05-30 15:14:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCredentialsFromConfigWithCacheCredentialsTrue(): void
|
2014-09-15 11:21:33 +00:00
|
|
|
{
|
2014-09-11 09:48:24 +00:00
|
|
|
$url = 'http://svn.apache.org';
|
|
|
|
|
|
|
|
$config = new Config();
|
|
|
|
$config->merge(
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
|
|
|
'config' => [
|
|
|
|
'http-basic' => [
|
|
|
|
'svn.apache.org' => ['username' => 'foo', 'password' => 'bar'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]
|
2014-09-11 09:48:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$svn = new Svn($url, new NullIO, $config);
|
2014-09-16 13:16:55 +00:00
|
|
|
$svn->setCacheCredentials(true);
|
2024-11-06 12:49:06 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialArgs');
|
2014-09-11 09:48:24 +00:00
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
2024-11-06 12:49:06 +00:00
|
|
|
self::assertEquals(['--username', 'foo', '--password', 'bar'], $reflMethod->invoke($svn));
|
2014-09-11 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCredentialsFromConfigWithCacheCredentialsFalse(): void
|
2014-09-15 11:21:33 +00:00
|
|
|
{
|
2014-09-11 09:48:24 +00:00
|
|
|
$url = 'http://svn.apache.org';
|
|
|
|
|
|
|
|
$config = new Config();
|
|
|
|
$config->merge(
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
|
|
|
'config' => [
|
|
|
|
'http-basic' => [
|
|
|
|
'svn.apache.org' => ['username' => 'foo', 'password' => 'bar'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]
|
2014-09-11 09:48:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$svn = new Svn($url, new NullIO, $config);
|
2014-09-16 13:16:55 +00:00
|
|
|
$svn->setCacheCredentials(false);
|
2024-11-06 12:49:06 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialArgs');
|
2014-09-11 09:48:24 +00:00
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
2024-11-06 12:49:06 +00:00
|
|
|
self::assertEquals(['--no-auth-cache', '--username', 'foo', '--password', 'bar'], $reflMethod->invoke($svn));
|
2014-09-11 09:48:24 +00:00
|
|
|
}
|
2012-06-14 10:10:01 +00:00
|
|
|
}
|