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
@@ -0,0 +1,286 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Installer;
|
||||
|
||||
use App\Support\PrivilegedDatabaseAccounts;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* 인스톨러 DB 최고권한 계정 차단 회귀 테스트
|
||||
*
|
||||
* 배경: 인스톨러에는 사용자명 검증이 전무했고, `.env.example` fallback 기본값이
|
||||
* `DB_WRITE_USERNAME=root` 였다. 그 결과 root 로 설치하면 설치는 성공하지만
|
||||
* 이후 코어 부팅이 확장 로딩 전체를 스킵해 깨진 화면만 남았다.
|
||||
* 설치 단계에서 미리 차단하는지 보장한다.
|
||||
*
|
||||
* 검증 축:
|
||||
* - Step 3 폼 POST 검증: Write DB / Read DB 양쪽, 최고권한 / 빈 값 / 정상
|
||||
* - 인스톨러가 코어와 같은 판정 SSoT 를 공유하는지 (목록 이원화 차단)
|
||||
* - 다국어 키 존재 및 :username 치환 동작 (ko/en)
|
||||
*/
|
||||
class PrivilegedDbAccountGuardTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
if (! defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__, 3));
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__, 3).'/public/install/includes/config.php';
|
||||
require_once dirname(__DIR__, 3).'/public/install/includes/functions.php';
|
||||
require_once dirname(__DIR__, 3).'/public/install/includes/request-handler.php';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// lang() 은 전역 $translations 를 읽는다 (functions.php:316).
|
||||
$GLOBALS['translations'] = require dirname(__DIR__, 3).'/public/install/lang/ko.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* config.php 가 코어의 판정 SSoT 클래스를 로드해야 한다.
|
||||
* 인스톨러가 자체 목록을 갖게 되면 코어와 판정이 어긋난다.
|
||||
*
|
||||
* @effects installer_and_core_share_the_same_judgement_class
|
||||
*/
|
||||
public function test_installer_loads_shared_judgement_class(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
class_exists(PrivilegedDatabaseAccounts::class),
|
||||
'config.php 가 PrivilegedDatabaseAccounts 를 로드하지 않았습니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 3 폼 POST 에서 Write DB 최고권한 계정이 거부되어야 한다.
|
||||
*
|
||||
* @scenario account_kind=privileged, enforcement_point=installer_step3_write, install_state=not_completed
|
||||
*
|
||||
* @effects installer_step3_post_rejects_privileged_username
|
||||
*/
|
||||
#[DataProvider('privilegedUsernameProvider')]
|
||||
public function test_step3_rejects_privileged_write_username(string $username): void
|
||||
{
|
||||
$errors = [];
|
||||
validateDbUsername($username, 'db_write_username', $errors);
|
||||
|
||||
$this->assertArrayHasKey(
|
||||
'db_write_username',
|
||||
$errors,
|
||||
sprintf('사용자명 "%s" 이 거부되지 않았습니다.', $username)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read DB 도 동일하게 차단되어야 한다 (Write 만 막으면 Read 로 우회 가능).
|
||||
*
|
||||
* @scenario account_kind=privileged, enforcement_point=installer_step3_read, install_state=not_completed
|
||||
*
|
||||
* @effects installer_step3_post_rejects_privileged_username
|
||||
*/
|
||||
#[DataProvider('privilegedUsernameProvider')]
|
||||
public function test_step3_rejects_privileged_read_username(string $username): void
|
||||
{
|
||||
$errors = [];
|
||||
validateDbUsername($username, 'db_read_username', $errors);
|
||||
|
||||
$this->assertArrayHasKey('db_read_username', $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* 빈 사용자명(설정 누락)도 Write DB 에서 거부되어야 한다.
|
||||
*
|
||||
* @scenario account_kind=empty, enforcement_point=installer_step3_write, install_state=not_completed
|
||||
*
|
||||
* @effects installer_step3_post_rejects_empty_username
|
||||
*/
|
||||
#[DataProvider('emptyUsernameProvider')]
|
||||
public function test_step3_rejects_empty_write_username(string $username): void
|
||||
{
|
||||
$errors = [];
|
||||
validateDbUsername($username, 'db_write_username', $errors);
|
||||
|
||||
$this->assertArrayHasKey('db_write_username', $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* 빈 사용자명은 Read DB 에서도 거부되어야 한다.
|
||||
*
|
||||
* @scenario account_kind=empty, enforcement_point=installer_step3_read, install_state=not_completed
|
||||
*
|
||||
* @effects installer_step3_post_rejects_empty_username
|
||||
*/
|
||||
#[DataProvider('emptyUsernameProvider')]
|
||||
public function test_step3_rejects_empty_read_username(string $username): void
|
||||
{
|
||||
$errors = [];
|
||||
validateDbUsername($username, 'db_read_username', $errors);
|
||||
|
||||
$this->assertArrayHasKey('db_read_username', $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string}>
|
||||
*/
|
||||
public static function privilegedUsernameProvider(): array
|
||||
{
|
||||
return [
|
||||
'root' => ['root'],
|
||||
'postgres' => ['postgres'],
|
||||
'sa' => ['sa'],
|
||||
'sys' => ['sys'],
|
||||
'system' => ['system'],
|
||||
'대문자 ROOT (우회 차단)' => ['ROOT'],
|
||||
'앞뒤 공백 " root " (우회 차단)' => [' root '],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string}>
|
||||
*/
|
||||
public static function emptyUsernameProvider(): array
|
||||
{
|
||||
return [
|
||||
'빈 문자열' => [''],
|
||||
'공백만' => [' '],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 정상 계정은 Write DB 에서 통과해야 한다 — 특히 `admin` 오차단 방지.
|
||||
*
|
||||
* @scenario account_kind=normal, enforcement_point=installer_step3_write, install_state=not_completed
|
||||
*
|
||||
* @effects installer_step3_post_accepts_normal_username
|
||||
*/
|
||||
#[DataProvider('acceptedUsernameProvider')]
|
||||
public function test_step3_accepts_normal_write_username(string $username): void
|
||||
{
|
||||
$errors = [];
|
||||
validateDbUsername($username, 'db_write_username', $errors);
|
||||
|
||||
$this->assertSame(
|
||||
[],
|
||||
$errors,
|
||||
sprintf('정상 사용자명 "%s" 이 잘못 거부됐습니다.', $username)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 정상 계정은 Read DB 에서도 통과해야 한다 (과잉 차단 방지).
|
||||
*
|
||||
* @scenario account_kind=normal, enforcement_point=installer_step3_read, install_state=not_completed
|
||||
*
|
||||
* @effects installer_step3_post_accepts_normal_username
|
||||
*/
|
||||
#[DataProvider('acceptedUsernameProvider')]
|
||||
public function test_step3_accepts_normal_read_username(string $username): void
|
||||
{
|
||||
$errors = [];
|
||||
validateDbUsername($username, 'db_read_username', $errors);
|
||||
|
||||
$this->assertSame([], $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string}>
|
||||
*/
|
||||
public static function acceptedUsernameProvider(): array
|
||||
{
|
||||
return [
|
||||
'g7user' => ['g7user'],
|
||||
'admin (일반 권한 계정 오차단 방지)' => ['admin'],
|
||||
'rootuser' => ['rootuser'],
|
||||
'g7_root' => ['g7_root'],
|
||||
'my_site_db' => ['my_site_db'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 빈 값과 최고권한 계정은 서로 다른 메시지여야 한다 — 운영자가 원인을 구분해야 한다.
|
||||
*
|
||||
* @effects empty_and_privileged_produce_distinct_messages
|
||||
*/
|
||||
public function test_empty_and_privileged_produce_different_messages(): void
|
||||
{
|
||||
$emptyErrors = [];
|
||||
validateDbUsername('', 'db_write_username', $emptyErrors);
|
||||
|
||||
$privilegedErrors = [];
|
||||
validateDbUsername('root', 'db_write_username', $privilegedErrors);
|
||||
|
||||
$this->assertNotSame(
|
||||
$emptyErrors['db_write_username'],
|
||||
$privilegedErrors['db_write_username']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 차단 메시지는 입력한 계정명을 치환해 보여줘야 한다 (:username).
|
||||
*
|
||||
* @effects installer_message_substitutes_username_and_offers_alternative
|
||||
*/
|
||||
public function test_privileged_message_substitutes_username(): void
|
||||
{
|
||||
$errors = [];
|
||||
validateDbUsername('postgres', 'db_write_username', $errors);
|
||||
|
||||
$message = $errors['db_write_username'];
|
||||
|
||||
$this->assertStringContainsString('postgres', $message);
|
||||
$this->assertStringNotContainsString(':username', $message, '치환되지 않은 플레이스홀더가 남아 있습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 차단만 하고 해결책이 없으면 사용자가 진행 불가 상태에 갇힌다.
|
||||
* ko/en 양쪽 문구가 대안(전용 계정 생성)을 제시하는지 확인한다.
|
||||
*/
|
||||
#[DataProvider('localeProvider')]
|
||||
public function test_message_offers_an_alternative(string $locale, string $needle): void
|
||||
{
|
||||
$translations = require dirname(__DIR__, 3)."/public/install/lang/{$locale}.php";
|
||||
|
||||
$this->assertArrayHasKey('error_db_username_privileged', $translations);
|
||||
$this->assertStringContainsString($needle, $translations['error_db_username_privileged']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string, 1: string}>
|
||||
*/
|
||||
public static function localeProvider(): array
|
||||
{
|
||||
return [
|
||||
'ko' => ['ko', '전용 데이터베이스 사용자'],
|
||||
'en' => ['en', 'dedicated database user'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* OPcache 관련 다국어 키가 ko/en 양쪽에 존재해야 한다 (요구사항 카드 렌더용).
|
||||
*
|
||||
* @effects installer_opcache_lang_keys_exist_in_ko_and_en
|
||||
*/
|
||||
#[DataProvider('opcacheLocaleProvider')]
|
||||
public function test_opcache_lang_keys_exist(string $locale): void
|
||||
{
|
||||
$translations = require dirname(__DIR__, 3)."/public/install/lang/{$locale}.php";
|
||||
|
||||
foreach (['opcache', 'opcache_enabled', 'opcache_disabled_short', 'opcache_disabled_warning', 'opcache_unknown'] as $key) {
|
||||
$this->assertArrayHasKey($key, $translations, sprintf('%s 로케일에 %s 키가 없습니다.', $locale, $key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string}>
|
||||
*/
|
||||
public static function opcacheLocaleProvider(): array
|
||||
{
|
||||
return [
|
||||
'ko' => ['ko'],
|
||||
'en' => ['en'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use App\Support\OpcacheStatus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* OPcache 상태 판정 SSoT 단위 테스트
|
||||
*
|
||||
* 인스톨러(요구사항 화면)와 코어(관리자 정보 탭)가 같은 답을 내야 하므로,
|
||||
* 이 클래스는 Laravel 부트 없이 동작해야 한다. 본 테스트가
|
||||
* `PHPUnit\Framework\TestCase` 를 직접 상속하는 것은 그 "의존성 0" 속성을
|
||||
* 검증하기 위함이다.
|
||||
*
|
||||
* 검증 축:
|
||||
* - 확장 미로드 → enabled=false (확인 불가 아님)
|
||||
* - 확장 로드 + opcache.enable=1 → enabled=true
|
||||
* - 확장 로드 + opcache.enable=0 → enabled=false (로드만으로 판정하면 안 되는 케이스)
|
||||
* - 확장 로드 + ini_get 차단(disable_functions) → enabled=null (확인 불가)
|
||||
*/
|
||||
class OpcacheStatusTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @scenario opcache_state=not_loaded, surface=judgement_ssot
|
||||
*
|
||||
* @effects not_loaded_reports_disabled_not_unknown
|
||||
*/
|
||||
public function test_extension_not_loaded_reports_disabled(): void
|
||||
{
|
||||
$result = OpcacheStatus::probe(
|
||||
extensionLoaded: fn () => false,
|
||||
iniGet: fn () => $this->fail('확장 미로드 시 ini_get 을 호출하면 안 됩니다.'),
|
||||
);
|
||||
|
||||
$this->assertSame(['loaded' => false, 'enabled' => false], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @scenario opcache_state=enabled, surface=judgement_ssot
|
||||
*
|
||||
* @effects on_off_directive_values_parsed
|
||||
*/
|
||||
public function test_loaded_and_enabled_reports_enabled(): void
|
||||
{
|
||||
$result = OpcacheStatus::probe(
|
||||
extensionLoaded: fn (string $name) => $name === OpcacheStatus::EXTENSION_NAME,
|
||||
iniGet: fn () => '1',
|
||||
);
|
||||
|
||||
$this->assertSame(['loaded' => true, 'enabled' => true], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 확장이 로드돼 있어도 opcache.enable=0 이면 실제로는 동작하지 않는다.
|
||||
* 확장 로드 여부만으로 판정하는 회귀를 차단한다.
|
||||
*
|
||||
* @scenario opcache_state=loaded_but_disabled, surface=judgement_ssot
|
||||
*
|
||||
* @effects loaded_but_disabled_directive_reports_disabled
|
||||
*/
|
||||
public function test_loaded_but_disabled_directive_reports_disabled(): void
|
||||
{
|
||||
$result = OpcacheStatus::probe(
|
||||
extensionLoaded: fn () => true,
|
||||
iniGet: fn () => '0',
|
||||
);
|
||||
|
||||
$this->assertSame(['loaded' => true, 'enabled' => false], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* ini_get 이 disable_functions 로 차단돼 Error 를 던지는 환경.
|
||||
* 경고도 차단도 아닌 "확인 불가"(null) 로 폴백해야 한다.
|
||||
*
|
||||
* @scenario opcache_state=ini_get_blocked, surface=judgement_ssot
|
||||
*
|
||||
* @effects ini_get_blocked_reports_unknown_null
|
||||
*/
|
||||
public function test_ini_get_blocked_reports_unknown(): void
|
||||
{
|
||||
$result = OpcacheStatus::probe(
|
||||
extensionLoaded: fn () => true,
|
||||
iniGet: fn () => throw new \Error('Call to undefined function ini_get()'),
|
||||
);
|
||||
|
||||
$this->assertSame(['loaded' => true, 'enabled' => null], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* ini_get 은 지시자를 못 읽으면 false 를 반환한다. 값 '0'(비활성 확정) 과
|
||||
* 구분해 "확인 불가" 로 처리해야 한다.
|
||||
*
|
||||
* @effects ini_get_false_distinguished_from_value_zero
|
||||
*/
|
||||
public function test_ini_get_returning_false_reports_unknown(): void
|
||||
{
|
||||
$result = OpcacheStatus::probe(
|
||||
extensionLoaded: fn () => true,
|
||||
iniGet: fn () => false,
|
||||
);
|
||||
|
||||
$this->assertSame(['loaded' => true, 'enabled' => null], $result);
|
||||
}
|
||||
|
||||
public function test_ini_get_returning_empty_string_reports_unknown(): void
|
||||
{
|
||||
$result = OpcacheStatus::probe(
|
||||
extensionLoaded: fn () => true,
|
||||
iniGet: fn () => '',
|
||||
);
|
||||
|
||||
$this->assertSame(['loaded' => true, 'enabled' => null], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* php.ini 는 On/Off 표기도 허용한다.
|
||||
*/
|
||||
public function test_on_off_directive_values_are_parsed(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
OpcacheStatus::probe(fn () => true, fn () => 'On')['enabled']
|
||||
);
|
||||
$this->assertFalse(
|
||||
OpcacheStatus::probe(fn () => true, fn () => 'Off')['enabled']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 인수 없이 호출해도 예외 없이 계약된 구조를 반환해야 한다
|
||||
* (실행 환경의 실제 OPcache 상태와 무관하게 형태만 검증).
|
||||
*/
|
||||
public function test_default_probe_returns_contracted_shape(): void
|
||||
{
|
||||
$result = OpcacheStatus::probe();
|
||||
|
||||
$this->assertArrayHasKey('loaded', $result);
|
||||
$this->assertArrayHasKey('enabled', $result);
|
||||
$this->assertIsBool($result['loaded']);
|
||||
$this->assertTrue($result['enabled'] === null || is_bool($result['enabled']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 인스톨러가 Laravel 오토로드 없이 `require_once` 로 로드할 수 있어야 하므로,
|
||||
* 소스에 프레임워크 심볼 참조가 없어야 한다.
|
||||
*/
|
||||
public function test_source_has_no_framework_dependency(): void
|
||||
{
|
||||
$source = file_get_contents(dirname(__DIR__, 3).'/app/Support/OpcacheStatus.php');
|
||||
|
||||
$this->assertIsString($source);
|
||||
|
||||
foreach (['use Illuminate', 'Illuminate\\', 'config(', 'app(', '__(', 'trans('] as $forbidden) {
|
||||
$this->assertStringNotContainsString(
|
||||
$forbidden,
|
||||
$source,
|
||||
sprintf('인스톨러 공용 클래스에 프레임워크 의존("%s")이 포함됐습니다.', $forbidden)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use App\Support\PrivilegedDatabaseAccounts;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* DB 최고권한 계정 판정 SSoT 단위 테스트
|
||||
*
|
||||
* 인스톨러와 코어가 같은 판정을 내려야 하므로, 이 클래스는 Laravel 부트 없이
|
||||
* 동작해야 한다. 본 테스트가 `PHPUnit\Framework\TestCase` 를 직접 상속하는 것은
|
||||
* 그 "의존성 0" 속성 자체를 검증하기 위함이다 (Tests\TestCase 사용 금지).
|
||||
*
|
||||
* 검증 축:
|
||||
* - 계정 종류: 최고권한(root/postgres/sa/sys/system) / 일반 / 빈 값 / null
|
||||
* - 표기 변형: 대문자 / 앞뒤 공백 (우회 차단)
|
||||
* - isBlocked 와 isUsable 의 책임 분리 (빈 값은 blocked 아님, 그러나 usable 도 아님)
|
||||
*/
|
||||
class PrivilegedDatabaseAccountsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 최고권한 계정 판정 — 대문자·앞뒤 공백 변형까지 정규화해 차단한다.
|
||||
*
|
||||
* @scenario account_kind=privileged, enforcement_point=judgement_ssot, install_state=completed
|
||||
*
|
||||
* @effects privileged_account_detected_case_and_whitespace_insensitive
|
||||
* @effects admin_account_not_blocked
|
||||
*/
|
||||
#[DataProvider('blockedProvider')]
|
||||
public function test_is_blocked_detects_privileged_accounts(?string $username, bool $expected): void
|
||||
{
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
PrivilegedDatabaseAccounts::isBlocked($username),
|
||||
sprintf('isBlocked(%s) 판정이 기대와 다릅니다.', var_export($username, true))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string|null, 1: bool}>
|
||||
*/
|
||||
public static function blockedProvider(): array
|
||||
{
|
||||
return [
|
||||
'root 차단' => ['root', true],
|
||||
'postgres 차단' => ['postgres', true],
|
||||
'sa 차단' => ['sa', true],
|
||||
'sys 차단' => ['sys', true],
|
||||
'system 차단' => ['system', true],
|
||||
'대문자 ROOT 차단' => ['ROOT', true],
|
||||
'혼합 대소문자 RoOt 차단' => ['RoOt', true],
|
||||
'앞뒤 공백 " root " 차단' => [' root ', true],
|
||||
'탭 문자 포함 차단' => ["\troot\n", true],
|
||||
'일반 계정 g7user 통과' => ['g7user', false],
|
||||
'admin 은 차단 대상 아님 (오차단 방지)' => ['admin', false],
|
||||
'root 를 포함한 다른 이름 통과' => ['rootuser', false],
|
||||
'g7_root 통과' => ['g7_root', false],
|
||||
'빈 문자열은 blocked 아님' => ['', false],
|
||||
'공백만 있는 문자열은 blocked 아님' => [' ', false],
|
||||
'null 은 blocked 아님' => [null, false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용 가능 여부 판정 — 빈 값(설정 누락)과 정상 계정을 구분한다.
|
||||
*
|
||||
* @scenario account_kind=empty, enforcement_point=judgement_ssot, install_state=completed
|
||||
*
|
||||
* @effects empty_username_rejected_as_unusable
|
||||
*/
|
||||
#[DataProvider('usableProvider')]
|
||||
public function test_is_usable_rejects_privileged_and_empty(?string $username, bool $expected): void
|
||||
{
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
PrivilegedDatabaseAccounts::isUsable($username),
|
||||
sprintf('isUsable(%s) 판정이 기대와 다릅니다.', var_export($username, true))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string|null, 1: bool}>
|
||||
*/
|
||||
public static function usableProvider(): array
|
||||
{
|
||||
return [
|
||||
'일반 계정 g7user 사용 가능' => ['g7user', true],
|
||||
'admin 사용 가능 (오차단 방지)' => ['admin', true],
|
||||
'rootuser 사용 가능' => ['rootuser', true],
|
||||
'숫자 문자열 0 도 유효한 계정명' => ['0', true],
|
||||
'root 사용 불가' => ['root', false],
|
||||
'ROOT 사용 불가' => ['ROOT', false],
|
||||
' root 사용 불가' => [' root ', false],
|
||||
'postgres 사용 불가' => ['postgres', false],
|
||||
'빈 문자열 사용 불가 (설정 누락)' => ['', false],
|
||||
'공백만 있는 문자열 사용 불가' => [' ', false],
|
||||
'null 사용 불가 (설정 누락)' => [null, false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 목록이 상수 1곳에서만 관리되는지 — 판정이 BLOCKED 상수와 어긋나면 실패한다.
|
||||
*
|
||||
* @scenario account_kind=normal, enforcement_point=judgement_ssot, install_state=completed
|
||||
*
|
||||
* @effects normal_username_accepted
|
||||
*/
|
||||
public function test_every_blocked_constant_entry_is_actually_blocked(): void
|
||||
{
|
||||
$this->assertNotEmpty(PrivilegedDatabaseAccounts::BLOCKED);
|
||||
|
||||
foreach (PrivilegedDatabaseAccounts::BLOCKED as $account) {
|
||||
$this->assertSame(
|
||||
strtolower($account),
|
||||
$account,
|
||||
sprintf('BLOCKED 항목 "%s" 는 소문자로 정의되어야 비교가 성립합니다.', $account)
|
||||
);
|
||||
$this->assertTrue(PrivilegedDatabaseAccounts::isBlocked($account));
|
||||
$this->assertFalse(PrivilegedDatabaseAccounts::isUsable($account));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `admin` 은 차단 대상이 아니다.
|
||||
*
|
||||
* 목록에 `admin` 을 넣으면 일반 권한으로 운영 중인 `admin` 계정 사용자가
|
||||
* 업그레이드 직후 에러 페이지에 갇힌다. 이 오차단을 구조적으로 고정한다.
|
||||
*
|
||||
* @effects admin_account_not_blocked
|
||||
*/
|
||||
public function test_admin_is_not_a_blocked_account(): void
|
||||
{
|
||||
$this->assertNotContains('admin', PrivilegedDatabaseAccounts::BLOCKED);
|
||||
$this->assertFalse(PrivilegedDatabaseAccounts::isBlocked('admin'));
|
||||
$this->assertTrue(PrivilegedDatabaseAccounts::isUsable('admin'));
|
||||
$this->assertTrue(PrivilegedDatabaseAccounts::isUsable('ADMIN'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 인스톨러가 Laravel 오토로드 없이 `require_once` 로 로드할 수 있어야 하므로,
|
||||
* 소스에 프레임워크 심볼 참조가 없어야 한다.
|
||||
*/
|
||||
public function test_source_has_no_framework_dependency(): void
|
||||
{
|
||||
$source = file_get_contents(
|
||||
dirname(__DIR__, 3).'/app/Support/PrivilegedDatabaseAccounts.php'
|
||||
);
|
||||
|
||||
$this->assertIsString($source);
|
||||
|
||||
foreach (['use Illuminate', 'Illuminate\\', 'config(', 'app(', '__(', 'trans('] as $forbidden) {
|
||||
$this->assertStringNotContainsString(
|
||||
$forbidden,
|
||||
$source,
|
||||
sprintf('인스톨러 공용 클래스에 프레임워크 의존("%s")이 포함됐습니다.', $forbidden)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user