Merge branch 'develop' of https://github.com/gnuboard/dev-g7 into develop

This commit is contained in:
HeuJung committed 2026-08-18 11:04:01 +09:00
commit 07c459f0ff
14 files changed
+481 -34

No files matched your search

@@ -0,0 +1,26 @@
<?php
namespace Modules\G7Testing\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\G7Testing\Console\FakeExtensionScheduleCommand;
/**
* 스케줄 Artisan 허용목록의 "확장 소유 명령" 계층을 HTTP 문맥에서 검증하기 위한
* 테스트 전용 서비스 프로바이더.
*
* 실제 확장 프로바이더는 `$this->app->runningInConsole()` 일 때만 커맨드를 Artisan 에
* 등록하므로, HTTP 요청(관리자 화면의 스케줄 저장 검증)에서는 `Artisan::all()` 에
* 확장 커맨드가 존재하지 않는다. 검증기는 이 경우 프로바이더가 선언한 `$commands`
* 기본값을 폴백으로 해석해야 한다 — 이 픽스처는 그 상황(커맨드 미등록 + 프로바이더의
* `$commands` 선언만 존재)을 재현한다.
*
* `Tests\` PSR-4 네임스페이스가 아니므로 오토로드되지 않는다 — 사용처에서 require 한다.
*/
class FakeExtensionScheduleServiceProvider extends ServiceProvider
{
/** @var array<int, class-string> 실제 확장 프로바이더와 동일한 선언 형태 */
protected array $commands = [
FakeExtensionScheduleCommand::class,
];
}
@@ -71,6 +71,41 @@ test.describe('레이아웃 표현식 평가 샌드박스', () => {
expect(result.date).toBe(true);
});
// @scenario case=destructuring_param
// @effects same_expression_same_value_across_paths
test('화살표 파라미터 배열 구조분해(([k, v])·홀)가 배포 번들에서 동작한다 (engine-v1.60.5 회귀)', async ({ page }) => {
const result = await page.evaluate(() => {
const g7 = (window as any).G7Core;
const ctx = {
sel: { 5: 50, 6: null },
perms: { 'admin.manage': true, read: true, write: false },
errors: { name: ['이름은 필수입니다'] },
};
return {
// _purchase_card.json 장바구니/바로구매 본문 형태 — 홀 + 쌍 분해
hole: g7.evaluateCondition('{{Object.entries(sel ?? {}).filter(([, vid]) => vid != null).length === 1}}', ctx),
pair: g7.evaluateCondition('{{Object.entries(sel ?? {}).filter(([, v]) => v != null).map(([gid, vid]) => Number(gid) + Number(vid)).includes(55)}}', ctx),
single: g7.evaluateCondition('{{Object.entries(sel ?? {}).map(([k]) => k).includes("5")}}', ctx),
// 게시판 환경설정 권한 computed 형태: filter([key]) + startsWith + map([key])
entriesFilterMap: g7.evaluateCondition(
"{{Object.entries(perms ?? {}).filter(([key]) => !key.startsWith('admin.')).map(([key]) => key).length === 2}}",
ctx,
),
// 검증 오류 표시 형태: ([field, messages])
fieldMessages: g7.evaluateCondition(
"{{Object.entries(errors ?? {}).map(([field, messages]) => field + ':' + messages[0])[0] === 'name:이름은 필수입니다'}}",
ctx,
),
};
});
expect(result.hole).toBe(true);
expect(result.pair).toBe(true);
expect(result.single).toBe(true);
expect(result.entriesFilterMap).toBe(true);
expect(result.fieldMessages).toBe(true);
});
// @scenario case=constructor_escape
// @effects sandbox_escape_blocked, dangerous_payload_does_not_set_global
test('constructor 체인 샌드박스 탈출이 코드를 실행하지 못한다', async ({ page }) => {
+61 -1
View File
@@ -33,6 +33,9 @@ class SeoMetaResolverTest extends TestCase
Config::set('g7_settings.core.seo.google_analytics_id', 'GA-12345');
Config::set('g7_settings.core.seo.google_site_verification', '');
Config::set('g7_settings.core.seo.naver_site_verification', '');
// 운영자가 로컬에 저장한 값(storage/app/settings/seo.json)이 부팅 시 config 로
// 실려 들어오므로, 미고정 시 og site_name fallback 단언이 환경에 좌우된다.
Config::set('g7_settings.core.seo.og_default_site_name', '');
Config::set('g7_settings.core.general.site_name', '그누보드7 쇼핑몰');
}
@@ -374,6 +377,35 @@ class SeoMetaResolverTest extends TestCase
$this->assertSame('나이키 에어맥스', $jsonLd['description']);
}
/**
* JSON-LD 는 `<script type="application/ld+json">` 안에 임베드되므로, 사용자
* 제어 값(검색어 등)의 `</script>` 가 스크립트 컨텍스트를 조기 종료해 실행 가능한
* script 요소를 재생성하지 못하도록 `<`·`>` 를 유니코드 이스케이프해야 한다.
* (봇 렌더는 _escaped_fragment_ 로 일반 UA 도 강제되므로 반사형 XSS 벡터가 된다.)
*/
public function test_structured_data_escapes_script_breakout_in_json_ld(): void
{
$seoConfig = [
'structured_data' => [
'@type' => 'SearchResultsPage',
'name' => 'G7 - {{query.q}}',
],
];
$context = ['query' => ['q' => '</script><script>alert(1)</script>']];
$result = $this->resolver->resolve($seoConfig, $context, null, null, []);
// 원문 태그가 그대로 실리면 스크립트 컨텍스트가 조기 종료돼 실행 가능한 script 요소가
// 재생성된다(반사형 XSS). JSON_HEX_TAG 가 태그 문자를 유니코드 이스케이프하므로 산출물에는
// 리터럴 태그 열림/닫힘 문자가 없어야 한다.
$this->assertDoesNotMatchRegularExpression('#</?script#', $result['jsonLd']);
$this->assertStringContainsString(chr(0x5C).'u003C', $result['jsonLd']);
// 이스케이프에도 불구하고 JSON 파싱 시 원래 값이 복원된다(구조화 데이터 의미 보존).
$decoded = json_decode($result['jsonLd'], true);
$this->assertSame('G7 - </script><script>alert(1)</script>', $decoded['name']);
}
/**
* 구조화 데이터가 없으면 jsonLd는 null입니다.
*/
@@ -1562,7 +1594,7 @@ class SeoMetaResolverTest extends TestCase
'page_type' => 'product',
'vars' => [
// 표현식이 다국어 객체를 직접 반환 — substituteVars 까지 array 전달
'product_name' => "{{product.data.name}}",
'product_name' => '{{product.data.name}}',
'commerce_name' => '$module_settings:basic_info.shop_name',
],
];
@@ -1638,4 +1670,32 @@ class SeoMetaResolverTest extends TestCase
$this->assertSame('운동화', $result['og']['description']);
$this->assertSame('https://e.co/ko.jpg', $result['og']['image']);
}
/**
* 접미사 조립: 저장 시 TrimStrings 가 선행 공백을 제거하므로("| 그누보드7"),
* 제목이 있으면 공백을 복원해 잇고, 제목이 비면 매달린 구분자를 떼어낸다.
* (blade 는 title.titleSuffix 단순 연결 — 조립 규칙은 이 메서드가 SSoT)
*/
public function test_compose_title_suffix_restores_space_between_title_and_trimmed_suffix(): void
{
$this->assertSame(' | 그누보드7', SeoMetaResolver::composeTitleSuffix('가죽 크로스백', '| 그누보드7'));
}
public function test_compose_title_suffix_keeps_explicit_leading_space_as_is(): void
{
$this->assertSame(' | 그누보드7', SeoMetaResolver::composeTitleSuffix('가죽 크로스백', ' | 그누보드7'));
}
public function test_compose_title_suffix_strips_dangling_separator_when_title_is_empty(): void
{
$this->assertSame('그누보드7', SeoMetaResolver::composeTitleSuffix('', '| 그누보드7'));
$this->assertSame('그누보드7', SeoMetaResolver::composeTitleSuffix('', ' - 그누보드7'));
}
public function test_compose_title_suffix_returns_empty_when_suffix_is_blank(): void
{
$this->assertSame('', SeoMetaResolver::composeTitleSuffix('가죽 크로스백', ''));
$this->assertSame('', SeoMetaResolver::composeTitleSuffix('', ' '));
$this->assertSame('', SeoMetaResolver::composeTitleSuffix('', '| '));
}
}
@@ -675,6 +675,40 @@ class ScheduleCommandValidatorTest extends TestCase
$this->assertSame(ScheduleCommandValidator::ARTISAN_REASON_OPTION, $verdict['reason']);
}
/**
* Artisan 에 커맨드가 등록되지 않은 문맥(HTTP 요청)에서도, 활성 프로바이더가
* `$commands` 로 선언한 확장 소유 명령은 자동 허용된다.
*
* 실제 확장 프로바이더는 `runningInConsole()` 일 때만 커맨드를 등록하므로,
* 관리자 화면의 스케줄 저장 검증(HTTP)에서는 `Artisan::all()` 에 확장 커맨드가
* 없다. 등록 인스턴스가 없으면 프로바이더 선언(클래스 네임스페이스 + 실제 명령명
* 대조)을 폴백으로 해석해야 한다 — 없으면 "설치된 확장 명령 자동 허용" 약속이
* 웹 저장 경로에서 통째로 동작하지 않는다 (7.0.7 검수 발견).
*
* @scenario command_class=extension_owned, enforcement_point=validator_unit
*
* @effects extension_owned_commands_resolved_without_console_registration
*/
#[Test]
public function it_allows_provider_declared_extension_commands_without_console_registration(): void
{
require_once __DIR__.'/../../Fixtures/Extension/FakeExtensionScheduleCommand.php';
require_once __DIR__.'/../../Fixtures/Extension/FakeExtensionScheduleServiceProvider.php';
// Artisan::registerCommand 를 호출하지 않는다 — HTTP 문맥 재현.
$this->app->register(\Modules\G7Testing\Providers\FakeExtensionScheduleServiceProvider::class);
$verdict = ScheduleCommandValidator::inspectArtisanCommand('g7-testing-fake-extension-command --scope=all');
$this->assertTrue($verdict['allowed'], '프로바이더 선언 확장 명령이 HTTP 문맥에서 거부됨');
$this->assertSame('g7-testing-fake-extension-command', $verdict['name']);
// 자기 정의에 없는 옵션은 같은 폴백 경로에서도 거부되어야 한다.
$optionVerdict = ScheduleCommandValidator::inspectArtisanCommand('g7-testing-fake-extension-command --g7-not-a-real-option');
$this->assertFalse($optionVerdict['allowed']);
$this->assertSame(ScheduleCommandValidator::ARTISAN_REASON_OPTION, $optionVerdict['reason']);
}
/**
* 확장 네임스페이스를 비워도 코어 허용목록은 그대로 동작한다 (계층 독립성).
*
@@ -10,7 +10,7 @@ description: |
미실행(전역 canary `window.__g7jsi` 미설정) 양면을 잠근다.
axes:
case: [safe_expression, arrow_template_literal, constructor_escape, nonstring_key_escape, object_facade_safe]
case: [safe_expression, arrow_template_literal, destructuring_param, constructor_escape, nonstring_key_escape, object_facade_safe]
effects:
- same_expression_same_value_across_paths
@@ -59,6 +59,7 @@ effects:
- denylist_is_evaluated_before_the_allowlist
- make_prefix_blocks_all_code_generating_commands
- extension_owned_commands_are_allowed_by_namespace
- extension_owned_commands_resolved_without_console_registration
- extension_gate_can_be_turned_off
- extension_commands_only_accept_their_own_options
# 사용법 제한