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.5 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import { configureUpstreamCa } from "../../src/mitm/upstreamTrust.ts";

test("configureUpstreamCa — no-op when pemPath is undefined", () => {
  assert.doesNotThrow(() => configureUpstreamCa(undefined));
});

test("configureUpstreamCa — no-op when pemPath is empty string", () => {
  assert.doesNotThrow(() => configureUpstreamCa(""));
});

test("configureUpstreamCa — throws structured error for non-existent path", () => {
  const fakePath = "/nonexistent/path/that/does/not/exist/ca.pem";
  try {
    configureUpstreamCa(fakePath);
    assert.fail("Should have thrown");
  } catch (err) {
    assert.ok(err instanceof Error);
    assert.ok(!err.message.includes(" at /"), `Error message should not contain stack trace: ${err.message}`);
    assert.ok(err.message.includes(fakePath));
  }
});

test("configureUpstreamCa — error message contains AGENTBRIDGE_UPSTREAM_CA_CERT label", () => {
  const fakePath = "/no/such/file.pem";
  try {
    configureUpstreamCa(fakePath);
    assert.fail("Should have thrown");
  } catch (err) {
    assert.ok(err instanceof Error);
    assert.ok(err.message.includes("AGENTBRIDGE_UPSTREAM_CA_CERT"));
  }
});

test("configureUpstreamCa — error does not embed multiline stack trace in message", () => {
  try {
    configureUpstreamCa("/definitely/does/not/exist.pem");
  } catch (err) {
    assert.ok(err instanceof Error);
    assert.ok(!err.message.includes("\n    at "));
  }
});