공개 제보 — 파일 스토리지에서 S3 를 선택해 저장해도 실제 파일 저장이 동작하지 않던 결함의 전면 수정. - S3 어댑터(league/flysystem-aws-s3-v3)·predis 를 코어 기본 의존성으로 포함 — 어댑터 부재 즉사, phpredis 확장 없는 서버의 redis 선택 전면 다운 차단 (부트 시 확장 부재 감지 → predis 자동 폴백) - storage_driver=s3 저장 시 코어 첨부 업로드 디스크를 s3 로 전환 (ATTACHMENT_DISK env 명시가 항상 우선, 기존 행은 저장 당시 disk 로 서빙) - 첨부·템플릿 레이아웃 첨부 서빙을 행 disk 를 따르는 스토리지 스트림으로 교체 — 로컬 절대 경로 전제 fileResponse 는 S3 행에서 filemtime stat 500 (streamedFileResponse: 행 메타 기반 ETag/304/Cache-Control) - S3 호환 스토리지(R2/MinIO/NCP) 연결 지원: 엔드포인트 URL·path-style 설정 신설, 리전 목록 선택 → 자유 입력 전환, 연결 테스트를 실제 저장 경로와 동일 설정(endpoint/path-style)으로 정렬 - 사용 불능 드라이버(어댑터·PHP 확장 부재)의 저장/테스트 요청을 사유와 함께 422 로 차단하는 서버 게이트 신설 (DriverRegistryService 능력 판정) - 웹소켓 연결 테스트에 서버(백엔드 발송용) endpoint 검사 추가 — 클라이언트만 검사해 테스트 성공 + 실제 발송 실패가 가능하던 비대칭 해소 - env 빈 값(`KEY=`) 함정 정규화: AWS_URL/AWS_ENDPOINT/ATTACHMENT_DISK 빈 문자열을 미설정으로 취급 (config 정규화 + 예시 파일 주석 처리) - 플러그인 드라이버 폴백의 log 카테고리 죽은 키(logging.default) 정정 및 websocket 유령 설정 키 제거 - 실 AWS S3 종단 검증 완료 (설정 저장 → 업로드 S3 실저장 → 서빙 200/304)
125 lines
4.3 KiB
PHP
125 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services;
|
|
|
|
use App\Contracts\Extension\StorageInterface;
|
|
use App\Contracts\Repositories\TemplateLayoutAttachmentRepositoryInterface;
|
|
use App\Contracts\Repositories\TemplateRepositoryInterface;
|
|
use App\Models\Template;
|
|
use App\Models\TemplateLayoutAttachment;
|
|
use App\Services\TemplateLayoutAttachmentService;
|
|
use Mockery;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* 템플릿 레이아웃 첨부 디스크 인지 서빙 테스트 (공개 #99 / 내부 #563)
|
|
*
|
|
* PublicAttachmentController 이미지 서빙과 동형 결함 — getServableFilePath 가
|
|
* getBasePath 로 로컬 절대 경로를 조립해 S3 디스크 행에서 fileResponse(filemtime)가
|
|
* 500 이 나던 구조의 회귀 가드. 서빙은 StorageInterface::response() 스트림으로
|
|
* 디스크 무관하게 성립해야 한다.
|
|
*/
|
|
class TemplateLayoutAttachmentServingTest extends TestCase
|
|
{
|
|
private TemplateLayoutAttachmentService $service;
|
|
|
|
private $templateRepository;
|
|
|
|
private $storage;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$repository = Mockery::mock(TemplateLayoutAttachmentRepositoryInterface::class);
|
|
$this->templateRepository = Mockery::mock(TemplateRepositoryInterface::class);
|
|
$this->storage = Mockery::mock(StorageInterface::class);
|
|
|
|
$this->service = new TemplateLayoutAttachmentService(
|
|
$repository,
|
|
$this->templateRepository,
|
|
$this->storage
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 소속 템플릿 첨부를 만듭니다 (DB 미저장).
|
|
*/
|
|
private function makeAttachment(int $templateId, string $disk = 's3'): TemplateLayoutAttachment
|
|
{
|
|
$attachment = new TemplateLayoutAttachment([
|
|
'layout_name' => 'home',
|
|
'disk' => $disk,
|
|
'path' => 'sirsoft-basic/home/bg.png',
|
|
'original_name' => 'bg.png',
|
|
'mime_type' => 'image/png',
|
|
'size' => 70,
|
|
]);
|
|
$attachment->template_id = $templateId;
|
|
|
|
return $attachment;
|
|
}
|
|
|
|
/**
|
|
* s3 디스크 행이 StorageInterface::response() 스트림으로 서빙 정보를 반환해야 합니다.
|
|
*
|
|
* @scenario region_shape=aws_region,endpoint=absent,driver_usability=adapter_present,attachment_disk=follow_s3
|
|
*
|
|
* @effects attachment_upload_follows_driver
|
|
*/
|
|
public function test_s3_disk_attachment_returns_streamed_response(): void
|
|
{
|
|
$template = new Template;
|
|
$template->id = 7;
|
|
$this->templateRepository->shouldReceive('findByIdentifier')
|
|
->with('sirsoft-basic')->andReturn($template);
|
|
|
|
$stream = new StreamedResponse(function () {
|
|
echo 'bytes';
|
|
}, 200, ['Content-Type' => 'image/png']);
|
|
|
|
$this->storage->shouldReceive('withDisk')->with('s3')->andReturnSelf();
|
|
$this->storage->shouldReceive('response')->andReturn($stream);
|
|
|
|
$result = $this->service->getServableResponse('sirsoft-basic', $this->makeAttachment(7));
|
|
|
|
$this->assertNotNull($result);
|
|
$this->assertSame($stream, $result['response']);
|
|
$this->assertNotEmpty($result['etag_source']);
|
|
}
|
|
|
|
/**
|
|
* 경로 템플릿과 첨부 소속이 다르면 null 이어야 합니다 (교차 템플릿 접근 차단 유지).
|
|
*/
|
|
public function test_cross_template_access_returns_null(): void
|
|
{
|
|
$template = new Template;
|
|
$template->id = 7;
|
|
$this->templateRepository->shouldReceive('findByIdentifier')
|
|
->with('sirsoft-basic')->andReturn($template);
|
|
|
|
$result = $this->service->getServableResponse('sirsoft-basic', $this->makeAttachment(99));
|
|
|
|
$this->assertNull($result);
|
|
}
|
|
|
|
/**
|
|
* 스토리지에 파일이 없으면(response null) null 이어야 합니다.
|
|
*/
|
|
public function test_missing_file_returns_null(): void
|
|
{
|
|
$template = new Template;
|
|
$template->id = 7;
|
|
$this->templateRepository->shouldReceive('findByIdentifier')
|
|
->with('sirsoft-basic')->andReturn($template);
|
|
|
|
$this->storage->shouldReceive('withDisk')->with('s3')->andReturnSelf();
|
|
$this->storage->shouldReceive('response')->andReturnNull();
|
|
|
|
$result = $this->service->getServableResponse('sirsoft-basic', $this->makeAttachment(7));
|
|
|
|
$this->assertNull($result);
|
|
}
|
|
}
|