메일 인증 대신 휴대폰 본인확인을 쓸 수 있게 하는 플러그인을 추가한다. 가입·비밀번호 재설정·성인인증 등 코어 IDV 가 강제하는 모든 지점에서 동작하며, 테스트 모드로 계약 없이 전 흐름을 확인할 수 있다. 구현·검수 과정에서 드러난 저장소 전역 결함을 함께 처리했다. - 외래키 컬럼의 한국어 comment 가 방출되지 않던 문제 (소스 38건 교정 + 기설치본 백필 업그레이드 스텝 7종). ->comment 를 ->constrained 뒤에 체인하면 예외 없이 통과하면서 comment 가 조용히 사라진다 - 로케일 전환 후 확장 액션 핸들러가 소실되던 문제 (플러그인 3종에 재등록 진입점 노출) - 본인인증 상태 폴링 응답이 누적 시도 횟수를 함께 내보내던 문제 - 인증 안내 문구와 실제 진행 방식의 폭 경계 불일치 (768~1023px). 엔진과 같은 값을 같은 방법으로 읽도록 교정 - transition_overlay_target 이 replace 없이 무효이던 관리자 목록 40곳. 로딩 표시가 나오지 않아도 경고가 남지 않아 화면을 봐야만 알 수 있었다 두 인증 플러그인의 코어 최소 요구 버전을 7.0.6 으로 올린다. 운영 모드 자격증명 필수 검사가 7.0.6 의 설정 저장 검증 표면에 의존하며, 그보다 낮은 코어에서는 그 검사가 조용히 통과해 빈 자격증명으로 저장할 수 있었다. 재발 차단으로 정적 검사 룰 4종을 신설하고, 검사 도구가 미커밋 신규 확장을 "검사 파일 0" 으로 통과시키던 사각을 함께 막았다.
185 lines
7.1 KiB
PHP
185 lines
7.1 KiB
PHP
<?php
|
|
|
|
namespace Plugins\Sirsoft\VerificationNhnkcp\Tests\Feature\Identity;
|
|
|
|
use App\Models\IdentityVerificationLog;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Plugins\Sirsoft\VerificationNhnkcp\Exceptions\RemoteCallException;
|
|
use Plugins\Sirsoft\VerificationNhnkcp\Identity\KcpIdentityProvider;
|
|
use Plugins\Sirsoft\VerificationNhnkcp\Models\KcpCertTransaction;
|
|
use Plugins\Sirsoft\VerificationNhnkcp\Support\KcpIdentityHasher;
|
|
use Plugins\Sirsoft\VerificationNhnkcp\Tests\PluginTestCase;
|
|
|
|
/**
|
|
* challenge 발행(거래등록) 검증.
|
|
*
|
|
* 거래등록이 성공해야만 challenge 를 발행한다 — 실패 시 "열 수 없는 인증창" 을 위한 로그 행이
|
|
* 남지 않아야 한다. 성공 시 표준창 호출 정보가 프론트에 전달되고, 거래키는 해시 인덱스 +
|
|
* 암호문으로만 저장된다 (평문 컬럼 부재).
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
class KcpRequestChallengeTest extends PluginTestCase
|
|
{
|
|
private const TEST_CONFIG = [
|
|
'is_test_mode' => true,
|
|
'test_site_cd' => 'AO7F3',
|
|
'test_enc_key' => 'c2a22fa3ebe4698075bcac6b433d52e351c881b02fb83488d4283a43385b1f8e',
|
|
];
|
|
|
|
/**
|
|
* @scenario mode=test,kcp_response=success
|
|
*
|
|
* @effects challenge_issued_with_call_url_and_reg_cert_key
|
|
*/
|
|
public function test_successful_registration_issues_challenge_with_standard_window_payload(): void
|
|
{
|
|
$this->fakeRegistration('0000');
|
|
|
|
$user = User::factory()->create();
|
|
$challenge = $this->provider()->requestChallenge($user, ['purpose' => 'self_update']);
|
|
|
|
$this->assertSame(KcpIdentityProvider::PROVIDER_ID, $challenge->providerId);
|
|
$this->assertSame('phone', $challenge->channel);
|
|
$this->assertSame('https://testcert.kcp.co.kr/certGateway.do', $challenge->publicPayload['call_url']);
|
|
$this->assertSame('CERTKEY000000001', $challenge->publicPayload['reg_cert_key']);
|
|
$this->assertTrue($challenge->publicPayload['is_test_mode']);
|
|
$this->assertSame(hash('sha256', mb_strtolower($user->email)), $challenge->targetHash);
|
|
|
|
$log = IdentityVerificationLog::query()->whereKey($challenge->id)->first();
|
|
$this->assertNotNull($log);
|
|
$this->assertSame('sent', $log->status->value);
|
|
$this->assertSame((int) $user->id, (int) $log->user_id);
|
|
}
|
|
|
|
/**
|
|
* @scenario mode=test,kcp_response=success
|
|
*
|
|
* @effects transaction_row_stores_hashed_and_encrypted_reg_cert_key
|
|
*/
|
|
public function test_transaction_row_stores_key_as_hash_and_ciphertext_only(): void
|
|
{
|
|
$this->fakeRegistration('0000');
|
|
|
|
$challenge = $this->provider()->requestChallenge(['email' => 'guest@example.test'], ['purpose' => 'signup']);
|
|
|
|
$transaction = KcpCertTransaction::query()->where('challenge_id', $challenge->id)->first();
|
|
$this->assertNotNull($transaction);
|
|
$this->assertSame(
|
|
KcpIdentityHasher::hashRegCertKey('CERTKEY000000001'),
|
|
$transaction->reg_cert_key_hash,
|
|
'거래키는 조회용 keyed-hash 로만 인덱싱되어야 한다',
|
|
);
|
|
$this->assertNotSame('CERTKEY000000001', $transaction->reg_cert_key_encrypted, '평문 보관 금지');
|
|
$this->assertSame('CERTKEY000000001', Crypt::decryptString($transaction->reg_cert_key_encrypted));
|
|
$this->assertSame($challenge->metadata['ordr_idxx'], $transaction->ordr_idxx);
|
|
$this->assertNull($transaction->consumed_at);
|
|
}
|
|
|
|
/**
|
|
* @scenario mode=test,kcp_response=res_cd_error
|
|
*
|
|
* @effects res_cd_error_raises_remote_call_exception_without_challenge_row
|
|
*/
|
|
public function test_rejected_registration_does_not_create_any_row(): void
|
|
{
|
|
$this->fakeRegistration('8133', '가맹점 정보가 올바르지 않습니다.');
|
|
|
|
try {
|
|
$this->provider()->requestChallenge(['email' => 'guest@example.test'], ['purpose' => 'signup']);
|
|
$this->fail('거래등록 거절 시 예외가 발생해야 한다');
|
|
} catch (RemoteCallException $e) {
|
|
$this->assertStringContainsString('8133', $e->detail);
|
|
}
|
|
|
|
$this->assertSame(0, IdentityVerificationLog::query()->count(), 'challenge 로그가 남으면 안 된다');
|
|
$this->assertSame(0, KcpCertTransaction::query()->count(), '거래 행이 남으면 안 된다');
|
|
}
|
|
|
|
/**
|
|
* @scenario mode=test,kcp_response=http_error
|
|
*
|
|
* @effects http_error_raises_remote_call_exception_without_challenge_row
|
|
*/
|
|
public function test_communication_failure_does_not_create_any_row(): void
|
|
{
|
|
Http::fake([
|
|
'testcert.kcp.co.kr/*' => Http::response('gateway timeout', 504),
|
|
]);
|
|
|
|
$this->expectException(RemoteCallException::class);
|
|
|
|
try {
|
|
$this->provider()->requestChallenge(['email' => 'guest@example.test'], ['purpose' => 'signup']);
|
|
} finally {
|
|
$this->assertSame(0, IdentityVerificationLog::query()->count());
|
|
$this->assertSame(0, KcpCertTransaction::query()->count());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @scenario mode=live,kcp_response=success
|
|
*
|
|
* @effects live_mode_uses_live_host_and_prefixed_site_cd
|
|
*/
|
|
public function test_live_mode_calls_live_host_with_prefixed_site_code(): void
|
|
{
|
|
Http::fake([
|
|
'cert.kcp.co.kr/*' => Http::response([
|
|
'res_cd' => '0000',
|
|
'res_msg' => '정상처리',
|
|
'call_url' => 'https://cert.kcp.co.kr/certGateway.do',
|
|
'reg_cert_key' => 'LIVEKEY000000001',
|
|
]),
|
|
]);
|
|
|
|
$provider = $this->provider([
|
|
'is_test_mode' => false,
|
|
'live_site_cd' => 'A1B2C',
|
|
'live_enc_key' => 'live-enc-key',
|
|
]);
|
|
|
|
$challenge = $provider->requestChallenge(['email' => 'guest@example.test'], ['purpose' => 'signup']);
|
|
|
|
$this->assertSame('https://cert.kcp.co.kr/certGateway.do', $challenge->publicPayload['call_url']);
|
|
$this->assertFalse($challenge->publicPayload['is_test_mode']);
|
|
|
|
Http::assertSent(function ($request): bool {
|
|
$this->assertStringStartsWith('https://cert.kcp.co.kr/', $request->url());
|
|
$this->assertSame('SMA1B2C', $request->header('site_cd')[0] ?? null);
|
|
|
|
return true;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 거래등록 응답을 가로챈다.
|
|
*
|
|
* @param string $resCd 응답 코드
|
|
* @param string $resMsg 응답 메시지
|
|
*/
|
|
private function fakeRegistration(string $resCd, string $resMsg = '정상처리'): void
|
|
{
|
|
Http::fake([
|
|
'testcert.kcp.co.kr/*' => Http::response([
|
|
'res_cd' => $resCd,
|
|
'res_msg' => $resMsg,
|
|
'call_url' => $resCd === '0000' ? 'https://testcert.kcp.co.kr/certGateway.do' : '',
|
|
'reg_cert_key' => $resCd === '0000' ? 'CERTKEY000000001' : '',
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 설정이 주입된 provider 인스턴스.
|
|
*
|
|
* @param array<string, mixed> $config
|
|
*/
|
|
private function provider(array $config = self::TEST_CONFIG): KcpIdentityProvider
|
|
{
|
|
return app()->makeWith(KcpIdentityProvider::class, ['config' => $config]);
|
|
}
|
|
}
|