- 品牌替换:OpenCode/opencode → AirCoding/aircoding(16+ 文件) - Logo ASCII art:修复 left/right 行数不匹配导致的启动崩溃 - 启动诊断:添加 OPENCODE_PRINT_TIMING 计时探针 - dev 模式默认 --pure 跳过外部插件加载 - AGENTS.md 模板:追加 AirCoding 多 Agent 专项段落 - architect prompt + plugin:强化 AGENTS.md 产出验证
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { afterEach, describe, expect, test } from "bun:test"
|
|
import { Option, Redacted } from "effect"
|
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
|
import { ServerAuth } from "../../src/server/auth"
|
|
|
|
const original = {
|
|
OPENCODE_SERVER_PASSWORD: Flag.OPENCODE_SERVER_PASSWORD,
|
|
OPENCODE_SERVER_USERNAME: Flag.OPENCODE_SERVER_USERNAME,
|
|
}
|
|
|
|
afterEach(() => {
|
|
Flag.OPENCODE_SERVER_PASSWORD = original.OPENCODE_SERVER_PASSWORD
|
|
Flag.OPENCODE_SERVER_USERNAME = original.OPENCODE_SERVER_USERNAME
|
|
})
|
|
|
|
describe("ServerAuth", () => {
|
|
test("does not emit auth headers without a password", () => {
|
|
Flag.OPENCODE_SERVER_PASSWORD = undefined
|
|
Flag.OPENCODE_SERVER_USERNAME = "alice"
|
|
|
|
expect(ServerAuth.header()).toBeUndefined()
|
|
expect(ServerAuth.headers()).toBeUndefined()
|
|
})
|
|
|
|
test("defaults to the opencode username", () => {
|
|
Flag.OPENCODE_SERVER_PASSWORD = "secret"
|
|
Flag.OPENCODE_SERVER_USERNAME = undefined
|
|
|
|
expect(ServerAuth.headers()).toEqual({
|
|
Authorization: `Basic ${Buffer.from("opencode:secret").toString("base64")}`,
|
|
})
|
|
})
|
|
|
|
test("uses the configured username", () => {
|
|
Flag.OPENCODE_SERVER_PASSWORD = "secret"
|
|
Flag.OPENCODE_SERVER_USERNAME = "alice"
|
|
|
|
expect(ServerAuth.headers()).toEqual({
|
|
Authorization: `Basic ${Buffer.from("alice:secret").toString("base64")}`,
|
|
})
|
|
})
|
|
|
|
test("prefers explicit credentials", () => {
|
|
Flag.OPENCODE_SERVER_PASSWORD = "secret"
|
|
Flag.OPENCODE_SERVER_USERNAME = "alice"
|
|
|
|
expect(ServerAuth.headers({ password: "cli-secret", username: "bob" })).toEqual({
|
|
Authorization: `Basic ${Buffer.from("bob:cli-secret").toString("base64")}`,
|
|
})
|
|
})
|
|
|
|
test("validates decoded credentials against effect config", () => {
|
|
const config = { password: Option.some("secret"), username: "alice" }
|
|
|
|
expect(ServerAuth.required(config)).toBe(true)
|
|
expect(ServerAuth.authorized({ username: "alice", password: Redacted.make("secret") }, config)).toBe(true)
|
|
expect(ServerAuth.authorized({ username: "opencode", password: Redacted.make("secret") }, config)).toBe(false)
|
|
})
|
|
})
|