auth.test.ts 670 B

12345678910111213
  1. import { expect, test } from "bun:test"
  2. import { ServerAuth } from "@opencode-ai/server/auth"
  3. import { Option, Redacted } from "effect"
  4. test("accepts only the fixed opencode username", () => {
  5. const config = { password: Option.some("secret"), username: "opencode" }
  6. expect(ServerAuth.authorized({ username: "opencode", password: Redacted.make("secret") }, config)).toBe(true)
  7. expect(ServerAuth.authorized({ username: "custom", password: Redacted.make("secret") }, config)).toBe(false)
  8. })
  9. test("encodes the fixed opencode username", () => {
  10. expect(ServerAuth.header({ password: "secret" })).toBe(`Basic ${Buffer.from("opencode:secret").toString("base64")}`)
  11. })