Enhance: plans index show safe back link

This commit is contained in:
萝卜
2026-03-13 19:05:04 +00:00
parent c456585fb5
commit 69612847b7
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlanIndexBackLinkTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_index_should_show_safe_back_link_when_back_is_relative_path(): void
{
$this->loginAsPlatformAdmin();
$this->get('/admin/plans?status=active&back=' . urlencode('/admin/site-subscriptions?status=activated'))
->assertOk()
->assertSee('返回上一页(保留上下文)')
->assertSee('href="/admin/site-subscriptions?status=activated"', false);
}
public function test_index_should_not_show_back_link_when_back_is_external_url(): void
{
$this->loginAsPlatformAdmin();
$this->get('/admin/plans?back=' . urlencode('https://evil.example.com/'))
->assertOk()
->assertDontSee('返回上一页(保留上下文)');
}
}