feat(core): DB 최고권한 계정 차단 + OPcache 상태 안내
설치 단계와 코어 부팅의 정책이 엇갈려 있었다. 인스톨러는 root 를 자유롭게 허용하면서, 설치 후 부팅은 같은 값을 보고 확장 로딩 전체를 조용히 스킵했다. 설치는 성공하지만 이후 깨진 화면만 뜨고 원인은 로그 한 줄에만 남았다. 판정을 프레임워크 의존성 0 인 공용 SSoT 로 모아 인스톨러와 코어가 같은 답을 내게 하고, 설치 단계에서 서버 2경로로 차단하며, 설치 후 변경은 전용 에러 페이지로 드러낸다. 가드를 boot 가 아닌 미들웨어에 두어 artisan 이 죽지 않게 해 복구 수단을 남겼다. admin 은 일반 권한 운영 계정 오차단을 막기 위해 차단 목록에서 제외했다. OPcache 는 상태 조회 경로 자체가 없어 성능 저하를 인지할 방법이 없었다. 설치 단계 경고(비차단)와 관리자 정보 탭 표시를 같은 판정 SSoT 로 추가했다. 확장 로드 여부만으로는 부족해 opcache.enable 지시자까지 확인하며, ini_get 이 차단된 환경은 "확인 불가"로 폴백해 경고도 차단도 하지 않는다.
This commit is contained in:
1 parent
91ec5f2d1f
commit
062a88ca04
38 files changed
+2402
-56
No files matched your search
@@ -14,6 +14,7 @@ use App\Services\SettingsService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -1490,6 +1491,150 @@ class SettingsControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* OPcache 상태가 시스템 정보 페이로드에 포함된다.
|
||||
*
|
||||
* 관리자 환경설정 > 정보 탭이 이 값으로 상태 행과 성능 저하 경고 블록을 렌더한다.
|
||||
* enabled 는 true/false 외에 null("확인 불가" — ini_get 차단 환경)을 가질 수 있다.
|
||||
*
|
||||
* @scenario probe_item=opcache,probe_outcome=success,auth_state=authenticated_with_permission
|
||||
*
|
||||
* @effects opcache_status_exposed_in_system_info
|
||||
*/
|
||||
public function test_system_info_includes_opcache_status(): void
|
||||
{
|
||||
$cache = $this->app->make(CacheInterface::class);
|
||||
$cache->forget('settings.system_info.'.app()->getLocale());
|
||||
|
||||
$response = $this->authRequest()->getJson('/api/admin/settings/system-info');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
'data' => [
|
||||
'opcache' => ['loaded', 'enabled'],
|
||||
],
|
||||
]);
|
||||
|
||||
$opcache = $response->json('data.opcache');
|
||||
|
||||
$this->assertIsBool($opcache['loaded']);
|
||||
$this->assertTrue(
|
||||
$opcache['enabled'] === null || is_bool($opcache['enabled']),
|
||||
'opcache.enabled 는 true/false/null 중 하나여야 합니다.'
|
||||
);
|
||||
}
|
||||
|
||||
// 아래 test_system_info_reports_each_opcache_state 의 DataProvider 가 함께 검증하는
|
||||
// 나머지 3개 조합 (docblock 은 @scenario 를 1건만 인식하므로 라인 주석으로 병기).
|
||||
// @scenario opcache_state=loaded_but_disabled, surface=system_info_api
|
||||
// @effects opcache_status_exposed_in_system_info
|
||||
// @scenario opcache_state=not_loaded, surface=system_info_api
|
||||
// @effects opcache_status_exposed_in_system_info
|
||||
// @scenario opcache_state=ini_get_blocked, surface=system_info_api
|
||||
// @effects opcache_status_exposed_in_system_info
|
||||
|
||||
/**
|
||||
* OPcache 판정 결과가 API 페이로드에 그대로 실려 나온다.
|
||||
*
|
||||
* 관리자 정보 탭이 이 값으로 상태 행과 경고 블록을 렌더하므로, 네 가지 상태가
|
||||
* 각각 구별되어 전달되어야 한다. 특히 loaded_but_disabled(확장은 로드됐으나
|
||||
* opcache.enable=0)와 ini_get_blocked(null)이 뭉개지면 화면 판단이 무너진다.
|
||||
*
|
||||
* @scenario opcache_state=enabled, surface=system_info_api
|
||||
*
|
||||
* @effects opcache_status_exposed_in_system_info
|
||||
*/
|
||||
#[DataProvider('opcacheStateProvider')]
|
||||
public function test_system_info_reports_each_opcache_state(array $probe): void
|
||||
{
|
||||
$cache = $this->app->make(CacheInterface::class);
|
||||
$cache->forget('settings.system_info.'.app()->getLocale());
|
||||
|
||||
$service = new class($this->app, $probe) extends SettingsService
|
||||
{
|
||||
private array $stub;
|
||||
|
||||
public function __construct($app, array $stub)
|
||||
{
|
||||
parent::__construct(
|
||||
$app->make(ConfigRepositoryInterface::class),
|
||||
$app->make(AttachmentRepositoryInterface::class),
|
||||
$app->make(CacheInterface::class),
|
||||
);
|
||||
$this->stub = $stub;
|
||||
}
|
||||
|
||||
protected function getOpcacheStatus(): array
|
||||
{
|
||||
return $this->stub;
|
||||
}
|
||||
};
|
||||
$this->app->instance(SettingsService::class, $service);
|
||||
|
||||
$response = $this->authRequest()->getJson('/api/admin/settings/system-info');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertSame($probe, $response->json('data.opcache'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: array{loaded: bool, enabled: bool|null}}>
|
||||
*/
|
||||
public static function opcacheStateProvider(): array
|
||||
{
|
||||
return [
|
||||
'enabled' => [['loaded' => true, 'enabled' => true]],
|
||||
'loaded_but_disabled' => [['loaded' => true, 'enabled' => false]],
|
||||
'not_loaded' => [['loaded' => false, 'enabled' => false]],
|
||||
'ini_get_blocked' => [['loaded' => true, 'enabled' => null]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* OPcache probe 가 실패해도 격리되어 전체 200 이 유지된다.
|
||||
*
|
||||
* ini_get 이 disable_functions 로 차단된 호스팅에서 probe 하나가 죽어
|
||||
* system-info API 전체가 500 이 나는 것을 방지한다.
|
||||
*
|
||||
* @scenario probe_item=opcache,probe_outcome=throws_error,auth_state=authenticated_with_permission
|
||||
*
|
||||
* @effects failing_probe_isolated_and_api_returns_200
|
||||
* @effects failed_item_filled_with_unknown_fallback
|
||||
*/
|
||||
public function test_system_info_isolates_failing_opcache_probe(): void
|
||||
{
|
||||
$cache = $this->app->make(CacheInterface::class);
|
||||
$cache->forget('settings.system_info.'.app()->getLocale());
|
||||
|
||||
$service = new class($this->app) extends SettingsService
|
||||
{
|
||||
public function __construct($app)
|
||||
{
|
||||
parent::__construct(
|
||||
$app->make(ConfigRepositoryInterface::class),
|
||||
$app->make(AttachmentRepositoryInterface::class),
|
||||
$app->make(CacheInterface::class),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getOpcacheStatus(): array
|
||||
{
|
||||
throw new \Error('Call to undefined function ini_get() (disable_functions)');
|
||||
}
|
||||
};
|
||||
$this->app->instance(SettingsService::class, $service);
|
||||
|
||||
$response = $this->authRequest()->getJson('/api/admin/settings/system-info');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'opcache' => ['loaded' => false, 'enabled' => null],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용량 조회 실패 시 폴백 배열 구조 검증: unknownUsage 는 total/used/free 를
|
||||
* 'unknown' 으로, percentage 를 0 으로 채워 memory_usage·disk_usage 형식을 유지한다.
|
||||
|
||||
Reference in new issue
Block a user