Files
Gnuboard7/plugins/_bundled/sirsoft-verification_nhnkcp/tests/Feature/Controllers/KcpCallbackControllerTest.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

187 lines
6.6 KiB
PHP

<?php
namespace Plugins\Sirsoft\VerificationNhnkcp\Tests\Feature\Controllers;
use App\Contracts\Repositories\IdentityVerificationLogRepositoryInterface;
use App\Enums\IdentityOriginType;
use App\Enums\IdentityVerificationStatus;
use App\Models\IdentityVerificationLog;
use App\Models\User;
use App\Services\PluginSettingsService;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use Plugins\Sirsoft\VerificationNhnkcp\Identity\KcpIdentityProvider;
use Plugins\Sirsoft\VerificationNhnkcp\Repositories\KcpCertTransactionRepositoryInterface;
use Plugins\Sirsoft\VerificationNhnkcp\Support\KcpCertCrypto;
use Plugins\Sirsoft\VerificationNhnkcp\Tests\PluginTestCase;
/**
* 콜백 수신 → 브리지 전달 경로 검증 (HTTP 관점).
*
* 외부 인증기관이 보내는 form POST 는 CSRF 토큰이 없으므로 면제되어야 하고, 결과는 브리지
* 페이지로 넘어가되 개인정보는 주소에 실리지 않아야 한다.
*
* @since 1.0.0
*/
class KcpCallbackControllerTest extends PluginTestCase
{
private const CALLBACK_URL = '/plugins/sirsoft-verification_nhnkcp/plugin/nhnkcp/callback';
private const BRIDGE_URL = '/plugins/sirsoft-verification_nhnkcp/plugin/nhnkcp/bridge';
private const SITE_CD = 'AO7F3';
private const ENC_KEY = 'c2a22fa3ebe4698075bcac6b433d52e351c881b02fb83488d4283a43385b1f8e';
private const REG_CERT_KEY = 'CERTKEY000000001';
protected function setUp(): void
{
parent::setUp();
app(PluginSettingsService::class)->save(self::PLUGIN_IDENTIFIER, [
'is_test_mode' => true,
'test_site_cd' => self::SITE_CD,
'test_enc_key' => self::ENC_KEY,
]);
}
/**
* @scenario outcome=success,lookup=by_reg_cert_key,missing_field=none
*
* @effects success_issues_verification_token_and_marks_log_verified
*/
public function test_successful_callback_redirects_to_bridge_with_token(): void
{
$log = $this->createChallenge();
$this->fakeCertQuery();
$response = $this->post(self::CALLBACK_URL, [
'res_cd' => '0000',
'res_msg' => '정상처리',
'reg_cert_key' => self::REG_CERT_KEY,
'param_opt_1' => $log->id,
]);
$response->assertRedirect();
$location = $response->headers->get('Location');
$this->assertStringContainsString(self::BRIDGE_URL, (string) $location);
$this->assertStringContainsString('verification_token=', (string) $location);
$this->assertStringNotContainsString('홍길동', (string) $location);
$this->assertStringNotContainsString('01012345678', (string) $location);
}
/**
* @scenario outcome=cancelled,lookup=by_reg_cert_key,missing_field=none
*
* @effects cancelled_marks_log_cancelled_with_9999_code
*/
public function test_cancelled_callback_redirects_with_error_code(): void
{
$this->createChallenge();
Http::fake();
$response = $this->post(self::CALLBACK_URL, [
'res_cd' => '9999',
'res_msg' => '사용자취소',
'reg_cert_key' => self::REG_CERT_KEY,
]);
$response->assertRedirect();
$this->assertStringContainsString('identity_error=9999', (string) $response->headers->get('Location'));
}
/**
* @scenario outcome=not_found,lookup=by_reg_cert_key,missing_field=none
*
* @effects unknown_transaction_returns_not_found
*/
public function test_unknown_callback_redirects_with_not_found(): void
{
$response = $this->post(self::CALLBACK_URL, [
'res_cd' => '0000',
'reg_cert_key' => 'UNKNOWN',
]);
$response->assertRedirect();
$this->assertStringContainsString('identity_error=NOT_FOUND', (string) $response->headers->get('Location'));
}
/**
* @scenario outcome=success,lookup=by_param_opt,missing_field=none
*
* @effects bridge_query_carries_no_personal_information
*/
public function test_bridge_page_relays_result_to_opener_without_personal_information(): void
{
$response = $this->get(self::BRIDGE_URL.'?verification_token=tok-123&challenge_id=chal-123');
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'text/html; charset=UTF-8');
$html = $response->getContent();
$this->assertStringContainsString('identity_result', (string) $html);
$this->assertStringContainsString('tok-123', (string) $html);
// 부모창 전달은 동일 origin 으로 제한되어야 한다.
$this->assertStringContainsString('window.location.origin', (string) $html);
}
/**
* 결과조회 응답을 가로챈다.
*/
private function fakeCertQuery(): void
{
$encrypted = KcpCertCrypto::encrypt((string) json_encode([
'user_name' => '홍길동',
'birth_day' => '19900101',
'phone_no' => '01012345678',
'comm_id' => 'SKT',
'sex_code' => '01',
'local_code' => '01',
'CI' => 'CI-CTRL-0001',
'DI' => 'DI-CTRL-0001',
]), self::ENC_KEY, self::SITE_CD);
Http::fake([
'testcert.kcp.co.kr/*' => Http::response([
'res_cd' => '0000',
'res_msg' => '정상처리',
'enc_cert_data' => $encrypted['enc_data'],
'rv' => $encrypted['rv'],
]),
]);
}
/**
* 인증 대기 challenge + 거래 행을 만든다.
*
* @return IdentityVerificationLog
*/
private function createChallenge()
{
$log = app(IdentityVerificationLogRepositoryInterface::class)->create([
'id' => (string) Str::uuid(),
'provider_id' => KcpIdentityProvider::PROVIDER_ID,
'purpose' => 'self_update',
'channel' => KcpIdentityProvider::CHANNEL,
'user_id' => User::factory()->create()->id,
'target_hash' => hash('sha256', 'controller@example.test'),
'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-CTRL-0001'],
]);
app(KcpCertTransactionRepositoryInterface::class)
->create('G7-CTRL-0001', self::REG_CERT_KEY, $log->id);
return $log;
}
}