Files
zyt/identity-admin/tests/kefu-authorization.test.mjs
T
2026-11-11 13:53:14 +08:00

25 lines
1.4 KiB
JavaScript

import assert from 'node:assert/strict'
import { spawnSync } from 'node:child_process'
import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { basename, dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
test('客服授权 owner 边界、签名写穿、冲突与审计保持独立', async () => {
const runtime = await mkdtemp(join(tmpdir(), 'iam-kefu-authorization-'))
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^IAM_/i.test(key)))
Object.assign(env, { IAM_RUNTIME_PATH: runtime, IAM_GROUP_DB_PATH: join(runtime, 'group.sqlite'), IAM_GROUP_ENABLED: '1', IAM_GROUP_OWNER_IDS: '1', IAM_KEFU_COMPANY_CODE: 'zyt-im' })
try {
const result = spawnSync(process.env.IAM_TEST_PHP || 'php', ['-d', 'extension=pdo_sqlite', fileURLToPath(new URL('./kefu-authorization-fixture.php', import.meta.url))], { encoding: 'utf8', env, windowsHide: true, timeout: 30000 })
assert.ifError(result.error)
assert.equal(result.status, 0, `${result.stdout}${result.stderr}`)
assert.match(result.stdout, /PASS kefu authorization central: \d+ checks/)
process.stdout.write(result.stdout)
} finally {
assert.equal(dirname(resolve(runtime)), resolve(tmpdir()))
assert.ok(basename(runtime).startsWith('iam-kefu-authorization-'))
await rm(runtime, { recursive: true, force: true })
}
})