2020-09-24 15:48:22 +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\Http;
|
|
|
|
|
|
|
|
use Composer\Util\Http\RequestProxy;
|
|
|
|
use Composer\Test\TestCase;
|
|
|
|
|
|
|
|
class RequestProxyTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider dataSecure
|
2021-10-27 14:18:46 +00:00
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
* @param bool $expectedSecure
|
2020-09-24 15:48:22 +00:00
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testIsSecure($url, $expectedSecure): void
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
|
|
|
$proxy = new RequestProxy($url, array(), '');
|
|
|
|
|
|
|
|
$this->assertSame($expectedSecure, $proxy->isSecure());
|
|
|
|
}
|
|
|
|
|
2022-02-21 12:42:28 +00:00
|
|
|
public function dataSecure(): array
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
|
|
|
// url, secure
|
|
|
|
return array(
|
2020-11-22 13:48:56 +00:00
|
|
|
'basic' => array('http://proxy.com:80', false),
|
|
|
|
'secure' => array('https://proxy.com:443', true),
|
|
|
|
'none' => array('', false),
|
2020-09-24 15:48:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-24 08:36:39 +00:00
|
|
|
* @dataProvider dataProxyUrl
|
2021-10-27 14:18:46 +00:00
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
* @param string $format
|
|
|
|
* @param string $expected
|
2020-09-24 15:48:22 +00:00
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetFormattedUrlFormat($url, $format, $expected): void
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
|
|
|
$proxy = new RequestProxy($url, array(), $url);
|
|
|
|
|
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-02-21 12:42:28 +00:00
|
|
|
public function dataProxyUrl(): array
|
2020-09-24 15:48:22 +00:00
|
|
|
{
|
|
|
|
$format = 'proxy (%s)';
|
|
|
|
|
|
|
|
// url, format, expected
|
|
|
|
return array(
|
|
|
|
array('', $format, ''),
|
|
|
|
array('http://proxy.com:80', $format, 'proxy (http://proxy.com:80)'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|