Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Tests\Unit;
use PHPUnit\Framework\TestCase;use Wotnak\Atproto\Security\OutboundUrlPolicy;
/** * Tests deterministic outbound URL policy. */final class OutboundUrlPolicyTest extends TestCase {
public function testLeavesHostnameResolutionToTransport(): void { $policy = new OutboundUrlPolicy();
static::assertTrue($policy->isAllowedHttpsUrl('https://example.invalid/path')); }
public function testRejectsUnsafeUrlStructureAndLocalHosts(): void { $policy = new OutboundUrlPolicy();
foreach ([ 'http://example.com', 'https://user@example.com', 'https://localhost', 'https://pds.local', 'https://pds.internal', ] as $url) { static::assertFalse($policy->isAllowedHttpsUrl($url), $url); } }
public function testRejectsSpecialPurposeIpLiterals(): void { $policy = new OutboundUrlPolicy(); foreach ([ '100.64.0.1', '198.18.0.1', '192.0.2.1', '198.51.100.1', '203.0.113.1', '2001:db8::1', '2002:0a00:0001::1', '64:ff9b::7f00:1', '64:ff9b::a00:1', 'fc00::1', 'fec0::1', ] as $address) { $host = \str_contains($address, ':') ? '[' . $address . ']' : $address; static::assertFalse($policy->isAllowedHttpsUrl('https://' . $host), $address); } static::assertTrue($policy->isAllowedHttpsUrl('https://93.184.216.34')); static::assertTrue($policy->isAllowedHttpsUrl('https://[64:ff9b::5db8:d822]')); static::assertTrue($policy->isAllowedHttpsUrl('https://[2606:4700:4700::1111]')); }
public function testRejectsAlternateNumericIpSyntax(): void { $policy = new OutboundUrlPolicy();
foreach ([ 'https://127.1', 'https://0177.0.0.1', 'https://0x7f.0.0.1', 'https://2130706433', ] as $url) { static::assertFalse($policy->isAllowedHttpsUrl($url), $url); } }
public function testDevelopmentHostExceptionAppliesOnlyToServiceUrls(): void { $policy = new OutboundUrlPolicy(allowedDevelopmentHosts: ['localhost']);
static::assertTrue($policy->isAllowedServiceUrl('http://localhost:2583')); static::assertFalse($policy->isAllowedHttpsUrl('https://localhost')); }
}