2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2020-09-24 15:48:22 +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\Util\Http;
|
|
|
|
|
|
|
|
use Composer\Util\Http\RequestProxy;
|
|
|
|
use Composer\Test\TestCase;
|
|
|
|
|
|
|
|
class RequestProxyTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider dataSecure
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testIsSecure(string $url, bool $expectedSecure): void
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$proxy = new RequestProxy($url, [], '');
|
2020-09-24 15:48:22 +00:00
|
|
|
|
|
|
|
$this->assertSame($expectedSecure, $proxy->isSecure());
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function dataSecure(): array
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
|
|
|
// url, secure
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
'basic' => ['http://proxy.com:80', false],
|
|
|
|
'secure' => ['https://proxy.com:443', true],
|
|
|
|
'none' => ['', false],
|
|
|
|
];
|
2020-09-24 15:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-24 08:36:39 +00:00
|
|
|
* @dataProvider dataProxyUrl
|
2020-09-24 15:48:22 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testGetFormattedUrlFormat(string $url, string $format, string $expected): void
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$proxy = new RequestProxy($url, [], $url);
|
2020-09-24 15:48:22 +00:00
|
|
|
|
2020-10-24 08:36:39 +00:00
|
|
|
$message = $proxy->getFormattedUrl($format);
|
2020-09-24 15:48:22 +00:00
|
|
|
$this->assertSame($expected, $message);
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function dataProxyUrl(): array
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
|
|
|
$format = 'proxy (%s)';
|
|
|
|
|
|
|
|
// url, format, expected
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['', $format, ''],
|
|
|
|
['http://proxy.com:80', $format, 'proxy (http://proxy.com:80)'],
|
|
|
|
];
|
2020-09-24 15:48:22 +00:00
|
|
|
}
|
|
|
|
}
|