File: ProxyItemTest.php

package info (click to toggle)
composer 2.8.8-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,716 kB
  • sloc: php: 77,384; makefile: 59; xml: 39
file content (69 lines) | stat: -rw-r--r-- 2,280 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php declare(strict_types=1);

/*
 * 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\ProxyItem;
use Composer\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class ProxyItemTest extends TestCase
{
    #[DataProvider('dataMalformed')]
    public function testThrowsOnMalformedUrl(string $url): void
    {
        self::expectException('RuntimeException');
        $proxyItem = new ProxyItem($url, 'http_proxy');
    }

    /**
     * @return array<string, array<string>>
     */
    public static function dataMalformed(): array
    {
        return [
            'ws-r' => ["http://user\rname@localhost:80"],
            'ws-n' => ["http://user\nname@localhost:80"],
            'ws-t' => ["http://user\tname@localhost:80"],
            'no-host' => ['localhost'],
            'no-port' => ['scheme://localhost'],
            'port-0' => ['http://localhost:0'],
            'port-big' => ['http://localhost:65536'],
        ];
    }

    #[DataProvider('dataFormatting')]
    public function testUrlFormatting(string $url, string $expected): void
    {
        $proxyItem = new ProxyItem($url, 'http_proxy');
        $proxy = $proxyItem->toRequestProxy('http');

        self::assertSame($expected, $proxy->getStatus());
    }

    /**
     * @return array<string, array<string>>
     */
    public static function dataFormatting(): array
    {
        // url, expected
        return [
            'none' => ['http://proxy.com:8888', 'http://proxy.com:8888'],
            'lowercases-scheme' => ['HTTP://proxy.com:8888', 'http://proxy.com:8888'],
            'adds-http-scheme' => ['proxy.com:80', 'http://proxy.com:80'],
            'adds-http-port' => ['http://proxy.com', 'http://proxy.com:80'],
            'adds-https-port' => ['https://proxy.com', 'https://proxy.com:443'],
            'removes-user' => ['http://user@proxy.com:6180', 'http://***@proxy.com:6180'],
            'removes-user-pass' => ['http://user:p%40ss@proxy.com:6180', 'http://***:***@proxy.com:6180'],
        ];
    }
}