2018-01-05 14:20:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\Util;
|
|
|
|
|
|
|
|
use Composer\Util\Url;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2018-01-05 14:20:30 +00:00
|
|
|
use Composer\Config;
|
|
|
|
|
|
|
|
class UrlTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider distRefsProvider
|
2021-10-27 14:18:46 +00:00
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
* @param string $expectedUrl
|
|
|
|
* @param array<string, mixed> $conf
|
|
|
|
* @param string $ref
|
2018-01-05 14:20:30 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testUpdateDistReference(string $url, string $expectedUrl, array $conf = array(), string $ref = 'newref'): void
|
2018-01-05 14:20:30 +00:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
$config->merge(array('config' => $conf));
|
|
|
|
|
2018-01-09 15:48:15 +00:00
|
|
|
$this->assertSame($expectedUrl, Url::updateDistReference($config, $url, $ref));
|
2018-01-05 14:20:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 12:42:28 +00:00
|
|
|
public static function distRefsProvider(): array
|
2018-01-05 14:20:30 +00:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
// github
|
|
|
|
array('https://github.com/foo/bar/zipball/abcd', 'https://api.github.com/repos/foo/bar/zipball/newref'),
|
|
|
|
array('https://www.github.com/foo/bar/zipball/abcd', 'https://api.github.com/repos/foo/bar/zipball/newref'),
|
|
|
|
array('https://github.com/foo/bar/archive/abcd.zip', 'https://api.github.com/repos/foo/bar/zipball/newref'),
|
|
|
|
array('https://github.com/foo/bar/archive/abcd.tar.gz', 'https://api.github.com/repos/foo/bar/tarball/newref'),
|
|
|
|
array('https://api.github.com/repos/foo/bar/tarball', 'https://api.github.com/repos/foo/bar/tarball/newref'),
|
|
|
|
array('https://api.github.com/repos/foo/bar/tarball/abcd', 'https://api.github.com/repos/foo/bar/tarball/newref'),
|
|
|
|
|
|
|
|
// github enterprise
|
|
|
|
array('https://mygithub.com/api/v3/repos/foo/bar/tarball/abcd', 'https://mygithub.com/api/v3/repos/foo/bar/tarball/newref', array('github-domains' => array('mygithub.com'))),
|
|
|
|
|
|
|
|
// bitbucket
|
|
|
|
array('https://bitbucket.org/foo/bar/get/abcd.zip', 'https://bitbucket.org/foo/bar/get/newref.zip'),
|
|
|
|
array('https://www.bitbucket.org/foo/bar/get/abcd.tar.bz2', 'https://bitbucket.org/foo/bar/get/newref.tar.bz2'),
|
|
|
|
|
|
|
|
// gitlab
|
|
|
|
array('https://gitlab.com/api/v4/projects/foo%2Fbar/repository/archive.zip?sha=abcd', 'https://gitlab.com/api/v4/projects/foo%2Fbar/repository/archive.zip?sha=newref'),
|
|
|
|
array('https://www.gitlab.com/api/v4/projects/foo%2Fbar/repository/archive.zip?sha=abcd', 'https://gitlab.com/api/v4/projects/foo%2Fbar/repository/archive.zip?sha=newref'),
|
|
|
|
array('https://gitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.gz?sha=abcd', 'https://gitlab.com/api/v4/projects/foo%2Fbar/repository/archive.tar.gz?sha=newref'),
|
|
|
|
|
|
|
|
// gitlab enterprise
|
|
|
|
array('https://mygitlab.com/api/v4/projects/foo%2Fbar/repository/archive.tar.gz?sha=abcd', 'https://mygitlab.com/api/v4/projects/foo%2Fbar/repository/archive.tar.gz?sha=newref', array('gitlab-domains' => array('mygitlab.com'))),
|
|
|
|
array('https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=abcd', 'https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=newref', array('gitlab-domains' => array('mygitlab.com'))),
|
2018-07-24 12:32:52 +00:00
|
|
|
array('https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=abcd', 'https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=65', array('gitlab-domains' => array('mygitlab.com')), '65'),
|
2018-01-05 14:20:30 +00:00
|
|
|
);
|
|
|
|
}
|
2020-01-30 14:50:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider sanitizeProvider
|
2021-10-27 14:18:46 +00:00
|
|
|
*
|
|
|
|
* @param string $expected
|
|
|
|
* @param string $url
|
2020-01-30 14:50:46 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testSanitize(string $expected, string $url): void
|
2020-01-30 14:50:46 +00:00
|
|
|
{
|
|
|
|
$this->assertSame($expected, Url::sanitize($url));
|
|
|
|
}
|
|
|
|
|
2022-02-21 12:42:28 +00:00
|
|
|
public static function sanitizeProvider(): array
|
2020-01-30 14:50:46 +00:00
|
|
|
{
|
|
|
|
return array(
|
2020-10-23 11:27:46 +00:00
|
|
|
// with scheme
|
2020-01-30 14:50:46 +00:00
|
|
|
array('https://foo:***@example.org/', 'https://foo:bar@example.org/'),
|
|
|
|
array('https://foo@example.org/', 'https://foo@example.org/'),
|
|
|
|
array('https://example.org/', 'https://example.org/'),
|
|
|
|
array('http://***:***@example.org', 'http://10a8f08e8d7b7b9:foo@example.org'),
|
|
|
|
array('https://foo:***@example.org:123/', 'https://foo:bar@example.org:123/'),
|
|
|
|
array('https://example.org/foo/bar?access_token=***', 'https://example.org/foo/bar?access_token=abcdef'),
|
|
|
|
array('https://example.org/foo/bar?foo=bar&access_token=***', 'https://example.org/foo/bar?foo=bar&access_token=abcdef'),
|
2021-08-11 11:24:41 +00:00
|
|
|
array('https://***:***@github.com/acme/repo', 'https://ghp_1234567890abcdefghijklmnopqrstuvwxyzAB:x-oauth-basic@github.com/acme/repo'),
|
2020-10-23 11:27:46 +00:00
|
|
|
// without scheme
|
|
|
|
array('foo:***@example.org/', 'foo:bar@example.org/'),
|
|
|
|
array('foo@example.org/', 'foo@example.org/'),
|
|
|
|
array('example.org/', 'example.org/'),
|
|
|
|
array('***:***@example.org', '10a8f08e8d7b7b9:foo@example.org'),
|
|
|
|
array('foo:***@example.org:123/', 'foo:bar@example.org:123/'),
|
|
|
|
array('example.org/foo/bar?access_token=***', 'example.org/foo/bar?access_token=abcdef'),
|
|
|
|
array('example.org/foo/bar?foo=bar&access_token=***', 'example.org/foo/bar?foo=bar&access_token=abcdef'),
|
2020-01-30 14:50:46 +00:00
|
|
|
);
|
|
|
|
}
|
2018-01-05 14:20:30 +00:00
|
|
|
}
|