feat(settings): 코어 아웃바운드 HTTP 프록시 설정 추가
접속 IP 를 제한하는 결제사 API 를 로컬·스테이징에서 연동하려면 서버가 내보내는 요청의 출발지 IP 를 바꿔야 한다. 브라우저 프록시로는 바뀌지 않는 축이라 코어 환경설정으로 도입한다. 게이트는 디버그 모드이며 판정은 OutboundProxy 한 곳이 소유한다. 화면의 조건부 렌더링은 편의일 뿐이라 저장 API 직접 호출을 막지 못하므로, 실질 게이트를 판정 지점에 둔다. 주입·적용 지점은 결과만 소비한다. 적용은 Http::globalOptions 전역 옵션이라 확장의 Http:: 호출까지 함께 경유한다. 외부 연동 규약상 curl 핸들을 직접 다뤄야 하는 확장은 OutboundProxy::curlOptions 로 같은 프록시를 탄다 — KG이니시스 본인인증 승인 요청과 CBT 연결 점검을 이 통로로 편입했다. CBT 의 TCP 443 확인은 원시 소켓으로는 프록시를 태울 수 없어 curl CONNECT_ONLY 로 교체했다. 저장 전 연결 테스트는 저장값이 아니라 제출값을 검사하고, 그 프록시를 거쳤을 때 외부에 보이는 IP 를 함께 보고한다. 운영자가 결제사에 등록할 값이라 저장하고 나서 되짚지 않도록 했다. 적용과 같은 조립을 거치므로 확인한 구성과 저장 후 적용되는 구성이 어긋나지 않는다.
This commit is contained in:
1 parent
0e8b625436
commit
a7b7c64573
55 files changed
+2040
-30
No files matched your search
@@ -0,0 +1,322 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Settings;
|
||||
|
||||
use App\Contracts\Repositories\ConfigRepositoryInterface;
|
||||
use App\Http\Requests\Settings\SaveSettingsRequest;
|
||||
use App\Providers\AppServiceProvider;
|
||||
use App\Services\OutboundProxyTester;
|
||||
use App\Services\SettingsService;
|
||||
use Illuminate\Http\Client\Factory;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\Validator;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 아웃바운드 프록시 설정의 저장·검증·적용을 고정합니다.
|
||||
*
|
||||
* 이 설정은 화면 한 곳에서 입력되지만 네 지점을 지나야 실제로 동작합니다 — 검증(FormRequest),
|
||||
* 분류 저장(고급 탭 → debug 카테고리), 판정(OutboundProxy), 적용(Http 전역 옵션). 어느 한
|
||||
* 지점이 빠지면 "저장은 되는데 적용되지 않는" 상태가 되고, 저장 응답은 200 이라 화면에도
|
||||
* API 에도 실패가 드러나지 않습니다.
|
||||
*
|
||||
* 축 조합은 각 테스트 메서드의 @scenario 주석이 담당한다.
|
||||
*
|
||||
* @effects proxy_setting_persists_to_debug_category
|
||||
* @effects proxy_setting_rejects_invalid_url
|
||||
* @effects proxy_applied_to_global_http_options
|
||||
* @effects proxy_absent_leaves_global_http_options_untouched
|
||||
* @effects proxy_connection_test_reports_egress_ip
|
||||
*/
|
||||
class OutboundProxySettingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 고급 탭에서 저장한 프록시 값이 debug 카테고리에 기록되는지 확인합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_setting_persists_to_debug_category
|
||||
*/
|
||||
public function test_proxy_settings_saved_from_advanced_tab_are_persisted(): void
|
||||
{
|
||||
$saved = app(SettingsService::class)->saveSettings([
|
||||
'_tab' => 'advanced',
|
||||
'advanced' => [
|
||||
'outbound_proxy' => 'socks5h://127.0.0.1:1080',
|
||||
'outbound_proxy_bypass' => ['g7.dev', 'localhost'],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertTrue($saved, '고급 탭 저장이 실패했습니다.');
|
||||
|
||||
$debug = app(ConfigRepositoryInterface::class)->getCategory('debug');
|
||||
|
||||
$this->assertSame(
|
||||
'socks5h://127.0.0.1:1080',
|
||||
$debug['outbound_proxy'] ?? null,
|
||||
'debug.outbound_proxy 가 저장되지 않았습니다 — 고급 탭 분류표에서 누락되면 값이 조용히 버려집니다.'
|
||||
);
|
||||
$this->assertSame(['g7.dev', 'localhost'], $debug['outbound_proxy_bypass'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 기존 설치본에도 새 키가 기본값으로 노출되는지 확인합니다.
|
||||
*
|
||||
* 설정 JSON 은 defaults 와 병합되어 읽히므로 별도 마이그레이션 없이 키가 생겨야 합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=empty, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_setting_persists_to_debug_category
|
||||
*/
|
||||
public function test_new_keys_are_present_through_defaults_merge(): void
|
||||
{
|
||||
$debug = app(ConfigRepositoryInterface::class)->getCategory('debug');
|
||||
|
||||
$this->assertArrayHasKey('outbound_proxy', $debug);
|
||||
$this->assertArrayHasKey('outbound_proxy_bypass', $debug);
|
||||
$this->assertSame('', $debug['outbound_proxy']);
|
||||
$this->assertSame([], $debug['outbound_proxy_bypass']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 적용할 수 없는 형태의 주소는 저장 검증에서 막습니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=invalid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_setting_rejects_invalid_url
|
||||
*/
|
||||
public function test_invalid_proxy_url_fails_validation(): void
|
||||
{
|
||||
$validator = $this->validatorForAdvanced([
|
||||
'outbound_proxy' => 'ftp://proxy.internal:21',
|
||||
]);
|
||||
|
||||
$this->assertTrue(
|
||||
$validator->fails(),
|
||||
'허용 목록에 없는 스킴이 검증을 통과했습니다 — 저장은 되고 적용은 안 되는 상태가 됩니다.'
|
||||
);
|
||||
$this->assertArrayHasKey('advanced.outbound_proxy', $validator->errors()->messages());
|
||||
}
|
||||
|
||||
/**
|
||||
* 유효한 주소와 빈 값은 검증을 통과합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_setting_rejects_invalid_url
|
||||
*/
|
||||
public function test_valid_and_empty_proxy_url_pass_validation(): void
|
||||
{
|
||||
foreach (['socks5h://127.0.0.1:1080', 'http://proxy.internal:3128', ''] as $url) {
|
||||
$validator = $this->validatorForAdvanced(['outbound_proxy' => $url]);
|
||||
|
||||
$this->assertFalse(
|
||||
$validator->errors()->has('advanced.outbound_proxy'),
|
||||
"유효한 주소 '{$url}' 가 거부됐습니다."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 예외 목록의 각 항목이 문자열·길이 검증을 받는지 확인합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_setting_rejects_invalid_url
|
||||
*/
|
||||
public function test_bypass_list_items_are_validated(): void
|
||||
{
|
||||
$validator = $this->validatorForAdvanced([
|
||||
'outbound_proxy_bypass' => [str_repeat('a', 256)],
|
||||
]);
|
||||
|
||||
$this->assertTrue($validator->fails());
|
||||
$this->assertArrayHasKey('advanced.outbound_proxy_bypass.0', $validator->errors()->messages());
|
||||
}
|
||||
|
||||
/**
|
||||
* 판정 결과가 있으면 Http 전역 옵션에 프록시가 실립니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_applied_to_global_http_options
|
||||
*/
|
||||
public function test_resolved_proxy_is_applied_to_global_http_options(): void
|
||||
{
|
||||
$proxy = [
|
||||
'http' => 'socks5h://127.0.0.1:1080',
|
||||
'https' => 'socks5h://127.0.0.1:1080',
|
||||
'no' => ['g7.dev'],
|
||||
];
|
||||
|
||||
config(['g7.outbound_proxy' => $proxy]);
|
||||
$this->invokeOutboundProxyConfigurer();
|
||||
|
||||
$this->assertSame(
|
||||
['proxy' => $proxy],
|
||||
$this->globalHttpOptions(),
|
||||
'Http 전역 옵션에 프록시가 실리지 않았습니다 — 설정은 저장되어도 실제 요청은 그대로 나갑니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 판정 결과가 없으면 Http 전역 옵션을 건드리지 않습니다.
|
||||
*
|
||||
* 디버그 모드가 꺼져 있으면 판정이 null 을 돌려주므로, 이 경로가 프록시 미적용을 보장합니다.
|
||||
*
|
||||
* @scenario debug_mode=off, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_absent_leaves_global_http_options_untouched
|
||||
*/
|
||||
public function test_absent_proxy_leaves_global_http_options_untouched(): void
|
||||
{
|
||||
foreach ([null, [], ''] as $value) {
|
||||
config(['g7.outbound_proxy' => $value]);
|
||||
$this->invokeOutboundProxyConfigurer();
|
||||
|
||||
$this->assertSame(
|
||||
[],
|
||||
$this->globalHttpOptions(),
|
||||
'프록시 미적용 상태인데 Http 전역 옵션이 설정됐습니다.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 고급 탭 검증기를 구성합니다.
|
||||
*
|
||||
* @param array<string, mixed> $advanced advanced 탭 입력값
|
||||
*/
|
||||
private function validatorForAdvanced(array $advanced): Validator
|
||||
{
|
||||
$request = new SaveSettingsRequest;
|
||||
$request->merge(['_tab' => 'advanced', 'advanced' => $advanced]);
|
||||
$request->setContainer(app());
|
||||
|
||||
return validator(
|
||||
$request->all(),
|
||||
$request->rules(),
|
||||
$request->messages(),
|
||||
$request->attributes()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* AppServiceProvider 의 프록시 적용 로직만 실행합니다.
|
||||
*/
|
||||
private function invokeOutboundProxyConfigurer(): void
|
||||
{
|
||||
$this->resetGlobalHttpOptions();
|
||||
|
||||
$provider = new AppServiceProvider($this->app);
|
||||
$method = new ReflectionMethod($provider, 'configureOutboundProxy');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Http 팩토리의 전역 옵션을 비웁니다.
|
||||
*/
|
||||
private function resetGlobalHttpOptions(): void
|
||||
{
|
||||
Http::globalOptions([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Http 팩토리에 설정된 전역 옵션을 읽습니다.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function globalHttpOptions(): array
|
||||
{
|
||||
$factory = $this->app->make(Factory::class);
|
||||
$property = new ReflectionProperty($factory, 'globalOptions');
|
||||
$property->setAccessible(true);
|
||||
|
||||
return (array) value($property->getValue($factory));
|
||||
}
|
||||
|
||||
/**
|
||||
* 연결 테스트가 프록시를 거친 출발지 IP 를 보고합니다.
|
||||
*
|
||||
* 출발지 IP 는 운영자가 결제사에 등록해야 하는 값이라, 저장하기 전에 알 수 있어야 합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_connection_test_reports_egress_ip
|
||||
*/
|
||||
public function test_connection_test_reports_egress_ip(): void
|
||||
{
|
||||
Http::fake(['*' => Http::response('203.0.113.9', 200)]);
|
||||
|
||||
$result = app(OutboundProxyTester::class)->test('socks5h://127.0.0.1:1080');
|
||||
|
||||
$this->assertTrue($result['success']);
|
||||
$this->assertSame('203.0.113.9', $result['egress_ip']);
|
||||
$this->assertSame('settings.outbound_proxy_test_success', $result['message_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 연결 테스트는 제출된 값을 검사합니다 — 저장된 설정이나 전역 옵션을 보지 않습니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_connection_test_reports_egress_ip
|
||||
*/
|
||||
public function test_connection_test_uses_submitted_proxy_not_stored_settings(): void
|
||||
{
|
||||
config(['g7.outbound_proxy' => null]);
|
||||
Http::globalOptions([]);
|
||||
|
||||
Http::fake(['*' => Http::response('203.0.113.9', 200)]);
|
||||
|
||||
$result = app(OutboundProxyTester::class)->test('socks5h://10.0.0.9:1080', ['g7.dev']);
|
||||
|
||||
// 전역 프록시가 없는 상태에서도 제출값으로 요청이 나갔다.
|
||||
Http::assertSentCount(1);
|
||||
$this->assertTrue($result['success']);
|
||||
|
||||
// 전역 옵션은 비어 있는 채여야 한다 — 테스트가 전역 상태를 바꾸면 이후 모든 요청이
|
||||
// 저장하지도 않은 프록시를 타게 된다.
|
||||
$this->assertSame([], $this->globalHttpOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* 적용 불가 주소는 외부 호출 없이 즉시 거부합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=invalid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_connection_test_reports_egress_ip
|
||||
*/
|
||||
public function test_connection_test_rejects_invalid_url_without_calling_out(): void
|
||||
{
|
||||
Http::fake();
|
||||
|
||||
$result = app(OutboundProxyTester::class)->test('ftp://proxy.internal:21');
|
||||
|
||||
$this->assertFalse($result['success']);
|
||||
$this->assertSame('settings.outbound_proxy_test_invalid_url', $result['message_key']);
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 조회 대상이 없으면 확인 불가로 보고합니다 — 실패와 구분되어야 합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_connection_test_reports_egress_ip
|
||||
*/
|
||||
public function test_connection_test_reports_when_no_lookup_target_is_configured(): void
|
||||
{
|
||||
config(['core.outbound_proxy.egress_lookup_urls' => []]);
|
||||
Http::fake();
|
||||
|
||||
$result = app(OutboundProxyTester::class)->test('socks5h://127.0.0.1:1080');
|
||||
|
||||
$this->assertFalse($result['success']);
|
||||
$this->assertSame('settings.outbound_proxy_test_no_lookup_url', $result['message_key']);
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* E2E: 환경설정 > 고급 — 아웃바운드 HTTP 프록시 (#600)
|
||||
*
|
||||
* 시나리오 매니페스트: tests/scenarios/outbound-http-proxy.yaml — 마킹은 각 테스트의
|
||||
* scenario(k=v 조합)·effects 주석이 담당하며, 헤더 요약 마킹은 파서 형식이 아니다
|
||||
*
|
||||
* 배경: 접속 IP 를 제한하는 결제사 API 를 로컬에서 테스트하려면 서버가 내보내는 요청의
|
||||
* 출발지 IP 를 바꿔야 한다. 브라우저 프록시로는 바뀌지 않는 축이라 코어 설정으로 도입했다.
|
||||
*
|
||||
* 검증:
|
||||
* 1. 디버그 모드가 꺼져 있으면 프록시 입력칸이 화면에 없다
|
||||
* 2. 디버그 모드를 켜면 프록시 주소 Input 과 예외 목록 TagInput 이 마운트된다
|
||||
* 3. 적용할 수 없는 형태의 주소는 저장이 거부되고 해당 필드에 inline 에러가 표시된다
|
||||
*/
|
||||
import { test, expect, issueToken, authenticatePage } from '../../fixtures/auth';
|
||||
|
||||
/**
|
||||
* 관리자 환경설정 고급 탭 진입.
|
||||
*
|
||||
* 이 화면은 하드 로드 시 설정 응답이 도착하기 전에도 폼이 렌더되어 조작할 수 있고,
|
||||
* 그 조작은 뒤늦게 도착한 `initLocal` 시드에 덮인다(실측 노출 창 300~430ms).
|
||||
* 제품 차원의 잠금은 두지 않기로 했으므로(#600 PO 결정), 테스트가 시드 완료를
|
||||
* 기다린 뒤에 조작한다.
|
||||
*/
|
||||
async function gotoAdvancedTab(page: import('@playwright/test').Page): Promise<void> {
|
||||
await page.goto('/admin/settings?tab=advanced');
|
||||
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
|
||||
await expect(page.locator('#card_debug_settings')).toBeAttached({ timeout: 20_000 });
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
() =>
|
||||
page.evaluate(
|
||||
() => Object.keys((window as any).G7Core?.state?.getLocal?.()?.form?.advanced ?? {}).length
|
||||
),
|
||||
{ timeout: 20_000 }
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
}
|
||||
|
||||
/** 디버그 모드 토글을 켠다 (이미 켜져 있으면 그대로 둔다) */
|
||||
async function enableDebugMode(page: import('@playwright/test').Page): Promise<void> {
|
||||
const checkbox = page.locator('input[name="advanced.debug_mode"]').first();
|
||||
await expect(checkbox).toBeAttached({ timeout: 10_000 });
|
||||
|
||||
if (!(await checkbox.isChecked())) {
|
||||
// Toggle 은 sr-only checkbox 를 감싼 wrapper 가 클릭 대상이다
|
||||
await page.locator('#toggle_debug_mode .toggle-switch-wrapper').first().click();
|
||||
}
|
||||
|
||||
await expect(page.locator('#outbound_proxy_settings')).toBeAttached({ timeout: 10_000 });
|
||||
}
|
||||
|
||||
// @scenario debug_mode=off, proxy_value=valid, bypass_list=empty
|
||||
// @effects proxy_inputs_hidden_when_debug_mode_off
|
||||
test('#600 - 디버그 모드가 꺼져 있으면 프록시 입력칸이 없다', async ({ page }) => {
|
||||
const token = issueToken('core.settings.read', 'core.settings.update');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
await gotoAdvancedTab(page);
|
||||
expect(page.url()).not.toMatch(/\/admin\/login/);
|
||||
|
||||
// 존재 확정: 같은 카드의 SQL 쿼리 로그 토글은 조건 없이 렌더된다.
|
||||
// 이 확인이 없으면 아래 부재 단언이 "아직 렌더 전" 과 구분되지 않는다.
|
||||
await expect(page.locator('[name="advanced.sql_query_log"]').first()).toBeAttached();
|
||||
|
||||
await expect(page.locator('#outbound_proxy_settings')).toHaveCount(0);
|
||||
await expect(page.locator('input[name="advanced.outbound_proxy"]')).toHaveCount(0);
|
||||
});
|
||||
|
||||
// @scenario debug_mode=on, proxy_value=valid, bypass_list=empty
|
||||
// @effects proxy_inputs_visible_when_debug_mode_on
|
||||
test('@smoke #600 - 디버그 모드를 켜면 프록시 주소와 예외 목록이 마운트된다', async ({ page }) => {
|
||||
const token = issueToken('core.settings.read', 'core.settings.update');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
await gotoAdvancedTab(page);
|
||||
await enableDebugMode(page);
|
||||
|
||||
const proxyInput = page.locator('input[name="advanced.outbound_proxy"]').first();
|
||||
await expect(proxyInput).toBeAttached();
|
||||
|
||||
await proxyInput.fill('socks5h://127.0.0.1:1080');
|
||||
await expect(proxyInput).toHaveValue('socks5h://127.0.0.1:1080');
|
||||
|
||||
// 예외 목록은 TagInput — 자유 입력 후 Enter 로 항목이 된다
|
||||
await expect(page.locator('#input_outbound_proxy_bypass')).toBeAttached();
|
||||
});
|
||||
|
||||
// @scenario debug_mode=on, proxy_value=invalid, bypass_list=empty
|
||||
// @effects proxy_setting_rejects_invalid_url
|
||||
test('#600 - 허용되지 않는 형태의 프록시 주소는 저장이 거부된다', async ({ page }) => {
|
||||
const token = issueToken('core.settings.read', 'core.settings.update');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
await gotoAdvancedTab(page);
|
||||
await enableDebugMode(page);
|
||||
|
||||
const proxyInput = page.locator('input[name="advanced.outbound_proxy"]').first();
|
||||
await proxyInput.fill('ftp://proxy.internal:21');
|
||||
|
||||
const saveResponse = page.waitForResponse(
|
||||
(response) => response.request().method() === 'POST' && /\/api\/admin\/settings\/?$/.test(new URL(response.url()).pathname),
|
||||
{ timeout: 20_000 }
|
||||
);
|
||||
|
||||
await page.getByRole('button', { name: /저장|Save/ }).first().click();
|
||||
|
||||
const response = await saveResponse;
|
||||
expect(response.status()).toBe(422);
|
||||
|
||||
await expect(page.locator('#input_outbound_proxy .form-error')).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
// @scenario debug_mode=on, proxy_value=valid, bypass_list=empty
|
||||
// @effects proxy_connection_test_button_wired
|
||||
test('#600 - 연결 테스트가 프록시를 거친 출발지 IP 를 화면에 보고한다', async ({ page }) => {
|
||||
const token = issueToken('core.settings.read', 'core.settings.update');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
await gotoAdvancedTab(page);
|
||||
await enableDebugMode(page);
|
||||
|
||||
// 프록시 주소를 비운 상태에서는 테스트 버튼이 잠겨 있다 (보낼 값이 없다)
|
||||
await expect(page.locator('#btn_test_outbound_proxy')).toBeDisabled();
|
||||
|
||||
await page.locator('input[name="advanced.outbound_proxy"]').first().fill('socks5h://127.0.0.1:1080');
|
||||
await expect(page.locator('#btn_test_outbound_proxy')).toBeEnabled();
|
||||
|
||||
// 외부 프록시 서버는 E2E 환경에 없으므로 응답만 스텁한다 —
|
||||
// 버튼 배선·요청 페이로드·결과 렌더는 전부 실경로다.
|
||||
await page.route('**/api/admin/settings/test-outbound-proxy', async (route) => {
|
||||
const body = route.request().postDataJSON();
|
||||
expect(body.outbound_proxy).toBe('socks5h://127.0.0.1:1080');
|
||||
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: '프록시 연결에 성공했습니다. 외부 서비스에는 이 IP 로 보입니다.',
|
||||
data: { success: true, egress_ip: '203.0.113.9', elapsed_ms: 120, error: null },
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.locator('#btn_test_outbound_proxy').click();
|
||||
|
||||
const result = page.locator('#outbound_proxy_test_result');
|
||||
await expect(result).toBeVisible({ timeout: 10_000 });
|
||||
await expect(result).toContainText('203.0.113.9');
|
||||
});
|
||||
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use App\Support\OutboundProxy;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 아웃바운드 프록시 적용 판정을 고정합니다.
|
||||
*
|
||||
* 이 판정은 코어가 바깥으로 내보내는 모든 HTTP 요청의 경로를 정합니다. 잘못 열리면 결제 승인
|
||||
* 요청까지 운영자가 지정한 제3의 서버를 경유하게 되고, 그 사실이 예외나 로그로 드러나지
|
||||
* 않습니다 — 요청은 정상 성공하고 상대편에 보이는 출발지 IP 만 달라집니다.
|
||||
*
|
||||
* 그래서 관리자 화면에서 입력칸을 감추는 것은 게이트가 아닙니다. 저장 API 를 직접 호출하면
|
||||
* 값은 그대로 저장되므로, 실질 게이트는 이 판정 하나입니다.
|
||||
*
|
||||
* 축 조합은 각 테스트 메서드의 @scenario 주석이 담당한다.
|
||||
*/
|
||||
class OutboundProxyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 디버그 모드가 꺼져 있으면 저장값이 남아 있어도 적용하지 않습니다.
|
||||
*
|
||||
* @scenario debug_mode=off, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_not_applied_when_debug_mode_off
|
||||
*/
|
||||
public function test_proxy_is_not_applied_when_debug_mode_is_off(): void
|
||||
{
|
||||
$resolved = OutboundProxy::resolve([
|
||||
'mode' => false,
|
||||
'outbound_proxy' => 'socks5h://127.0.0.1:1080',
|
||||
'outbound_proxy_bypass' => ['internal.example'],
|
||||
]);
|
||||
|
||||
$this->assertNull(
|
||||
$resolved,
|
||||
'디버그 모드가 꺼진 상태에서 프록시가 적용되었습니다 — 화면 조건부 렌더링은 저장 API 직접 호출을 막지 못하므로 이 판정이 유일한 게이트입니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* mode 키 자체가 없는 설정도 미적용으로 판정합니다.
|
||||
*
|
||||
* @scenario debug_mode=off, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_not_applied_when_debug_mode_off
|
||||
*/
|
||||
public function test_proxy_is_not_applied_when_mode_key_is_absent(): void
|
||||
{
|
||||
$this->assertNull(
|
||||
OutboundProxy::resolve(['outbound_proxy' => 'http://proxy.internal:3128']),
|
||||
'mode 키 부재를 디버그 모드 ON 으로 해석했습니다 — 판정은 fail-closed 여야 합니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 디버그 모드가 켜져 있고 주소가 유효하면 http/https 양쪽에 적용합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_applied_when_debug_mode_on
|
||||
*/
|
||||
public function test_proxy_is_applied_for_both_schemes_when_debug_mode_is_on(): void
|
||||
{
|
||||
$resolved = OutboundProxy::resolve([
|
||||
'mode' => true,
|
||||
'outbound_proxy' => 'socks5h://127.0.0.1:1080',
|
||||
]);
|
||||
|
||||
$this->assertSame([
|
||||
'http' => 'socks5h://127.0.0.1:1080',
|
||||
'https' => 'socks5h://127.0.0.1:1080',
|
||||
'no' => [],
|
||||
], $resolved);
|
||||
}
|
||||
|
||||
/**
|
||||
* 값이 비어 있으면 프록시를 쓰지 않는 상태로 판정합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=empty, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_applied_when_debug_mode_on
|
||||
*/
|
||||
public function test_empty_proxy_value_disables_proxy(): void
|
||||
{
|
||||
$this->assertNull(OutboundProxy::resolve(['mode' => true, 'outbound_proxy' => '']));
|
||||
$this->assertNull(OutboundProxy::resolve(['mode' => true, 'outbound_proxy' => ' ']));
|
||||
$this->assertNull(OutboundProxy::resolve(['mode' => true]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 허용 목록에 없는 스킴과 호스트 없는 주소는 적용하지 않습니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=invalid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_rejects_disallowed_scheme
|
||||
*
|
||||
* @dataProvider invalidProxyUrls
|
||||
*/
|
||||
public function test_invalid_proxy_url_is_not_applied(string $url, string $why): void
|
||||
{
|
||||
$this->assertNull(
|
||||
OutboundProxy::resolve(['mode' => true, 'outbound_proxy' => $url]),
|
||||
$why
|
||||
);
|
||||
$this->assertFalse(OutboundProxy::isValidUrl($url), $why);
|
||||
}
|
||||
|
||||
/**
|
||||
* 적용 불가 주소 목록.
|
||||
*
|
||||
* @return array<string, array{0: string, 1: string}>
|
||||
*/
|
||||
public static function invalidProxyUrls(): array
|
||||
{
|
||||
return [
|
||||
'스킴 없음' => ['127.0.0.1:1080', '스킴 없는 주소가 통과했습니다 — cURL 이 프록시로 해석하지 못합니다.'],
|
||||
'파일 스킴' => ['file:///etc/passwd', 'file 스킴이 통과했습니다.'],
|
||||
'ftp 스킴' => ['ftp://proxy.internal:21', '허용 목록에 없는 스킴이 통과했습니다.'],
|
||||
'호스트 없음' => ['http://', '호스트 없는 주소가 통과했습니다.'],
|
||||
'빈 문자열' => ['', '빈 값이 유효 주소로 판정됐습니다.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 허용 스킴은 모두 적용 가능해야 합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_applied_when_debug_mode_on
|
||||
*/
|
||||
public function test_every_allowed_scheme_is_accepted(): void
|
||||
{
|
||||
foreach (OutboundProxy::ALLOWED_SCHEMES as $scheme) {
|
||||
$this->assertTrue(
|
||||
OutboundProxy::isValidUrl($scheme.'://proxy.internal:1080'),
|
||||
"허용 목록의 스킴 {$scheme} 이 거부됐습니다 — 목록과 판정이 어긋나면 저장은 되는데 적용되지 않습니다."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 예외 목록은 공백 제거·빈 항목 제거·중복 제거 후 순번을 다시 매깁니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_bypass_list_normalized
|
||||
*/
|
||||
public function test_bypass_list_is_normalized(): void
|
||||
{
|
||||
$resolved = OutboundProxy::resolve([
|
||||
'mode' => true,
|
||||
'outbound_proxy' => 'http://proxy.internal:3128',
|
||||
'outbound_proxy_bypass' => [' g7.dev ', '', 'g7.dev', 'localhost', 42, null],
|
||||
]);
|
||||
|
||||
$this->assertSame(['g7.dev', 'localhost'], $resolved['no']);
|
||||
$this->assertSame(
|
||||
[0, 1],
|
||||
array_keys($resolved['no']),
|
||||
'예외 목록 키가 비연속입니다 — JSON 직렬화 시 객체가 되어 목록으로 읽히지 않습니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 예외 목록이 배열이 아니면 빈 목록으로 취급합니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_bypass_list_normalized
|
||||
*/
|
||||
public function test_non_array_bypass_list_becomes_empty(): void
|
||||
{
|
||||
$resolved = OutboundProxy::resolve([
|
||||
'mode' => true,
|
||||
'outbound_proxy' => 'http://proxy.internal:3128',
|
||||
'outbound_proxy_bypass' => 'g7.dev',
|
||||
]);
|
||||
|
||||
$this->assertSame([], $resolved['no']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 적용 중인 프록시는 curl 옵션 형태로도 제공됩니다.
|
||||
*
|
||||
* `Http::` 파사드를 쓰지 못하는 호출 지점(외부 SDK 규약상 curl 핸들을 직접 다뤄야 하는
|
||||
* 경우)이 같은 프록시를 타려면 이 통로가 필요합니다. 이 통로가 없으면 그 경로만 조용히
|
||||
* 직접 나가고, 요청은 정상 성공하므로 아무 신호도 남지 않습니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_exposed_as_curl_options
|
||||
*/
|
||||
public function test_resolved_proxy_is_exposed_as_curl_options(): void
|
||||
{
|
||||
config(['g7.outbound_proxy' => OutboundProxy::resolve([
|
||||
'mode' => true,
|
||||
'outbound_proxy' => 'socks5h://127.0.0.1:1080',
|
||||
'outbound_proxy_bypass' => ['g7.dev', 'localhost'],
|
||||
])]);
|
||||
|
||||
$this->assertSame([
|
||||
CURLOPT_PROXY => 'socks5h://127.0.0.1:1080',
|
||||
CURLOPT_NOPROXY => 'g7.dev,localhost',
|
||||
], OutboundProxy::curlOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* 프록시 미적용 상태에서는 빈 배열이라 curl_setopt_array 에 그대로 넘겨도 무해합니다.
|
||||
*
|
||||
* @scenario debug_mode=off, proxy_value=valid, bypass_list=empty
|
||||
*
|
||||
* @effects proxy_exposed_as_curl_options
|
||||
*/
|
||||
public function test_curl_options_are_empty_when_proxy_is_not_applied(): void
|
||||
{
|
||||
config(['g7.outbound_proxy' => OutboundProxy::resolve([
|
||||
'mode' => false,
|
||||
'outbound_proxy' => 'socks5h://127.0.0.1:1080',
|
||||
])]);
|
||||
|
||||
$this->assertSame([], OutboundProxy::curlOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* 저장 전 연결 테스트와 실제 적용이 같은 조립·정규화를 거칩니다.
|
||||
*
|
||||
* 이 테스트의 목적은 "저장 전에 확인한다" 는 기능의 전제를 지키는 것입니다. 조립을 두 곳에서
|
||||
* 각각 하면 예외 목록의 공백·빈 항목·중복 처리가 어긋나, 운영자가 확인한 구성과 저장 후
|
||||
* 실제로 적용되는 구성이 달라집니다. 두 구성 모두 정상 동작하므로 어긋남 자체는 아무런
|
||||
* 오류도 남기지 않습니다.
|
||||
*
|
||||
* @scenario debug_mode=on, proxy_value=valid, bypass_list=normalizable
|
||||
*
|
||||
* @effects proxy_bypass_list_normalized
|
||||
*/
|
||||
public function test_connection_test_and_applied_config_share_the_same_assembly(): void
|
||||
{
|
||||
$url = ' socks5h://127.0.0.1:1080 ';
|
||||
$bypass = [' g7.dev ', '', 'g7.dev', 'localhost'];
|
||||
|
||||
// 실제 적용 경로 (SettingsServiceProvider → config('g7.outbound_proxy'))
|
||||
$applied = OutboundProxy::resolve([
|
||||
'mode' => true,
|
||||
'outbound_proxy' => $url,
|
||||
'outbound_proxy_bypass' => $bypass,
|
||||
]);
|
||||
|
||||
// 저장 전 연결 테스트 경로 (OutboundProxyTester)
|
||||
$tested = OutboundProxy::options($url, $bypass);
|
||||
|
||||
$this->assertSame($applied, $tested);
|
||||
$this->assertSame(['g7.dev', 'localhost'], $tested['no']);
|
||||
$this->assertSame('socks5h://127.0.0.1:1080', $tested['https']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
feature: 코어 아웃바운드 HTTP 프록시 설정
|
||||
|
||||
description: |
|
||||
코어가 바깥으로 내보내는 모든 HTTP 요청(결제 승인, 코어 업데이트 조회, GeoIP 내려받기,
|
||||
알림 웹훅)을 운영자가 지정한 프록시로 경유시키는 환경설정. 접속 IP 를 제한하는 외부
|
||||
서비스를 로컬·스테이징 환경에서 연동하기 위한 것이다.
|
||||
|
||||
핵심 동작:
|
||||
- 저장 키는 debug 카테고리 소속 (debug.outbound_proxy, debug.outbound_proxy_bypass)
|
||||
- 적용 게이트는 디버그 모드 — App\Support\OutboundProxy 가 단독 판정
|
||||
- 디버그 모드 OFF 면 저장값이 남아 있어도 미적용 (화면 조건부 렌더링은 게이트가 아님)
|
||||
- 적용은 Http::globalOptions 전역 옵션 — 확장의 Http:: 호출까지 함께 경유
|
||||
- 개별 요청의 withOptions(['proxy' => ...]) 가 전역 옵션보다 우선
|
||||
- Http:: 파사드를 쓰지 못하는 curl 직접 호출은 OutboundProxy::curlOptions() 로 편입
|
||||
- 저장 전 연결 테스트는 저장값이 아니라 제출값을 검사하고 출발지 IP 를 보고
|
||||
|
||||
축 설계: 판정에 실제로 영향을 주는 입력만 축으로 둔다. 검증 지점(단위/저장/적용/화면)은
|
||||
같은 조합을 여러 계층에서 확인하는 것이므로 축이 아니라 테스트 파일의 분담이다.
|
||||
|
||||
axes:
|
||||
debug_mode: [on, off]
|
||||
proxy_value: [valid, invalid, empty]
|
||||
bypass_list: [empty, normalizable]
|
||||
|
||||
exclusions:
|
||||
- { debug_mode: off, proxy_value: invalid, reason: "게이트가 먼저 걸려 주소 형태를 평가하지 않는다" }
|
||||
- { debug_mode: off, proxy_value: empty, reason: "동일 — 미적용 판정이 주소보다 앞선다" }
|
||||
- { debug_mode: off, bypass_list: normalizable, reason: "미적용 판정에서는 예외 목록을 계산하지 않는다" }
|
||||
- { proxy_value: invalid, bypass_list: normalizable, reason: "주소가 거부되면 예외 목록은 계산되지 않는다" }
|
||||
- { proxy_value: empty, bypass_list: normalizable, reason: "프록시를 쓰지 않으면 예외 목록은 의미가 없다" }
|
||||
|
||||
effects:
|
||||
- proxy_not_applied_when_debug_mode_off
|
||||
- proxy_applied_when_debug_mode_on
|
||||
- proxy_rejects_disallowed_scheme
|
||||
- proxy_bypass_list_normalized
|
||||
- proxy_setting_persists_to_debug_category
|
||||
- proxy_setting_rejects_invalid_url
|
||||
- proxy_applied_to_global_http_options
|
||||
- proxy_absent_leaves_global_http_options_untouched
|
||||
- proxy_inputs_hidden_when_debug_mode_off
|
||||
- proxy_inputs_visible_when_debug_mode_on
|
||||
- proxy_exposed_as_curl_options
|
||||
- proxy_connection_test_reports_egress_ip
|
||||
- proxy_connection_test_button_wired
|
||||
|
||||
test_files:
|
||||
- tests/Unit/Support/OutboundProxyTest.php
|
||||
- tests/Feature/Settings/OutboundProxySettingTest.php
|
||||
- templates/_bundled/sirsoft-admin_basic/__tests__/layouts/admin-settings-outbound-proxy-visibility.test.tsx
|
||||
- tests/Playwright/specs/admin/settings-outbound-proxy.spec.ts
|
||||
Reference in new issue
Block a user