feat(performance): 쿠팡 연결 테스트 — HMAC(CEA) 서명으로 발주서 실제 조회

쿠팡 OPEN API 키를 입력했지만 연결 테스트가 "다음 단계에서 구현"만 돌려줘
키가 이 서버에서 통하는지 알 수 없었다. 키는 판매자당 1개이고 사방넷용
(연동업체 선택)으로 발급한 키는 이 서버 IP 에서 막힐 수 있어 먼저 확인이 필요.

- CEA HMAC-SHA256 서명(signed-date + METHOD + path + query, 공식 예제 방식),
  쿠팡 예시와 같은 쿼리 인코딩(+ → %2B, : 유지)
- test_connection: 오늘 결제완료 발주서(v5 ordersheets) 1건 조회
- 401/403 → 인증 실패 + "연동업체 키면 자체개발로 바꾸고 이 서버 IP 허용" 안내
- 매출 수집은 아직 — 맞출 WING 화면을 정한 뒤 구현(주석에 API 조사 결과)
- 테스트: 서명 형식·쿼리 인코딩·403 메시지·비밀값 미노출

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 00:14:06 +09:00
parent b52b182d47
commit dd6a849fbd
2 changed files with 139 additions and 2 deletions
@@ -754,6 +754,55 @@ def test_cafe24_market_map_empty_by_default():
assert target_code("shopn") == target_code("coupang", "coupang") == target_code("NCHECKOUT") == "cafe24"
def test_coupang_hmac_and_connection_errors():
"""쿠팡 CEA HMAC 서명(공식 예제 방식) + 연결 테스트 오류 구분. 비밀값은 메시지에 없다."""
import hashlib
import hmac as _hmac
import httpx
from app.modules.performance.adapters import coupang as cp
from app.modules.performance.adapters.base import AdapterContext
q = cp.build_query({"createdAtFrom": "2026-09-30+09:00", "status": "ACCEPT", "maxPerPage": 1})
assert q == "createdAtFrom=2026-09-30%2B09:00&status=ACCEPT&maxPerPage=1"
now = 1_790_000_000 # 2026-09-21 14:13:20 UTC
h = cp.authorization("GET", "/p", q, "AK", "SK", now=now)
dt = "260921T141320Z"
sig = _hmac.new(b"SK", f"{dt}GET/p{q}".encode(), hashlib.sha256).hexdigest()
assert h == f"CEA algorithm=HmacSHA256, access-key=AK, signed-date={dt}, signature={sig}"
class Creds(dict):
def get(self, k, default=""):
return dict.get(self, k, default)
def has(self, k):
return bool(dict.get(self, k))
ctx = AdapterContext(code="coupang", credentials=Creds(vendor_id="A00012345", access_key="AK-1", secret_key="SK-SECRET"))
seen = {}
def fake_get(url, headers=None, timeout=None, status=200, body=None):
seen["url"], seen["auth"] = url, headers["Authorization"]
return httpx.Response(status, json=body if body is not None else {"code": 200, "data": []})
orig = httpx.get
try:
httpx.get = fake_get
msg = cp.CoupangAdapter().test_connection(ctx)
assert "연결 정상" in msg and "/vendors/A00012345/ordersheets?createdAtFrom=" in seen["url"]
assert "%2B09:00" in seen["url"] and "SK-SECRET" not in seen["auth"]
httpx.get = lambda url, headers=None, timeout=None: fake_get(url, headers, timeout, 403, {"message": "Access Denied"})
try:
cp.CoupangAdapter().test_connection(ctx)
except AuthFailed as exc:
assert "403" in exc.message and "자체개발" in exc.message and "SK-SECRET" not in exc.message
else:
raise AssertionError("403 이면 인증 실패여야 합니다")
finally:
httpx.get = orig
def test_registry_and_event_validation():
codes = [a.code for a in all_adapters()]
assert len(codes) == len(set(codes)) == 10