feat(core,extensions): 구동 에셋 자체 제공 · 자산 실패 폴백 · 운영자 추가 에셋(custom/)
공개 저장소 이슈 gnuboard/g7 (@bigmsg) 제보에서 출발한 작업이다. 브라우저가 화면을 그리려고 제3자 CDN 에 도달해야 하면, 그 도달 실패는 예외도 로그도 남기지 않고 화면 기능만 조용히 사라진다. 폐쇄망·방화벽·광고차단기에서 재현되는데 자체 서버 로그에는 흔적이 없어 운영자가 원인을 특정할 수 없다. 제보된 것은 편집기 하나였지만 같은 구조가 아이콘·글꼴·코드편집기·압축 라이브러리·설치 마법사·개발 대시보드에 똑같이 있었으므로, 번들 확장과 템플릿 전체를 자체 제공으로 옮겼다. 런타임에 외부로 나가는 것은 주소 검색 서비스 하나만 남았다. 자체 제공만으로는 부족하다 — 자기 서버에서 받는 파일도 실패할 수 있고, 종전에는 그 실패가 무음이었다. CSS 경로에 재시도 계층을 세우고(스크립트 경로와 동형), 서버가 HTML 에 직접 심는 externals 까지 실패를 붙잡아 안내 배너와 [다시 시도]로 표면화했다. 편집기·코드편집기는 확보 실패 시 평문 입력으로 내려앉되 저장 계약을 유지한다. 두 번째 축은 운영자가 CSS 를 덧붙일 자리가 없던 문제다(sir.kr 문의). 확장 디렉토리의 custom/ 을 운영자 소유로 정해, 확장 교체가 그 디렉토리만은 보존하게 했다. 출처에 의존하지 않는 서술자로 해석하므로 나중에 다른 출처가 붙어도 소비자는 바뀌지 않는다. 확장 자산과 같은 메커니즘으로 정적 게시되어 CSS 내부 상대 url 도 해석되고, 파일을 고치면 그 변경을 감지해 재게시까지 예약된다. FTP 접근이 없는 운영자에게는 그 자리도 없는 것과 같으므로 레이아웃 편집기에서 직접 넣고 고칠 수 있게 했다. 모듈·플러그인·템플릿이 한 엔드포인트를 공유한다 — 타입별로 나누면 같은 검증이 세 벌로 갈리고 그중 약한 하나가 우회로가 된다. 여기서 올린 스크립트는 그 레이아웃 한 장이 아니라 사이트 전 화면에서 실행되므로 레이아웃 편집과 분리된 전용 권한으로 연다. 운영자 CSS 가 화면을 조작 불능으로 만들면 그것을 고칠 화면에도 같은 CSS 가 실려 스스로 갇히므로, 서버가 목록을 비우는 탈출구(?custom=off)를 함께 뒀다. 동봉 자산은 재생성 경로에 버전 대조 가드를 붙였다. 선언과 다른 버전을 버전 디렉토리에 써 넣는 조용한 거짓말은 배포된 뒤에는 드러나지 않는다.
This commit is contained in:
@@ -433,4 +433,116 @@ class ModuleAssetServingTest extends TestCase
|
||||
// Assert: 200 서빙이 아니어야 한다 (검증 실패 → 리다이렉트)
|
||||
$this->assertNotSame(200, $browser->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 운영자가 넣은 `custom/` 자산도 서빙된다.
|
||||
*
|
||||
* 모듈 자산 경로는 확장 루트 기준이라 `custom/` 이 별도 분기 없이 해석된다
|
||||
* (템플릿만 `dist/` 하드코딩이라 분기가 필요했다). 그 사실을 실제 HTTP 로 고정한다 —
|
||||
* 서비스 반환값만 보면 라우트·FormRequest 게이트를 통과하는지가 남는다.
|
||||
*
|
||||
* @scenario custom_source=convention_scan, custom_asset=css
|
||||
*
|
||||
* @effects custom_asset_loaded_after_extension_bundles
|
||||
*/
|
||||
public function test_serves_operator_custom_css_from_active_module(): void
|
||||
{
|
||||
// Arrange
|
||||
mkdir($this->testModulePath.'/custom', 0755, true);
|
||||
file_put_contents($this->testModulePath.'/custom/custom.css', '.operator { color: red; }');
|
||||
|
||||
// Act
|
||||
$response = $this->get('/api/modules/assets/test-module/custom/custom.css');
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$this->assertTrue(
|
||||
str_starts_with($response->headers->get('Content-Type'), 'text/css'),
|
||||
'Content-Type should start with text/css'
|
||||
);
|
||||
|
||||
// BinaryFileResponse 는 스트리밍이라 본문이 버퍼에 없다 — 어떤 파일을 서빙했는지로
|
||||
// 확인한다. dist/ 의 동명 파일이 아니라 custom/ 의 파일이어야 한다.
|
||||
$served = $response->baseResponse->getFile()->getRealPath();
|
||||
$this->assertSame(
|
||||
realpath($this->testModulePath.'/custom/custom.css'),
|
||||
$served,
|
||||
'custom/ 의 파일이 서빙되어야 한다'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 비활성 모듈의 `custom/` 은 서빙되지 않는다.
|
||||
*
|
||||
* 비활성 확장의 자산이 계속 응답하면 "껐는데 스타일이 남아 있다" 가 된다.
|
||||
*
|
||||
* @scenario custom_source=convention_scan
|
||||
*
|
||||
* @effects inactive_extension_custom_not_served
|
||||
*/
|
||||
public function test_returns_404_for_custom_asset_of_inactive_module(): void
|
||||
{
|
||||
// Arrange
|
||||
mkdir($this->testModulePath.'/custom', 0755, true);
|
||||
file_put_contents($this->testModulePath.'/custom/custom.css', '.operator { color: red; }');
|
||||
|
||||
$this->activeModule->update(['status' => ExtensionStatus::Inactive->value]);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/api/modules/assets/test-module/custom/custom.css');
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* `custom/` 도 확장자 화이트리스트를 그대로 받는다 — 신규 확장자를 열지 않는다.
|
||||
*
|
||||
* @scenario custom_source=convention_scan, custom_asset=static_file
|
||||
*
|
||||
* @effects custom_disallowed_extension_blocked
|
||||
*/
|
||||
public function test_blocks_disallowed_file_type_under_custom(): void
|
||||
{
|
||||
// Arrange
|
||||
mkdir($this->testModulePath.'/custom', 0755, true);
|
||||
file_put_contents($this->testModulePath.'/custom/notes.txt', 'not an asset');
|
||||
|
||||
// Act
|
||||
$response = $this->getJson('/api/modules/assets/test-module/custom/notes.txt');
|
||||
|
||||
// Assert: FormRequest 의 확장자 게이트가 거부한다 (422)
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('path');
|
||||
$this->assertStringNotContainsString('not an asset', $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* `custom/` 자산도 ETag 로 304 를 돌려준다 — 운영자 파일이라고 캐시 계약이 다르지 않다.
|
||||
*
|
||||
* @scenario custom_source=convention_scan, custom_asset=css
|
||||
*
|
||||
* @effects custom_asset_url_busts_on_file_change
|
||||
*/
|
||||
public function test_returns_304_for_custom_asset_when_etag_matches(): void
|
||||
{
|
||||
// Arrange
|
||||
mkdir($this->testModulePath.'/custom', 0755, true);
|
||||
file_put_contents($this->testModulePath.'/custom/custom.css', '.operator { color: red; }');
|
||||
|
||||
$first = $this->get('/api/modules/assets/test-module/custom/custom.css');
|
||||
$first->assertStatus(200);
|
||||
|
||||
$etag = $first->headers->get('ETag');
|
||||
$this->assertNotNull($etag, 'custom 자산에도 ETag 가 있어야 한다');
|
||||
|
||||
// Act
|
||||
$second = $this->get(
|
||||
'/api/modules/assets/test-module/custom/custom.css',
|
||||
['If-None-Match' => $etag]
|
||||
);
|
||||
|
||||
// Assert
|
||||
$second->assertStatus(304);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user