Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
26 lines
1.1 KiB
PHP
26 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Tests\TestCase;
|
||
|
||
/** X-Remote-User верим только соседу по докер-сети (Caddy); с тейлнета или снаружи заголовок — не пропуск. */
|
||
class RemoteUserTrustTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
public function test_header_is_trusted_from_docker_bridge_and_loopback(): void
|
||
{
|
||
$this->withServerVariables(['REMOTE_ADDR' => '172.21.0.1'])->getJson('/me', ['X-Remote-User' => 'luci'])->assertOk();
|
||
$this->withServerVariables(['REMOTE_ADDR' => '127.0.0.1'])->getJson('/me', ['X-Remote-User' => 'luci'])->assertOk();
|
||
}
|
||
|
||
public function test_header_from_tailnet_or_internet_is_rejected(): void
|
||
{
|
||
$this->withServerVariables(['REMOTE_ADDR' => '100.124.15.61'])->getJson('/me', ['X-Remote-User' => 'luci'])
|
||
->assertStatus(401)->assertJsonPath('message', 'X-Remote-User принимается только от прокси');
|
||
$this->withServerVariables(['REMOTE_ADDR' => '8.8.8.8'])->getJson('/me', ['X-Remote-User' => 'luci'])->assertStatus(401);
|
||
}
|
||
}
|