import test from 'node:test'; import assert from 'node:assert/strict'; import { verifyAbc } from '../scripts/verify-abc.mjs'; const env = { CLOUDFLARE_API_TOKEN: 'fixture-cloudflare-token', SESSION_SECRET: 'fixture-session-'.repeat(3), ABC_API_KEY: 'fixture-project-key', AUTH_CLIENT_ID: 'fixture-public-pkce-client', ABC_PROJECT_ID: '01a1c543-ab4f-744f-8eff-ab85f2644271', ABC_CHANNEL_ID: '01a1c544-35ac-7674-9bf0-2469bfbe3e52', ORG_CONTEXT_ENABLED: 'true', ORG_CONTEXT_TENANT_IDS: '["038326b6-954a-48a7-a85f-efd83f62b82a"]', ORG_CONTEXT_KEY_ID: 'fixture-key-id', ORG_CONTEXT_KEY_SECRET: 'fixture-key-secret', DEPLOY_COMMIT_SHA: 'a'.repeat(40) }; const fields = [{ key: 'title' }, { key: 'contents' }, { key: 'Category', options: ['ERROR_QNA', 'IMPROVEMENT_QNA', 'GENERAL_QNA'].map((key) => ({ key })) }]; test('ABC connection verification reads the configured production channel without writing data', async () => { await verifyAbc(env, async (url, options) => { assert.equal(url, 'https://qa.brsw.kr/api/projects/' + env.ABC_PROJECT_ID + '/channels/' + env.ABC_CHANNEL_ID + '/fields'); assert.equal(options.method, 'GET'); assert.equal(options.body, undefined); assert.equal(options.redirect, 'error'); assert.equal(options.headers['x-api-key'], env.ABC_API_KEY); return Response.json(fields); }); }); test('ABC connection verification blocks wrong production targets before sending credentials', async () => { let requests = 0; for (const override of [ { ABC_API_BASE_URL: 'https://feedback.hmac.kr' }, { ABC_CHANNEL_ID: '01900000-0000-7000-8000-000000000002' } ]) { await assert.rejects(verifyAbc({ ...env, ...override }, async () => { requests++; }), /must match the production EGBIM Q&A target/); } assert.equal(requests, 0); }); test('ABC connection verification rejects wrong keys and channel schemas without printing credentials', async () => { for (const status of [401, 403, 404]) { await assert.rejects(verifyAbc(env, async () => new Response('', { status })), new RegExp('HTTP ' + status)); } await assert.rejects(verifyAbc(env, async () => Response.json([{ key: 'title' }])), /contents, Category/); await assert.rejects(verifyAbc(env, async () => Response.json(fields.map((field) => ({ ...field, options: [] })))), /category options/); await assert.rejects(verifyAbc(env, async () => { throw new Error(env.ABC_API_KEY); }), (error) => { assert.ok(!error.message.includes(env.ABC_API_KEY)); return true; }); });