Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.4 KB
Raw Blame
import { test } from "node:test";
import assert from "node:assert/strict";

import { combineModalCredential } from "@/app/(dashboard)/dashboard/providers/[id]/providerPageHelpers";

// #5446 — Modal auth requires TWO credentials (Token ID + Token Secret) joined
// as `Bearer <TOKEN_ID>:<TOKEN_SECRET>`. The add-connection form collects them in
// two fields and combines them into the single encrypted `apiKey` value; the
// generic bearer executor then emits `Bearer <apiKey>` unchanged.
test("combineModalCredential — joins id + secret with a colon", () => {
  assert.equal(combineModalCredential("ak-abc123", "as-def456"), "ak-abc123:as-def456");
});

test("combineModalCredential — trims surrounding whitespace on both fields", () => {
  assert.equal(combineModalCredential("  ak-abc  ", "  as-def  "), "ak-abc:as-def");
});

test("combineModalCredential — no secret returns the id verbatim (supports pasting a combined id:secret)", () => {
  assert.equal(combineModalCredential("ak-abc:as-def", ""), "ak-abc:as-def");
  assert.equal(combineModalCredential("ak-abc", "   "), "ak-abc");
});

test("combineModalCredential — id empty but secret present returns the secret", () => {
  assert.equal(combineModalCredential("", "as-def"), "as-def");
});

test("combineModalCredential — both empty returns empty string", () => {
  assert.equal(combineModalCredential("", ""), "");
  assert.equal(combineModalCredential("   ", "   "), "");
});