* fix(configure): reject literal "undefined" and "null" gateway auth tokens * fix(configure): reject literal "undefined" and "null" gateway auth tokens * fix(configure): validate gateway password prompt and harden token coercion (#13767) (thanks @omair445) * test: remove unused vitest imports in baseline lint fixtures (#13767) --------- Co-authored-by: Luna AI <luna@coredirection.ai> Co-authored-by: Peter Steinberger <steipete@gmail.com>
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { withTempHome } from "../../test/helpers/temp-home.js";
|
|
import { resolveProviderAuths } from "./provider-usage.auth.js";
|
|
|
|
describe("resolveProviderAuths key normalization", () => {
|
|
it("strips embedded CR/LF from env keys", async () => {
|
|
await withTempHome(
|
|
async () => {
|
|
const auths = await resolveProviderAuths({
|
|
providers: ["zai", "minimax", "xiaomi"],
|
|
});
|
|
expect(auths).toEqual([
|
|
{ provider: "zai", token: "zai-key" },
|
|
{ provider: "minimax", token: "minimax-key" },
|
|
{ provider: "xiaomi", token: "xiaomi-key" },
|
|
]);
|
|
},
|
|
{
|
|
env: {
|
|
ZAI_API_KEY: "zai-\r\nkey",
|
|
MINIMAX_API_KEY: "minimax-\r\nkey",
|
|
XIAOMI_API_KEY: "xiaomi-\r\nkey",
|
|
},
|
|
},
|
|
);
|
|
});
|
|
|
|
it("strips embedded CR/LF from stored auth profiles (token + api_key)", async () => {
|
|
await withTempHome(
|
|
async (home) => {
|
|
const agentDir = path.join(home, ".openclaw", "agents", "main", "agent");
|
|
await fs.mkdir(agentDir, { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(agentDir, "auth-profiles.json"),
|
|
`${JSON.stringify(
|
|
{
|
|
version: 1,
|
|
profiles: {
|
|
"minimax:default": { type: "token", provider: "minimax", token: "mini-\r\nmax" },
|
|
"xiaomi:default": { type: "api_key", provider: "xiaomi", key: "xiao-\r\nmi" },
|
|
},
|
|
},
|
|
null,
|
|
2,
|
|
)}\n`,
|
|
"utf8",
|
|
);
|
|
|
|
const auths = await resolveProviderAuths({
|
|
providers: ["minimax", "xiaomi"],
|
|
});
|
|
expect(auths).toEqual([
|
|
{ provider: "minimax", token: "mini-max" },
|
|
{ provider: "xiaomi", token: "xiao-mi" },
|
|
]);
|
|
},
|
|
{
|
|
env: {
|
|
MINIMAX_API_KEY: undefined,
|
|
MINIMAX_CODE_PLAN_KEY: undefined,
|
|
XIAOMI_API_KEY: undefined,
|
|
},
|
|
},
|
|
);
|
|
});
|
|
});
|