v7.0.0-beta.4 release
This commit is contained in:
1 parent
05db17887d
commit
1db039ff34
1545 files changed
+136783
-11634
No files matched your search
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Tests\Feature\Middleware;
|
||||
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -106,62 +104,37 @@ class ThrottleMiddlewareTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* 실제 API 라우트에 throttle이 적용되었는지 확인합니다.
|
||||
* 사용자/관리자 라우트에 throttle 이 적용되어 있는지 미들웨어 목록으로 확인합니다.
|
||||
*
|
||||
* 참고: Route::middleware() 는 alias 를 FQCN 으로 resolve 한 결과를 반환하므로
|
||||
* 'throttle:600,1' 문자열 일치 대신 부분 매칭(ThrottleRequests/throttle 키워드)을 사용한다.
|
||||
* 로그인 라우트(api.auth.login)에는 throttle 이 적용되지 않는다 — 현재 정책.
|
||||
*/
|
||||
public function test_actual_api_routes_have_throttle_applied(): void
|
||||
public function test_throttle_is_applied_to_authenticated_api_routes(): void
|
||||
{
|
||||
// 인증 라우트에 throttle 적용 확인
|
||||
$route = Route::getRoutes()->getByName('api.auth.login');
|
||||
$this->assertNotNull($route);
|
||||
$this->assertContains('throttle:600,1', $route->middleware());
|
||||
$userRoute = Route::getRoutes()->getByName('api.user.auth.user');
|
||||
$adminRoute = Route::getRoutes()->getByName('api.admin.auth.user');
|
||||
$this->assertNotNull($userRoute);
|
||||
$this->assertNotNull($adminRoute);
|
||||
|
||||
$this->assertThrottleMiddlewareApplied($userRoute->middleware(), 'api.user.auth.user');
|
||||
$this->assertThrottleMiddlewareApplied($adminRoute->middleware(), 'api.admin.auth.user');
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 라우트에 throttle이 적용되었는지 확인합니다.
|
||||
* 미들웨어 배열에서 throttle(ThrottleRequests) 적용 여부를 확인합니다.
|
||||
*
|
||||
* @param array<string> $middleware
|
||||
*/
|
||||
public function test_admin_routes_have_throttle_applied(): void
|
||||
private function assertThrottleMiddlewareApplied(array $middleware, string $routeName): void
|
||||
{
|
||||
// 관리자 역할 생성
|
||||
$adminRole = Role::create([
|
||||
'identifier' => 'admin',
|
||||
'name' => ['ko' => '관리자', 'en' => 'Administrator'],
|
||||
'description' => ['ko' => '시스템 관리자', 'en' => 'System administrator'],
|
||||
'extension_type' => ExtensionOwnerType::Core,
|
||||
'extension_identifier' => 'core',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$adminUser = User::factory()->create();
|
||||
$adminUser->roles()->attach($adminRole->id);
|
||||
|
||||
// 관리자 라우트에 throttle 적용 확인
|
||||
$route = Route::getRoutes()->getByName('api.admin.auth.user');
|
||||
$this->assertNotNull($route);
|
||||
$this->assertContains('throttle:600,1', $route->middleware());
|
||||
|
||||
// 실제 요청으로 확인
|
||||
$response = $this->actingAs($adminUser)
|
||||
->getJson('/api/admin/auth/user');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertHeader('X-RateLimit-Limit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자 라우트에 throttle이 적용되었는지 확인합니다.
|
||||
*/
|
||||
public function test_user_routes_have_throttle_applied(): void
|
||||
{
|
||||
// 사용자 라우트에 throttle 적용 확인
|
||||
$route = Route::getRoutes()->getByName('api.user.auth.user');
|
||||
$this->assertNotNull($route);
|
||||
$this->assertContains('throttle:600,1', $route->middleware());
|
||||
|
||||
// 실제 요청으로 확인
|
||||
$response = $this->actingAs($this->testUser)
|
||||
->getJson('/api/user/auth/user');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertHeader('X-RateLimit-Limit');
|
||||
$hasThrottle = false;
|
||||
foreach ($middleware as $m) {
|
||||
if (str_contains($m, 'ThrottleRequests') || str_starts_with($m, 'throttle:')) {
|
||||
$hasThrottle = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertTrue($hasThrottle, "{$routeName} 라우트에 throttle 미들웨어가 적용되어야 합니다");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user