/
gkat
/
gitverse-codex-plugin
Обзор
Документация
Войти
/
gkat
/
gitverse-codex-plugin
Код
Запросы
0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
test/auth.test.mjs
86 строк
2 KB
gkat
Add cross-platform authentication and usage guide
29 июл 2026, 15:18
29 июл 2026, 15:18
a87de51
Код
Авторство
О чём код?
import assert from "node:assert/strict"; import test from "node:test"; import { resolveToken } from "../scripts/auth.mjs"; function fakeExec(responses, calls) { return (command, args) => { calls.push({ command, args }); const key = `${command} ${args.join(" ")}`; if (!(key in responses)) throw new Error("not found"); return responses[key]; }; } test("prefers GITVERSE_TOKEN without calling a credential store", () => { const calls = []; const result = resolveToken({ env: { GITVERSE_TOKEN: " env-token " }, platform: "linux", execFileSync: fakeExec({}, calls), }); assert.deepEqual(result, { token: "env-token", source: "GITVERSE_TOKEN" }); assert.deepEqual(calls, []); }); test("reads a configured macOS Keychain service and account", () => { const calls = []; const responses = { "security find-generic-password -w -s custom-service -a alice": "mac-token\n", }; const result = resolveToken({ env: { GITVERSE_SECRET_NAME: "custom-service", GITVERSE_SECRET_ACCOUNT: "alice", }, platform: "darwin", execFileSync: fakeExec(responses, calls), }); assert.equal(result.token, "mac-token"); assert.equal(result.source, "macOS Keychain (custom-service)"); }); test("reads Linux Secret Service with secret-tool", () => { const calls = []; const responses = { "secret-tool lookup service codex-gitverse-mcp account bob": "linux-token\n", }; const result = resolveToken({ env: { GITVERSE_SECRET_ACCOUNT: "bob" }, platform: "linux", execFileSync: fakeExec(responses, calls), }); assert.equal(result.token, "linux-token"); assert.equal(result.source, "Linux Secret Service (codex-gitverse-mcp)"); }); test("reads Windows PowerShell SecretManagement", () => { const calls = []; const execFileSync = (command, args) => { calls.push({ command, args }); if (command === "powershell.exe") return "windows-token"; throw new Error("not found"); }; const result = resolveToken({ env: {}, platform: "win32", execFileSync, }); assert.equal(result.token, "windows-token"); assert.match(result.source, /PowerShell SecretManagement/); assert.equal(calls[0].command, "powershell.exe"); }); test("fails without exposing attempted secret values", () => { assert.throws( () => resolveToken({ env: {}, platform: "linux", execFileSync: () => { throw new Error("secret backend unavailable"); }, }), /GitVerse token not found for linux/, ); });