Files
HeuJung d17ea28da5 fix(core,board,ecommerce,page,kginicis): 정책값 하드코딩·계약 분리 결함 일괄 수정
관리자 환경설정이 값을 저장은 하지만 실제 동작에는 닿지 않던 결함군을 정리했다.
설정 화면(min/max)·저장 검증(FormRequest)·런타임 적용(Service) 세 계층이 각자
리터럴을 들고 있어 서로 조용히 갈라지던 것이 공통 원인이다.

경계값 SSoT 도입:
- config/core.php `settings_limits` 를 단일 출처로 두고, FormRequest 는 이 값으로
 규칙을 만들고 화면은 설정 응답의 `_meta.limits` 로 같은 값을 받아 바인딩한다.
- 게시판·이커머스도 각 모듈 config 의 limits 를 동일 구조로 노출한다.

적용되지 않던 정책을 실제로 적용:
- 비밀번호 최소 길이·특수문자 필수(신규 지정 7개 경로. 로그인은 제외 — 정책을
 올렸을 때 기존 회원이 자기 계정에 접근조차 못 하는 데드락을 막기 위함)
- 계정 잠금 시간 0 = 무한대(전용 컬럼 분리. timestamp 상한과 NULL 규약 때문에
 기존 컬럼 재사용이 불가능하다) + 관리자 수동 해제 경로
- 업로드 최대 크기·허용 확장자, 게시판 첨부 개수·댓글 깊이, 페이지 첨부 정책,
 장바구니 수량·구매 한도, 마일리지 사용 한도, 주문 부가세

파생 결함:
- 큐 Job(sync 드라이버)이 진행 중인 요청의 Request 바인딩을 덮어써, 뒤이어 실행되는
 훅 리스너가 헤더를 잃고 조용히 건너뛰었다. Job 이 원 바인딩을 복원하도록 고치고,
 전송 헤더가 필요한 리스너는 동기 실행으로 선언한다.
- 확장 업데이트 실패 시 상태만 되돌리고 상태 캐시를 비우지 않아, 그 확장의 관리자
 화면만 캐시 TTL(기본 하루) 동안 404 로 남았다. 실패 경로에도 무효화를 대칭으로
 두고, 빈 목록 자체를 캐시하지 않는다.
- 글 작성 시 첨부 파일이 Service 로 전달되지 않아 검증·권한은 통과하고 첨부만 사라졌다.
- 환경설정 저장 실패 안내가 내부 설정 키를 그대로 노출했다(105개 항목에 라벨 부여).

재발 방지:
- audit 룰 3종(레이아웃 경계 리터럴 / FormRequest 경계 불일치 / Service 재클램프)
- 테스트 실행 범위 강제 훅(check-test-scope)
- 트러블슈팅 사례 2건(큐 Job 요청 오염 / 확장 상태 캐시 고착)

공개 이슈: gnuboard/g7
2026-07-30 07:52:24 +09:00

198 lines
6.8 KiB
PHP

<?php
namespace Modules\Sirsoft\Board\Tests\Feature;
require_once __DIR__.'/../ModuleTestCase.php';
use App\Models\Role;
use App\Models\User;
use Modules\Sirsoft\Board\Exceptions\PostNotCommentableException;
use Modules\Sirsoft\Board\Services\CommentService;
use Modules\Sirsoft\Board\Tests\BoardTestCase;
/**
* 댓글 작성 불가 게시글 상태 응답 계약 테스트
*
* 검증 목적:
* - 요청 경로: `CommentValidationRule` 이 블라인드/삭제 게시글을 422 로 선차단한다 (기존 계약 고정)
* - Service 직접 경로: FormRequest 를 거치지 않는 훅·확장 호출에서도 도메인 예외로 막힌다
*
* 깊이 상한(B1)·첨부 개수(B3)와 같은 구조다 — 요청 단계는 UX 선차단, Service 가 최종 불변조건.
* Service 가 베이스 `\Exception` 을 던지면 컨트롤러의 제네릭 catch 에 걸려 500 + 일반 문구가 되어
* 사유가 사라지므로, 전용 예외를 두어 422 로 매핑한다.
*
* @group board
* @group comment
*/
class CommentPostStateTest extends BoardTestCase
{
private User $memberUser;
protected function getTestBoardSlug(): string
{
return 'comment-post-state';
}
protected function getDefaultBoardAttributes(string $slug): array
{
return [
'slug' => $slug,
'name' => ['ko' => '댓글 상태 게시판', 'en' => 'Comment State Board'],
'is_active' => true,
'use_comment' => true,
'max_comment_depth' => 5,
];
}
protected function setUp(): void
{
parent::setUp();
$this->setGuestPermissions(['posts.read', 'posts.write', 'comments.read', 'comments.write']);
$this->grantUserRolePermissions(['posts.read', 'posts.write', 'comments.read', 'comments.write']);
$this->memberUser = User::factory()->create(['email' => 'comment-post-state@test.com']);
$userRole = Role::where('identifier', 'user')->first();
if ($userRole) {
$this->memberUser->roles()->attach($userRole->id);
}
}
/**
* 요청 경로: 블라인드 게시글 댓글은 422 로 선차단된다
*
* @scenario entity=board_comment, post_state=blinded
*
* @effects blinded_post_comment_rejected_422
*/
public function test_request_path_rejects_comment_on_blinded_post(): void
{
$postId = $this->createTestPost(['status' => 'blinded']);
$this->actingAs($this->memberUser)
->postJson($this->storeUrl($postId), ['content' => '블라인드 글에 댓글'])
->assertStatus(422);
$this->assertDatabaseMissing('board_comments', ['post_id' => $postId]);
}
/**
* 요청 경로: 삭제된 게시글 댓글은 422 로 선차단된다
*
* @scenario entity=board_comment, post_state=deleted
*
* @effects deleted_post_comment_rejected_422
*/
public function test_request_path_rejects_comment_on_deleted_post(): void
{
$postId = $this->createTestPost(['status' => 'deleted']);
$this->actingAs($this->memberUser)
->postJson($this->storeUrl($postId), ['content' => '삭제된 글에 댓글'])
->assertStatus(422);
$this->assertDatabaseMissing('board_comments', ['post_id' => $postId]);
}
/**
* Service 직접 경로: 블라인드 게시글은 도메인 예외로 막힌다
*
* 베이스 `\Exception` 이면 컨트롤러 제네릭 catch 에 흡수되어 사유가 사라진다.
*
* @scenario entity=board_comment, post_state=blinded
*
* @effects blinded_post_comment_rejected_422
*/
public function test_service_direct_call_rejects_comment_on_blinded_post(): void
{
$postId = $this->createTestPost(['status' => 'blinded']);
$this->expectException(PostNotCommentableException::class);
$this->expectExceptionMessage(__('sirsoft-board::messages.comment.post_blinded'));
app(CommentService::class)->createComment($this->board->slug, [
'post_id' => $postId,
'content' => 'FormRequest 를 우회한 블라인드 글 댓글',
'user_id' => $this->memberUser->id,
]);
}
/**
* Service 직접 경로: 삭제된 게시글은 도메인 예외로 막힌다
*
* @scenario entity=board_comment, post_state=deleted
*
* @effects deleted_post_comment_rejected_422
*/
public function test_service_direct_call_rejects_comment_on_deleted_post(): void
{
$postId = $this->createTestPost(['status' => 'deleted']);
$this->expectException(PostNotCommentableException::class);
$this->expectExceptionMessage(__('sirsoft-board::messages.comment.post_deleted'));
app(CommentService::class)->createComment($this->board->slug, [
'post_id' => $postId,
'content' => 'FormRequest 를 우회한 삭제 글 댓글',
'user_id' => $this->memberUser->id,
]);
}
/**
* Service 직접 경로: soft-delete 된 게시글도 도메인 예외로 막힌다
*
* @scenario entity=board_comment, post_state=soft_deleted
*
* @effects deleted_post_comment_rejected_422
*/
public function test_service_direct_call_rejects_comment_on_soft_deleted_post(): void
{
$postId = $this->createTestPost(['deleted_at' => now()]);
$this->expectException(PostNotCommentableException::class);
$this->expectExceptionMessage(__('sirsoft-board::messages.comment.post_deleted'));
app(CommentService::class)->createComment($this->board->slug, [
'post_id' => $postId,
'content' => 'FormRequest 를 우회한 soft-delete 글 댓글',
'user_id' => $this->memberUser->id,
]);
}
/**
* 정상 게시글의 댓글 작성은 요청·Service 양 경로에서 그대로 통과한다 (과잉 차단 방지)
*
* @scenario entity=board_comment, post_state=published
*
* @effects published_post_comment_allowed
*/
public function test_comment_on_published_post_still_passes(): void
{
$postId = $this->createTestPost();
$this->actingAs($this->memberUser)
->postJson($this->storeUrl($postId), ['content' => '정상 댓글'])
->assertStatus(201);
$comment = app(CommentService::class)->createComment($this->board->slug, [
'post_id' => $postId,
'content' => 'Service 직접 호출 댓글',
'user_id' => $this->memberUser->id,
]);
$this->assertNotNull($comment->id);
}
/**
* 댓글 생성 엔드포인트 URL 을 생성합니다.
*
* @param int $postId 게시글 ID
* @return string 댓글 생성 URL
*/
private function storeUrl(int $postId): string
{
return "/api/modules/sirsoft-board/boards/{$this->board->slug}/posts/{$postId}/comments";
}
}