feat(core,board,ecommerce,page,ckeditor5,kginicis): 업로드 이미지 축소·로그인 2단계 인증 도입 + 파생 결함 수정
인터뷰에서 방향만 정하고 남겨 뒀던 후속 5건을 구현하고, 커밋 전 종합 점검에서 발견한 결함 2건을 함께 고쳤다. 기능 도입: - 업로드 이미지 축소 — `upload.image_max_width` / `image_max_height` / `image_quality` 는 저장·검증만 되고 리사이즈 코드가 0건이었다. 비율 유지, 상한 이내면 재인코딩하지 않음(불필요한 화질 손실 방지), 한계 미설정이면 무동작(기존 사이트 이미지 보호). PNG·GIF·WebP 투명도 보존. 실패해도 업로드는 계속되고 원본이 저장된다. - 로그인 2단계 인증 — `security.two_factor_auth` 는 설정 항목만 있고 구현도 화면 컨트롤도 없었다. 코어 IDV 인프라를 재사용해 purpose `login` 을 추가하고, 비밀번호 확인 통과 후 challenge 만 발행한다(토큰 미발급 + logout). `POST /api/auth/login/two-factor` 가 코드를 확인해야 토큰이 나가며, 로그인과 같은 요청 제한을 적용한다. challenge 의 purpose 를 대조해 다른 흐름의 challenge 로 로그인하는 것을 막는다. 코드 발송이 실패하면 실패로 알린다 — 2단계를 건너뛰고 로그인시키면 통제가 조용히 열린다. 결함 수정: - 게시글 수정 시 사용자 경로가 `attachment_ids` 를 Service 로 넘기지 않아, 검증과 권한은 통과하고 200 을 받는데 첨부만 조용히 연결되지 않았다. 관리자 경로는 넘기고 있어 같은 요청이 화면에 따라 다르게 동작했다. - 설정 화면 라디오가 `pointer-events-none` + Label click 으로만 상태를 바꿔, 키보드 방향키(change) 조작 시 화면 표시와 저장될 값이 어긋났다. 동일 패턴 4개 레이아웃 12개 라디오에 change 액션을 부여하고 params 를 click 과 동일하게 고정한다. - 주문완료 화면이 결제수단 확인보다 영수증 조회를 앞세워, PG 를 거치지 않는 주문에서도 매번 404 요청이 나갔다. - 개별 게시판 폼의 숫자 항목에 경계값 바인딩이 없어 환경설정 화면과 안내가 달랐다. 커밋 전 점검에서 발견: - 2단계 인증이 반쪽으로 들어가 있었다. enum 에 case 만 추가하고 코어 purpose 레지스트리와 ko/en 라벨을 빠뜨려, 목적 목록 API 에서 통째로 빠지고 `hasPurpose` 가 false 였으며 라벨 대신 i18n 키 원문이 반환됐다. 관리자가 이 목적의 메시지 템플릿·정책을 만들 수 없는 상태였다. 세 곳을 enum 기준으로 전수 대조하는 회귀 테스트를 함께 둔다. - 업로드 이미지 축소가 적용되지 않은 8번째 서비스(레이아웃 편집기 첨부)가 있었다. 열거형 커버리지 테스트는 내 조사 결과를 green 으로 고정할 뿐 전수를 증명하지 못한다 — 같은 규약을 조건으로 표현한 audit 룰이 첫 실행에서 검출했다. 재발 방지: - audit 룰 `upload-service-image-resize` (신규 업로드 서비스의 축소 누락 검출) - 트러블슈팅 사례 20 (코어 설정이 일부 경로에만 적용되는 증상의 진단 절차) - `sirsoft-ckeditor5` 의 코어 최소 요구 버전을 7.0.6 으로 상향 (신설 클래스 의존) 공개 이슈: gnuboard/g7
This commit is contained in:
1 parent
d17ea28da5
commit
7b56d5f23a
72 files changed
+2024
-99
No files matched your search
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Enums\IdentityVerificationPurpose;
|
||||
use App\Enums\UserStatus;
|
||||
use App\Models\IdentityVerificationLog;
|
||||
use App\Models\User;
|
||||
use App\Services\IdentityVerificationService;
|
||||
use Database\Seeders\IdentityMessageDefinitionSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 로그인 2단계 인증 테스트
|
||||
*
|
||||
* `security.two_factor_auth` 는 설정 화면에만 있고 구현이 없어, 켜도 아무 일도 일어나지
|
||||
* 않았습니다. 관리자는 2단계 인증이 걸린 줄 알지만 실제로는 비밀번호 하나로 로그인됩니다.
|
||||
*
|
||||
* 코어 본인인증(IDV) 인프라를 재사용하며, 이 흐름의 불변조건은 하나입니다 —
|
||||
* **코드 확인을 마치기 전에는 토큰이 발급되지 않는다.**
|
||||
*/
|
||||
class TwoFactorAuthTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Mail::fake();
|
||||
|
||||
// 인증번호 메일을 구성하려면 본인인증 메시지 정의가 있어야 한다. 실제 설치에는 있고
|
||||
// RefreshDatabase 직후에는 비어 있으므로, 없는 상태를 그대로 두면 "코드 발송 실패" 가 되어
|
||||
// 게이트 동작이 아니라 시드 부재를 측정하게 된다.
|
||||
$this->seed(IdentityMessageDefinitionSeeder::class);
|
||||
|
||||
$this->user = User::factory()->create([
|
||||
'email' => 'two-factor@test.com',
|
||||
'password' => Hash::make('Passw0rd!2fa'),
|
||||
'status' => UserStatus::Active->value,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2단계 인증 설정을 켜거나 끕니다.
|
||||
*
|
||||
* @param bool $enabled 활성화 여부
|
||||
*/
|
||||
private function setTwoFactor(bool $enabled): void
|
||||
{
|
||||
config(['g7_settings.core.security.two_factor_auth' => $enabled]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 로그인을 시도합니다.
|
||||
*
|
||||
* @return TestResponse 로그인 응답
|
||||
*/
|
||||
private function login()
|
||||
{
|
||||
return $this->postJson('/api/auth/login', [
|
||||
'email' => 'two-factor@test.com',
|
||||
'password' => 'Passw0rd!2fa',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function login_issues_a_token_directly_when_two_factor_is_off(): void
|
||||
{
|
||||
$this->setTwoFactor(false);
|
||||
|
||||
$response = $this->login();
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertNotEmpty($response->json('data.token'), '2단계 인증이 꺼져 있으면 종전대로 바로 로그인되어야 합니다.');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function login_withholds_the_token_when_two_factor_is_on(): void
|
||||
{
|
||||
$this->setTwoFactor(true);
|
||||
|
||||
$response = $this->login();
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$this->assertTrue(
|
||||
(bool) $response->json('data.two_factor_required'),
|
||||
'2단계 인증이 켜져 있는데 추가 확인 없이 응답했습니다.'
|
||||
);
|
||||
$this->assertNull(
|
||||
$response->json('data.token'),
|
||||
'코드 확인 전에 토큰이 발급되면 2단계 인증이 없는 것과 같습니다.'
|
||||
);
|
||||
$this->assertNotEmpty($response->json('data.challenge_id'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function verifying_the_challenge_completes_the_login(): void
|
||||
{
|
||||
$this->setTwoFactor(true);
|
||||
|
||||
$challengeId = $this->login()->json('data.challenge_id');
|
||||
|
||||
$response = $this->postJson('/api/auth/login/two-factor', [
|
||||
'challenge_id' => $challengeId,
|
||||
'code' => $this->issuedCode($challengeId),
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertNotEmpty($response->json('data.token'), '코드 확인에 성공했는데 토큰이 발급되지 않았습니다.');
|
||||
$this->assertSame('two-factor@test.com', $response->json('data.user.email'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function a_wrong_code_does_not_issue_a_token(): void
|
||||
{
|
||||
$this->setTwoFactor(true);
|
||||
|
||||
$challengeId = $this->login()->json('data.challenge_id');
|
||||
|
||||
$response = $this->postJson('/api/auth/login/two-factor', [
|
||||
'challenge_id' => $challengeId,
|
||||
'code' => '000000',
|
||||
]);
|
||||
|
||||
$response->assertStatus(401);
|
||||
$this->assertNull($response->json('data.token'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function a_challenge_issued_for_another_purpose_cannot_be_used_to_log_in(): void
|
||||
{
|
||||
$this->setTwoFactor(true);
|
||||
|
||||
// 가입·비밀번호 재설정 등 다른 용도로 발급된 challenge 를 들고 와 로그인할 수 있으면,
|
||||
// 그 흐름 하나만 통과해도 남의 계정에 들어갈 수 있다.
|
||||
$foreign = app(IdentityVerificationService::class)->start(
|
||||
IdentityVerificationPurpose::PasswordReset->value,
|
||||
$this->user,
|
||||
['origin_type' => 'route', 'origin_identifier' => 'test']
|
||||
);
|
||||
|
||||
$response = $this->postJson('/api/auth/login/two-factor', [
|
||||
'challenge_id' => $foreign->id,
|
||||
'code' => $this->issuedCode($foreign->id),
|
||||
]);
|
||||
|
||||
$response->assertStatus(401);
|
||||
$this->assertNull($response->json('data.token'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function login_fails_clearly_when_the_code_cannot_be_delivered(): void
|
||||
{
|
||||
$this->setTwoFactor(true);
|
||||
|
||||
// 메일 발송이 실패하면 프로바이더가 challenge 를 failed 로 표시한다. 그 상태를 무시하면
|
||||
// 사용자는 "인증번호를 보냈습니다" 안내를 받고 완료할 수 없는 challenge 를 들고 막힌다.
|
||||
Mail::shouldReceive('send')->andThrow(new \RuntimeException('SMTP unavailable'));
|
||||
Mail::shouldReceive('to')->andThrow(new \RuntimeException('SMTP unavailable'));
|
||||
|
||||
$response = $this->login();
|
||||
|
||||
$response->assertStatus(401);
|
||||
$this->assertNull(
|
||||
$response->json('data.token'),
|
||||
'발송 실패 시 2단계 인증을 건너뛰고 로그인시키면 보안 통제가 조용히 열립니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* challenge 에 알려진 인증 코드를 심고 그 값을 돌려줍니다.
|
||||
*
|
||||
* 발급된 코드는 해시로만 저장되므로 되읽을 수 없습니다. 기존 IDV 테스트와 같은 방식으로
|
||||
* 알려진 값의 해시를 심어 "코드가 맞을 때" 를 재현합니다 — 검증 대상은 코드 생성이 아니라
|
||||
* 로그인 게이트(코드 확인 전 토큰 미발급 / 확인 후 발급)입니다.
|
||||
*
|
||||
* @param string $challengeId challenge UUID
|
||||
* @return string 심어 둔 인증 코드
|
||||
*/
|
||||
private function issuedCode(string $challengeId): string
|
||||
{
|
||||
$code = '135790';
|
||||
|
||||
$log = IdentityVerificationLog::find($challengeId);
|
||||
$metadata = $log->metadata ?? [];
|
||||
$metadata['code_hash'] = Hash::make($code);
|
||||
|
||||
$log->metadata = $metadata;
|
||||
$log->save();
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Identity;
|
||||
|
||||
use App\Enums\IdentityVerificationPurpose;
|
||||
use App\Extension\IdentityVerification\IdentityVerificationManager;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 코어 purpose 계약 정합성 테스트
|
||||
*
|
||||
* 코어 purpose 는 세 곳에 동시에 존재해야 온전히 동작합니다.
|
||||
*
|
||||
* 1. `IdentityVerificationPurpose` enum — 코드에서 참조하는 값
|
||||
* 2. `IdentityVerificationManager::$corePurposes` — 관리자 화면·API 가 읽는 목록
|
||||
* 3. `lang/{ko,en}/identity.php` 의 `purposes.{value}` — 사람이 읽는 라벨
|
||||
*
|
||||
* 실측(2026-07-29): 2단계 인증을 도입하며 enum 에 `login` 만 추가하고 2·3 을 빠뜨렸다.
|
||||
* 그 결과 `hasPurpose('login')` 이 false 였고, `getAllPurposes()` 에서 빠져 관리자가
|
||||
* 이 목적의 메시지 템플릿·정책을 만들 수 없었으며, `Login->label()` 은 라벨 대신
|
||||
* `identity.purposes.login.label` 이라는 i18n 키 원문을 그대로 돌려줬다.
|
||||
*
|
||||
* 셋 중 하나만 빠져도 조용히 반쪽 동작하므로 값 목록을 하드코딩하지 않고
|
||||
* enum 을 기준으로 나머지 둘을 전수 대조한다 — 새 purpose 를 추가하면 자동으로 검사 대상이 된다.
|
||||
*/
|
||||
class CorePurposeRegistryParityTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function every_core_purpose_is_registered_in_the_manager(): void
|
||||
{
|
||||
$registered = array_keys(app(IdentityVerificationManager::class)->getAllPurposes());
|
||||
|
||||
foreach (IdentityVerificationPurpose::values() as $purpose) {
|
||||
$this->assertContains(
|
||||
$purpose,
|
||||
$registered,
|
||||
"purpose '{$purpose}' 가 corePurposes 레지스트리에 없습니다 — 관리자가 이 목적의 메시지 템플릿·정책을 만들 수 없습니다."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function every_core_purpose_answers_true_to_has_purpose(): void
|
||||
{
|
||||
$manager = app(IdentityVerificationManager::class);
|
||||
|
||||
foreach (IdentityVerificationPurpose::values() as $purpose) {
|
||||
$this->assertTrue(
|
||||
$manager->hasPurpose($purpose),
|
||||
"hasPurpose('{$purpose}') 가 false 입니다 — 코어 purpose 인데 등록되지 않은 것으로 취급됩니다."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function every_core_purpose_resolves_a_label_and_description_in_each_base_locale(): void
|
||||
{
|
||||
foreach (['ko', 'en'] as $locale) {
|
||||
$this->app->setLocale($locale);
|
||||
|
||||
foreach (IdentityVerificationPurpose::cases() as $case) {
|
||||
foreach (['label', 'description'] as $field) {
|
||||
$key = "identity.purposes.{$case->value}.{$field}";
|
||||
$translated = __($key);
|
||||
|
||||
$this->assertNotSame(
|
||||
$key,
|
||||
$translated,
|
||||
"[{$locale}] {$key} 번역이 없습니다 — 화면에 i18n 키 원문이 그대로 노출됩니다."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestWith;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 업로드 이미지 축소 적용 범위 테스트
|
||||
*
|
||||
* 최대 가로/세로·품질은 **코어 환경설정**이므로 특정 화면이 아니라 업로드 전 경로에
|
||||
* 적용되어야 합니다. 코어 첨부만 고치면 게시판·페이지·상품 이미지는 원본 그대로 저장되어,
|
||||
* 관리자 입장에서는 "설정을 켰는데 어떤 업로드는 줄고 어떤 업로드는 안 준다" 가 됩니다.
|
||||
*
|
||||
* 실측(2026-07-29): 코어 서비스만 적용한 상태에서 게시판 글쓰기로 2400x1800 을 올렸더니
|
||||
* 2400x1800 그대로 저장됐다 — 게시판 첨부는 코어 AttachmentService 를 거치지 않는다.
|
||||
*
|
||||
* 파일을 저장하는 업로드 서비스가 새로 생기면 이 목록에 추가해야 합니다.
|
||||
*/
|
||||
class ImageResizeCoverageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 업로드 파일을 디스크에 저장하는 서비스 전수.
|
||||
*
|
||||
* @param string $relativePath 검사 대상 서비스 경로
|
||||
*/
|
||||
#[Test]
|
||||
#[TestWith(['app/Services/AttachmentService.php'])]
|
||||
#[TestWith(['app/Services/TemplateLayoutAttachmentService.php'])]
|
||||
#[TestWith(['modules/_bundled/sirsoft-board/src/Services/AttachmentService.php'])]
|
||||
#[TestWith(['modules/_bundled/sirsoft-page/src/Services/PageAttachmentService.php'])]
|
||||
#[TestWith(['modules/_bundled/sirsoft-ecommerce/src/Services/ProductImageService.php'])]
|
||||
#[TestWith(['modules/_bundled/sirsoft-ecommerce/src/Services/CategoryImageService.php'])]
|
||||
#[TestWith(['modules/_bundled/sirsoft-ecommerce/src/Services/ProductReviewImageService.php'])]
|
||||
#[TestWith(['plugins/_bundled/sirsoft-ckeditor5/src/Services/ImageUploadService.php'])]
|
||||
public function every_upload_service_applies_the_configured_image_bounds(string $relativePath): void
|
||||
{
|
||||
$path = base_path($relativePath);
|
||||
|
||||
$this->assertFileExists($path);
|
||||
|
||||
$source = $this->stripComments(file_get_contents($path));
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'resizeInPlace',
|
||||
$source,
|
||||
"{$relativePath}: 업로드 이미지 축소가 적용되지 않았습니다 — 이 경로로 올린 이미지는 환경설정 상한을 무시합니다."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주석을 제거한 소스를 반환합니다.
|
||||
*
|
||||
* 설명 주석에 등장하는 호출 표기가 검사를 통과시키는 것을 막습니다.
|
||||
*
|
||||
* @param string $source 원본 소스
|
||||
* @return string 주석이 제거된 소스
|
||||
*/
|
||||
private function stripComments(string $source): string
|
||||
{
|
||||
$stripped = '';
|
||||
|
||||
foreach (token_get_all($source) as $token) {
|
||||
if (is_array($token) && in_array($token[0], [T_COMMENT, T_DOC_COMMENT], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stripped .= is_array($token) ? $token[1] : $token;
|
||||
}
|
||||
|
||||
return $stripped;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use App\Services\AttachmentService;
|
||||
use App\Support\ImageResizer;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 업로드 이미지 리사이즈 테스트
|
||||
*
|
||||
* 환경설정 > 업로드의 최대 가로/세로 크기와 품질은 저장·검증만 되고 실제로 이미지를 줄이는
|
||||
* 코드가 없었습니다. 관리자는 값을 바꾸면 적용된다고 인지하지만 원본이 그대로 저장됐습니다.
|
||||
*/
|
||||
class ImageResizerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 지정 크기의 임시 PNG 를 만듭니다.
|
||||
*
|
||||
* @param int $width 가로 픽셀
|
||||
* @param int $height 세로 픽셀
|
||||
* @return string 생성된 파일 경로
|
||||
*/
|
||||
private function makeImage(int $width, int $height): string
|
||||
{
|
||||
$path = tempnam(sys_get_temp_dir(), 'g7img').'.png';
|
||||
$image = imagecreatetruecolor($width, $height);
|
||||
imagefill($image, 0, 0, imagecolorallocate($image, 10, 120, 200));
|
||||
imagepng($image, $path);
|
||||
imagedestroy($image);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일의 가로·세로를 반환합니다.
|
||||
*
|
||||
* @param string $path 이미지 경로
|
||||
* @return array{0:int,1:int} [가로, 세로]
|
||||
*/
|
||||
private function dimensions(string $path): array
|
||||
{
|
||||
$size = getimagesize($path);
|
||||
|
||||
return [(int) $size[0], (int) $size[1]];
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_shrinks_an_image_that_exceeds_the_configured_bounds(): void
|
||||
{
|
||||
config(['attachment.image_max_width' => 800, 'attachment.image_max_height' => 600, 'attachment.image_quality' => 80]);
|
||||
|
||||
$path = $this->makeImage(1600, 1200);
|
||||
|
||||
$this->assertTrue(app(ImageResizer::class)->resizeInPlace($path, 'image/png'));
|
||||
|
||||
[$width, $height] = $this->dimensions($path);
|
||||
|
||||
$this->assertSame(800, $width);
|
||||
// 비율 유지 — 1600x1200 을 800 폭에 맞추면 600
|
||||
$this->assertSame(600, $height);
|
||||
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_keeps_aspect_ratio_when_only_one_side_exceeds(): void
|
||||
{
|
||||
config(['attachment.image_max_width' => 1000, 'attachment.image_max_height' => 1000, 'attachment.image_quality' => 80]);
|
||||
|
||||
$path = $this->makeImage(2000, 500);
|
||||
|
||||
$this->assertTrue(app(ImageResizer::class)->resizeInPlace($path, 'image/png'));
|
||||
|
||||
[$width, $height] = $this->dimensions($path);
|
||||
|
||||
$this->assertSame(1000, $width);
|
||||
$this->assertSame(250, $height);
|
||||
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_leaves_images_within_bounds_untouched(): void
|
||||
{
|
||||
config(['attachment.image_max_width' => 1000, 'attachment.image_max_height' => 1000]);
|
||||
|
||||
$path = $this->makeImage(400, 300);
|
||||
$before = md5_file($path);
|
||||
|
||||
$this->assertFalse(
|
||||
app(ImageResizer::class)->resizeInPlace($path, 'image/png'),
|
||||
'한계 이내 이미지는 다시 인코딩하지 않아야 합니다 — 불필요한 화질 손실을 만듭니다.'
|
||||
);
|
||||
$this->assertSame($before, md5_file($path));
|
||||
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_does_nothing_when_no_limit_is_configured(): void
|
||||
{
|
||||
config(['attachment.image_max_width' => null, 'attachment.image_max_height' => null]);
|
||||
|
||||
$path = $this->makeImage(4000, 3000);
|
||||
$before = md5_file($path);
|
||||
|
||||
$this->assertFalse(app(ImageResizer::class)->resizeInPlace($path, 'image/png'));
|
||||
$this->assertSame($before, md5_file($path));
|
||||
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_ignores_non_image_files(): void
|
||||
{
|
||||
config(['attachment.image_max_width' => 100, 'attachment.image_max_height' => 100]);
|
||||
|
||||
$path = tempnam(sys_get_temp_dir(), 'g7doc').'.txt';
|
||||
file_put_contents($path, str_repeat('a', 500));
|
||||
$before = md5_file($path);
|
||||
|
||||
$this->assertFalse(app(ImageResizer::class)->resizeInPlace($path, 'text/plain'));
|
||||
$this->assertSame($before, md5_file($path));
|
||||
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function upload_applies_the_configured_bounds(): void
|
||||
{
|
||||
config(['attachment.image_max_width' => 640, 'attachment.image_max_height' => 640, 'attachment.image_quality' => 75]);
|
||||
|
||||
$path = $this->makeImage(1280, 960);
|
||||
$upload = new UploadedFile($path, 'large.png', 'image/png', null, true);
|
||||
|
||||
$attachment = app(AttachmentService::class)->upload($upload);
|
||||
|
||||
$this->assertSame(640, $attachment->meta['width'] ?? null, '저장된 첨부의 가로가 설정 상한을 넘습니다 — 리사이즈가 업로드 경로에 적용되지 않았습니다.');
|
||||
$this->assertSame(480, $attachment->meta['height'] ?? null);
|
||||
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user