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
This commit is contained in:
HeuJung committed 2026-07-30 07:52:24 +09:00
1 parent 5d140dfbe6
commit d17ea28da5
272 files changed
+12431 -1006

No files matched your search

@@ -177,6 +177,11 @@ class ExtensionBundleServiceTest extends TestCase
public function test_dev_rewrites_source_mapping_url_to_asset_serving_path(): void
{
// 자산 URL 표기(경로형 vs `?file=` 쿼리형)는 사이트 설정이 정한다. 이 테스트가 보려는
// 것은 "개발 환경에서 소스맵 URL 이 에셋 서빙 주소로 재작성되는가" 이므로, 개발 사이트가
// 어느 모드를 쓰든 결과가 달라지지 않도록 경로형으로 고정한다.
config(['g7_settings.core.general.asset_url_mode' => 'extension']);
// 기본 testing 환경 = 비프로덕션 → dev rewrite 경로
$a = $this->writeFixture('a.js', "(function(){})()\n//# sourceMappingURL=a.js.map");
@@ -0,0 +1,118 @@
<?php
namespace Tests\Unit\Services;
use App\Extension\IdentityVerification\Providers\MailIdentityProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Log;
use ReflectionMethod;
use Tests\TestCase;
/**
* IDV 인증코드 길이 경계 테스트 (C3)
*
* 스키마가 경계를 선언하지 않아 서비스가 자체 상수(4~10)로 조용히 클램프했습니다.
* 관리자가 12를 설정하면 화면은 12로 보이는데 실제로는 10자리 코드가 발급됐습니다.
*/
class MailIdentityProviderCodeLengthTest extends TestCase
{
use RefreshDatabase;
/**
* 프로바이더 인스턴스를 반환합니다.
*
* @return MailIdentityProvider 프로바이더
*/
private function provider(): MailIdentityProvider
{
return app(MailIdentityProvider::class);
}
/**
* 스키마가 경계를 선언하는지 테스트합니다.
*
* 관리자 화면은 스키마를 그대로 노출하므로, 경계 선언이 곧 UI 계약이 된다.
*
* @scenario provider=mail, code_length=schema_declaration
*
* @effects schema_declares_min_max_boundaries
*/
public function test_schema_declares_code_length_boundaries(): void
{
$schema = $this->provider()->getSettingsSchema();
// 수정 전: min/max 키 자체가 없었다
$this->assertArrayHasKey('min', $schema['code_length']);
$this->assertArrayHasKey('max', $schema['code_length']);
$this->assertSame(MailIdentityProvider::MIN_CODE_LENGTH, $schema['code_length']['min']);
$this->assertSame(MailIdentityProvider::MAX_CODE_LENGTH, $schema['code_length']['max']);
$this->assertSame(MailIdentityProvider::DEFAULT_CODE_LENGTH, $schema['code_length']['default']);
}
/**
* 경계 내 길이는 그대로 적용되는지 테스트합니다.
*
* @scenario provider=mail, code_length=within_bounds
*
* @effects configured_length_applied_verbatim
*/
public function test_code_length_within_bounds_is_applied(): void
{
$method = new ReflectionMethod(MailIdentityProvider::class, 'generateNumericCode');
$this->assertSame(8, strlen($method->invoke($this->provider(), 8)));
$this->assertSame(4, strlen($method->invoke($this->provider(), 4)));
$this->assertSame(10, strlen($method->invoke($this->provider(), 10)));
}
/**
* 경계를 벗어나면 조용한 클램프 대신 기본값 폴백 + 경고 로그를 남기는지 테스트합니다.
*
* @scenario provider=mail, code_length=above_max
*
* @effects out_of_range_falls_back_to_default_with_warning
*/
public function test_out_of_range_falls_back_to_default_with_warning(): void
{
Log::spy();
$method = new ReflectionMethod(MailIdentityProvider::class, 'generateNumericCode');
// 수정 전: 12 → 10 으로 조용히 클램프
$code = $method->invoke($this->provider(), 12);
$this->assertSame(MailIdentityProvider::DEFAULT_CODE_LENGTH, strlen($code));
Log::shouldHaveReceived('warning')->once();
}
/**
* 하한 미만도 동일하게 폴백하는지 테스트합니다.
*
* @scenario provider=mail, code_length=below_min
*
* @effects out_of_range_falls_back_to_default_with_warning
*/
public function test_below_minimum_falls_back_to_default(): void
{
$method = new ReflectionMethod(MailIdentityProvider::class, 'generateNumericCode');
$this->assertSame(
MailIdentityProvider::DEFAULT_CODE_LENGTH,
strlen($method->invoke($this->provider(), 2))
);
}
/**
* 생성된 코드가 숫자로만 구성되는지 테스트합니다.
*
* @scenario provider=mail, code_length=within_bounds
*
* @effects generated_code_is_numeric
*/
public function test_generated_code_is_numeric(): void
{
$method = new ReflectionMethod(MailIdentityProvider::class, 'generateNumericCode');
$this->assertMatchesRegularExpression('/^\d{6}$/', $method->invoke($this->provider(), 6));
}
}
+27 -2
View File
@@ -150,6 +150,32 @@ class ModuleServiceAssetTest extends TestCase
'status' => ExtensionStatus::Active->value,
]);
$filePath = $this->testModulePath.'/dist/js/manifest.json';
file_put_contents($filePath, '{"version":3,"sources":[]}');
// Act
$result = $this->moduleService->getAssetFilePath('test-module', 'dist/js/manifest.json');
// Assert
$this->assertTrue($result['success']);
$this->assertEquals('application/json', $result['mimeType']);
}
/**
* 소스맵(.map)은 JSON 으로 타입 지정하지 않는다.
*
* 소스맵에는 원본 코드 전문(sourcesContent)이 담겨 있어, 서빙 허용 자체를 로컬 환경으로
* 한정하고 MIME 표에서도 제외했다(#471 / 공개 #72). 표에 되돌아오면 그 조치가 조용히
* 풀린 것이므로 명시적으로 고정한다.
*/
public function test_source_map_is_not_typed_as_json(): void
{
// Arrange
Module::factory()->create([
'identifier' => 'test-module',
'status' => ExtensionStatus::Active->value,
]);
$filePath = $this->testModulePath.'/dist/js/module.iife.js.map';
file_put_contents($filePath, '{"version":3,"sources":[]}');
@@ -157,8 +183,7 @@ class ModuleServiceAssetTest extends TestCase
$result = $this->moduleService->getAssetFilePath('test-module', 'dist/js/module.iife.js.map');
// Assert
$this->assertTrue($result['success']);
$this->assertEquals('application/json', $result['mimeType']);
$this->assertNotEquals('application/json', $result['mimeType']);
}
/**
@@ -30,8 +30,11 @@ class NotificationDefinitionServiceTest extends TestCase
*/
public function test_resolve_returns_active_definition(): void
{
// 코어 알림 정의(welcome 등)는 config/core.php 를 SSoT 로 부팅 시 DB 에 동기화되므로
// 같은 type 을 새로 만들면 중복이 된다. 이 테스트가 보려는 것은 resolve() 의 동작이라
// 코어가 선점하지 않는 전용 type 을 쓴다.
NotificationDefinition::create([
'type' => 'welcome',
'type' => 'active_resolve_target',
'hook_prefix' => 'core.auth',
'extension_type' => 'core',
'extension_identifier' => 'core',
@@ -43,12 +46,12 @@ class NotificationDefinitionServiceTest extends TestCase
'is_default' => true,
]);
$this->service->invalidateCache('welcome');
$this->service->invalidateCache('active_resolve_target');
$result = $this->service->resolve('welcome');
$result = $this->service->resolve('active_resolve_target');
$this->assertNotNull($result);
$this->assertEquals('welcome', $result->type);
$this->assertEquals('active_resolve_target', $result->type);
}
/**
@@ -111,8 +114,12 @@ class NotificationDefinitionServiceTest extends TestCase
$result = $this->service->getAllActive();
$this->assertCount(1, $result);
$this->assertEquals('active_one', $result->first()->type);
// 코어 알림 정의가 부팅 시 함께 동기화되므로 절대 개수로는 판정할 수 없다.
// 이 테스트의 주제는 "활성만 돌려주는가" 이므로 이 테스트가 만든 두 건으로 판정한다.
$types = $result->pluck('type');
$this->assertContains('active_one', $types);
$this->assertNotContains('inactive_one', $types);
}
/**
@@ -200,31 +200,37 @@ class NotificationTemplateServiceTest extends TestCase
*/
public function test_reset_to_default_restores_click_url_and_recipients(): void
{
$definition = NotificationDefinition::create([
'type' => 'welcome',
'hook_prefix' => 'core.auth',
'extension_type' => 'core',
'extension_identifier' => 'core',
'name' => ['ko' => '회원가입 환영'],
'variables' => [],
'channels' => ['database'],
'hooks' => [],
'is_active' => true,
'is_default' => true,
]);
// welcome 은 코어 알림 정의라 config/core.php 를 SSoT 로 부팅 시 이미 동기화되어 있다.
// 이 테스트는 그 정의에 템플릿을 매달아 복원 동작을 보므로, 있으면 그대로 쓴다.
$definition = NotificationDefinition::firstOrCreate(
['type' => 'welcome'],
[
'hook_prefix' => 'core.auth',
'extension_type' => 'core',
'extension_identifier' => 'core',
'name' => ['ko' => '회원가입 환영'],
'variables' => [],
'channels' => ['database'],
'hooks' => [],
'is_active' => true,
'is_default' => true,
]
);
// 관리자가 click_url/recipients 를 임의 값으로 수정한 상태
$template = NotificationTemplate::create([
'definition_id' => $definition->id,
'channel' => 'database',
'subject' => ['ko' => '수정된 제목'],
'body' => ['ko' => '수정된 본문'],
'click_url' => '/custom-edited-url',
'recipients' => [['type' => 'admin']],
'is_active' => true,
'is_default' => false,
'user_overrides' => ['click_url' => true, 'recipients' => true],
]);
// 관리자가 click_url/recipients 를 임의 값으로 수정한 상태.
// 코어 템플릿이 이미 동기화되어 있으면 그 행을 수정본으로 만든다 (실제 시나리오와 동일).
$template = NotificationTemplate::updateOrCreate(
['definition_id' => $definition->id, 'channel' => 'database'],
[
'subject' => ['ko' => '수정된 제목'],
'body' => ['ko' => '수정된 본문'],
'click_url' => '/custom-edited-url',
'recipients' => [['type' => 'admin']],
'is_active' => true,
'is_default' => false,
'user_overrides' => ['click_url' => true, 'recipients' => true],
]
);
$defaultData = $this->service->getDefaultTemplateData('welcome', 'database');
$restored = $this->service->resetToDefault($template, $defaultData);