Add visitor-IP header setting, checkout-button toggles, and configurable timer maximum
Test and Release / test (push) Successful in 1m13s
Test and Release / release (push) Successful in 5s

- Core\ClientIp: trusted-header resolution for rate limiting behind Cloudflare/proxies
- Settings: show/hide Pay Later and Debit/Credit Card (Pay Later off by default)
- add_time rule: optional max_timer_seconds (uncapped by default), editable in rule form

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 11:40:06 -08:00
1 parent 4f92cfdade
commit e4d9042aba
14 files changed
+278 -16

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Tests\Unit;
use PHPUnit\Framework\TestCase;
use StreamGoals\Core\ClientIp;
final class ClientIpTest extends TestCase {
private const PROXY = '172.70.1.1';
private const CLIENT = '203.0.113.9';
public function test_direct_mode_uses_remote_addr_and_ignores_headers(): void {
$srv = array( 'REMOTE_ADDR' => self::CLIENT, 'HTTP_CF_CONNECTING_IP' => '1.2.3.4', 'HTTP_X_FORWARDED_FOR' => '5.6.7.8' );
$this->assertSame( self::CLIENT, ClientIp::resolve( $srv, ClientIp::MODE_DIRECT ) );
$this->assertSame( self::CLIENT, ClientIp::resolve( $srv ) );
}
public function test_cloudflare_mode_uses_cf_header(): void {
$srv = array( 'REMOTE_ADDR' => self::PROXY, 'HTTP_CF_CONNECTING_IP' => self::CLIENT );
$this->assertSame( self::CLIENT, ClientIp::resolve( $srv, ClientIp::MODE_CLOUDFLARE ) );
}
public function test_cloudflare_mode_without_header_falls_back_to_remote_addr(): void {
$this->assertSame( self::PROXY, ClientIp::resolve( array( 'REMOTE_ADDR' => self::PROXY ), ClientIp::MODE_CLOUDFLARE ) );
}
public function test_invalid_header_values_are_ignored(): void {
foreach ( array( 'not-an-ip', '999.1.1.1', '', '1.2.3.4, 5.6.7.8', '<script>', "1.2.3.4\r\nX: y" ) as $bad ) {
$srv = array( 'REMOTE_ADDR' => self::PROXY, 'HTTP_CF_CONNECTING_IP' => $bad );
$this->assertSame( self::PROXY, ClientIp::resolve( $srv, ClientIp::MODE_CLOUDFLARE ), "accepted bad value: $bad" );
}
}
public function test_x_real_ip_mode(): void {
$this->assertSame( self::CLIENT, ClientIp::resolve( array( 'REMOTE_ADDR' => self::PROXY, 'HTTP_X_REAL_IP' => self::CLIENT ), ClientIp::MODE_REAL_IP ) );
}
public function test_forwarded_mode_takes_the_last_entry_not_the_spoofable_first(): void {
$srv = array( 'REMOTE_ADDR' => self::PROXY, 'HTTP_X_FORWARDED_FOR' => '6.6.6.6, ' . self::CLIENT );
$this->assertSame( self::CLIENT, ClientIp::resolve( $srv, ClientIp::MODE_FORWARDED ) );
$this->assertSame( self::CLIENT, ClientIp::resolve( array( 'REMOTE_ADDR' => self::PROXY, 'HTTP_X_FORWARDED_FOR' => self::CLIENT ), ClientIp::MODE_FORWARDED ) );
}
public function test_ipv6_is_accepted(): void {
$this->assertSame( '2001:db8::1', ClientIp::resolve( array( 'REMOTE_ADDR' => self::PROXY, 'HTTP_CF_CONNECTING_IP' => '2001:db8::1' ), ClientIp::MODE_CLOUDFLARE ) );
}
public function test_unknown_when_nothing_valid(): void {
$this->assertSame( 'unknown', ClientIp::resolve( array(), ClientIp::MODE_CLOUDFLARE ) );
$this->assertSame( 'unknown', ClientIp::resolve( array( 'REMOTE_ADDR' => 'garbage' ) ) );
}
public function test_unrecognised_mode_behaves_like_direct(): void {
$srv = array( 'REMOTE_ADDR' => self::CLIENT, 'HTTP_CF_CONNECTING_IP' => '1.2.3.4' );
$this->assertSame( self::CLIENT, ClientIp::resolve( $srv, 'something_else' ) );
}
}