Files
Gnuboard7/plugins/_bundled/sirsoft-verification_nhnkcp/tests/Feature/Controllers/KcpCallbackControllerTest.php
T
HeuJung 3ebbda5d86 feat(board,ecommerce,pay,verification,templates,core): 문의 답변 사슬·답글 삭제 정책·검증 계약 + 실패 사유 표면화 전수
공개 (답변 중복 등록)/(문의 삭제 시 답변 잔존) 수정과 동형 결함 전수 해소.

- 문의 답변 단일성: 1차(피벗 is_answered) + 2차(게시판 리스너 duplicate 마커) 이중 방어,
 경합 경로에서도 사유(reply_already_exists 422)가 보존되도록 훅 반환 계약 확장
- 질문·답변·피벗 생명주기 대칭: 삭제/복원/영구삭제 훅 연동 + 고아 데이터 백필 업그레이드 스텝
- 게시판별 답글 삭제 정책(cascade/block) 신설, 정렬 화이트리스트·per_page 게이트
 (전량 조회 소비처 200/999 를 수용하는 상한 999 — 조였다가 관리자 화면 2곳 422 회귀 즉시 정정)
- 결제/본인인증 플러그인 검증 계약: FormRequest 15종 승격 + 컨트롤러 catch 정합.
 거래 조회 tid 상한은 저장 컬럼(varchar 100) 기준 — 해외 CBT TID(40자) 수용
- onError 토스트 고정 문구 전수 해소(67건/50파일/15확장) — 서버 실패 사유를 그대로 표면화,
 change-password 오변수(response→error) 교정
- 코어 플러그인 설정 검증 안내의 항목 표시명이 스키마 라벨(ko/en) 폴백에 덮여 요청 로케일
 (ja) 라벨을 잃던 회귀 정정 — 번역 등록이 있으면 그것을 우선 (7.0.7 미출시 기능 자체 결함)
- 사전 결함 정리(Icon 등가표 27·darkmode 2·validated 통일), API 문서·CHANGELOG·ja 팩 동기
- develop(60652fdc0) 리베이스: getTable 정비와 병합 — 양측 의도 보존 (충돌 18파일)
2026-08-17 17:04:44 +09:00

222 lines
8.1 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);
}
/**
* 배열 주입(`?verification_token[]=x`)은 KcpBridgeRequest 의 string 규칙이 422 로
* 차단해야 한다 — 종전 `(string)` 캐스팅은 배열을 "Array" 문자열로 바꿔 브리지
* payload 에 유입시켰다.
*/
public function test_bridge_rejects_array_verification_token_with_422(): void
{
$response = $this->getJson(self::BRIDGE_URL.'?verification_token[]=x');
$response->assertStatus(422)
->assertJsonValidationErrors(['verification_token']);
}
/**
* 정상 쿼리의 identity_error / identity_error_message 는 브리지 HTML payload 에
* 그대로 실려야 한다 (KcpBridgeRequest 주입 후 bridgePayload() 경유 회귀 방지).
*/
public function test_bridge_renders_identity_error_message_passthrough(): void
{
$response = $this->get(self::BRIDGE_URL.'?'.http_build_query([
'challenge_id' => 'chal-456',
'identity_error' => '9999',
'identity_error_message' => '사용자취소',
]));
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'text/html; charset=UTF-8');
$html = (string) $response->getContent();
$this->assertStringContainsString('identity_result', $html);
$this->assertStringContainsString('"identity_error":"9999"', $html);
$this->assertStringContainsString('사용자취소', $html);
$this->assertStringContainsString('"challenge_id":"chal-456"', $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;
}
}