Files
Gnuboard7/plugins/_bundled/sirsoft-verification_nhnkcp/tests/Feature/Identity/KcpTestModeBirthdayFallbackTest.php
T
HeuJung bd215bc586 feat(identity): NHN KCP 휴대폰 본인확인 플러그인 추가
메일 인증 대신 휴대폰 본인확인을 쓸 수 있게 하는 플러그인을 추가한다.
가입·비밀번호 재설정·성인인증 등 코어 IDV 가 강제하는 모든 지점에서 동작하며,
테스트 모드로 계약 없이 전 흐름을 확인할 수 있다.

구현·검수 과정에서 드러난 저장소 전역 결함을 함께 처리했다.

- 외래키 컬럼의 한국어 comment 가 방출되지 않던 문제 (소스 38건 교정 +
 기설치본 백필 업그레이드 스텝 7종). ->comment 를 ->constrained 뒤에
 체인하면 예외 없이 통과하면서 comment 가 조용히 사라진다
- 로케일 전환 후 확장 액션 핸들러가 소실되던 문제 (플러그인 3종에
 재등록 진입점 노출)
- 본인인증 상태 폴링 응답이 누적 시도 횟수를 함께 내보내던 문제
- 인증 안내 문구와 실제 진행 방식의 폭 경계 불일치 (768~1023px).
 엔진과 같은 값을 같은 방법으로 읽도록 교정
- transition_overlay_target 이 replace 없이 무효이던 관리자 목록 40곳.
 로딩 표시가 나오지 않아도 경고가 남지 않아 화면을 봐야만 알 수 있었다

두 인증 플러그인의 코어 최소 요구 버전을 7.0.6 으로 올린다. 운영 모드
자격증명 필수 검사가 7.0.6 의 설정 저장 검증 표면에 의존하며, 그보다 낮은
코어에서는 그 검사가 조용히 통과해 빈 자격증명으로 저장할 수 있었다.

재발 차단으로 정적 검사 룰 4종을 신설하고, 검사 도구가 미커밋 신규 확장을
"검사 파일 0" 으로 통과시키던 사각을 함께 막았다.
2026-07-31 00:32:46 +09:00

171 lines
6.8 KiB
PHP

<?php
namespace Plugins\Sirsoft\VerificationNhnkcp\Tests\Feature\Identity;
use App\Contracts\Repositories\IdentityVerificationLogRepositoryInterface;
use App\Enums\IdentityOriginType;
use App\Enums\IdentityVerificationStatus;
use App\Models\IdentityVerificationLog;
use App\Models\User;
use Illuminate\Support\Str;
use Plugins\Sirsoft\VerificationNhnkcp\Identity\KcpIdentityProvider;
use Plugins\Sirsoft\VerificationNhnkcp\Repositories\KcpIdentityRecordRepositoryInterface;
use Plugins\Sirsoft\VerificationNhnkcp\Tests\PluginTestCase;
/**
* 테스트 모드에서 생년월일이 빠진 응답 처리 검증.
*
* KCP 규격상 `birth_day` 는 조건 없이 항상 내려오는 표준 필드지만(공식 "본인확인 결과 복호화"
* 표), KCP 테스트 서버는 실제 통신사 조회를 수행하지 않아 생년월일·성별·내외국인을 빈 값으로
* 응답한다. 운영과 동일하게 거절하면 테스트 환경에서는 어떤 방법으로도 인증을 완주할 수 없어
* 검수가 불가능해진다.
*
* 따라서 테스트 모드에서만 생년월일 부재를 허용하고, 운영 모드의 판정은 그대로 유지한다.
* 생년월일을 못 받으면 성인 여부는 계산할 수 없으므로 성인인증 목적은 계속 막는다.
*
* @since 1.0.0
*/
class KcpTestModeBirthdayFallbackTest extends PluginTestCase
{
private IdentityVerificationLogRepositoryInterface $logRepository;
protected function setUp(): void
{
parent::setUp();
$this->logRepository = app(IdentityVerificationLogRepositoryInterface::class);
}
/**
* @scenario mode=test,birth_day=absent,purpose=general
*
* @effects test_mode_accepts_response_without_birthday
*/
public function test_test_mode_accepts_missing_birthday(): void
{
$log = $this->createPendingLog(User::factory()->create()->id, 'self_update');
$result = $this->provider(true)->verify($log->id, $this->certData(''));
$this->assertTrue($result->success, '테스트 모드에서는 생년월일 없이도 본인확인을 인정해야 한다');
$this->assertNotEmpty($result->claims['verification_token'] ?? null);
$this->assertTrue($this->logRepository->findById($log->id)->isVerified());
}
/**
* @scenario mode=live,birth_day=absent,purpose=general
*
* @effects live_mode_rejects_response_without_birthday
*/
public function test_live_mode_still_rejects_missing_birthday(): void
{
$log = $this->createPendingLog(User::factory()->create()->id, 'self_update');
$result = $this->provider(false)->verify($log->id, $this->certData(''));
$this->assertFalse($result->success, '운영 모드에서 생년월일 부재는 비정상 응답이다');
$this->assertSame('INCOMPLETE_IDENTITY', $result->failureCode);
}
/**
* 생년월일 외 신원 핵심값은 테스트 모드에서도 완화하지 않는다. CI/DI 가 비면 중복가입 차단이
* 조용히 무력화되므로 어느 모드에서도 인정해서는 안 된다.
*
* @scenario mode=test,birth_day=absent,purpose=general
*
* @effects test_mode_still_rejects_missing_identity_values
*/
public function test_test_mode_does_not_relax_other_identity_values(): void
{
$log = $this->createPendingLog(User::factory()->create()->id, 'self_update');
$payload = array_merge($this->certData(''), ['di' => '']);
$result = $this->provider(true)->verify($log->id, $payload);
$this->assertFalse($result->success);
$this->assertSame('INCOMPLETE_IDENTITY', $result->failureCode);
}
/**
* 생년월일이 없으면 저장된 record 의 생년월일은 비어 있고 성인 여부는 참이 될 수 없다.
* 마이페이지는 이 상태를 "미성년" 이 아니라 "확인 불가" 로 표시해야 하므로, 저장 단계에서
* 두 상태가 구분 가능해야 한다.
*
* @scenario mode=test,birth_day=absent,purpose=general
*
* @effects missing_birthday_stored_as_null_with_adult_false
*/
public function test_record_keeps_birthday_null_when_absent(): void
{
$user = User::factory()->create();
$log = $this->createPendingLog($user->id, 'self_update');
$this->provider(true)->verify($log->id, $this->certData(''));
$record = app(KcpIdentityRecordRepositoryInterface::class)->findByUserId($user->id);
$this->assertNotNull($record, '인증이 인정되었으면 record 가 생성되어야 한다');
$this->assertNull($record->birthday_encrypted, '생년월일 미제공은 빈 암호문이 아니라 null 로 남는다');
$this->assertFalse((bool) $record->is_adult, '생년월일을 모르면 성인으로 단정하지 않는다');
}
/**
* @param bool $isTestMode 테스트 모드 여부
*/
private function provider(bool $isTestMode): KcpIdentityProvider
{
return app()->makeWith(KcpIdentityProvider::class, [
'config' => ['duplicate_field' => 'di', 'is_test_mode' => $isTestMode],
]);
}
/**
* KCP 테스트 서버 응답 형태 — 생년월일·성별·내외국인이 빈 값으로 내려온다.
*
* @param string $birthday YYYYMMDD (빈 문자열이면 미제공)
* @return array<string, mixed>
*/
private function certData(string $birthday): array
{
return [
'res_cd' => '0000',
'res_msg' => '정상처리',
'user_name' => '홍길동',
'birth_day' => $birthday,
'phone_no' => '01012345678',
'comm_id' => 'SKT',
'sex_code' => '',
'local_code' => '',
'ci' => 'CI-'.Str::random(10),
'di' => 'DI-'.Str::random(10),
];
}
/**
* 인증 대기 상태의 challenge 로그를 만든다.
*
* @param int $userId 사용자 ID
* @param string $purpose IDV purpose
*/
private function createPendingLog(int $userId, string $purpose): IdentityVerificationLog
{
return $this->logRepository->create([
'id' => (string) Str::uuid(),
'provider_id' => KcpIdentityProvider::PROVIDER_ID,
'purpose' => $purpose,
'channel' => KcpIdentityProvider::CHANNEL,
'user_id' => $userId,
'target_hash' => hash('sha256', 'birthday-fallback@example.com'),
'status' => IdentityVerificationStatus::Sent->value,
'render_hint' => 'text_code',
'attempts' => 0,
'max_attempts' => 0,
'origin_type' => IdentityOriginType::Route->value,
'origin_identifier' => 'api.identity.verify',
'verification_token' => null,
'expires_at' => now()->addMinutes(15),
'metadata' => ['ordr_idxx' => 'G7-'.Str::random(8)],
]);
}
}