Files
hado/core/tests/Feature/RemoteUserTrustTest.php

26 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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);
}
}