GeezerVison is showing github.com — fix(auth): respect server username in clients (#25596) · cavanaug/opencode@8694c5b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/acp.ts +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,9 +4,9 @@ import { effectCmd } from "../effect-cmd" | 4 | 4 | import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk" | 5 | 5 | import { ACP } from "@/acp/agent" | 6 | 6 | import { Server } from "@/server/server" | | 7 | +import { ServerAuth } from "@/server/auth" | 7 | 8 | import { createOpencodeClient } from "@opencode-ai/sdk/v2" | 8 | 9 | import { withNetworkOptions, resolveNetworkOptions } from "../network" | 9 | | -import { Flag } from "@opencode-ai/core/flag/flag" | 10 | 10 |
| 11 | 11 | const log = Log.create({ service: "acp-command" }) | 12 | 12 |
| @@ -27,13 +27,7 @@ export const AcpCommand = effectCmd({ | 27 | 27 |
| 28 | 28 | const sdk = createOpencodeClient({ | 29 | 29 | baseUrl: `http://${server.hostname}:${server.port}`, | 30 | | - headers: Flag.OPENCODE_SERVER_PASSWORD | 31 | | - ? { | 32 | | - Authorization: `Basic ${Buffer.from( | 33 | | - `${Flag.OPENCODE_SERVER_USERNAME ?? "opencode"}:${Flag.OPENCODE_SERVER_PASSWORD}`, | 34 | | - ).toString("base64")}`, | 35 | | - } | 36 | | - : undefined, | | 30 | + headers: ServerAuth.headers(), | 37 | 31 | }) | 38 | 32 |
| 39 | 33 | const input = new WritableStream<Uint8Array>({ | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/run.ts +2-7Lines changed: 2 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import { Effect } from "effect" | 5 | 5 | import { UI } from "../ui" | 6 | 6 | import { effectCmd } from "../effect-cmd" | 7 | 7 | import { Flag } from "@opencode-ai/core/flag/flag" | | 8 | +import { ServerAuth } from "@/server/auth" | 8 | 9 | import { EOL } from "os" | 9 | 10 | import { Filesystem } from "@/util/filesystem" | 10 | 11 | import { createOpencodeClient, type OpencodeClient, type ToolPart } from "@opencode-ai/sdk/v2" | @@ -656,13 +657,7 @@ export const RunCommand = effectCmd({ | 656 | 657 | } | 657 | 658 |
| 658 | 659 | if (args.attach) { | 659 | | - const headers = (() => { | 660 | | - const password = args.password ?? process.env.OPENCODE_SERVER_PASSWORD | 661 | | - if (!password) return undefined | 662 | | - const username = process.env.OPENCODE_SERVER_USERNAME ?? "opencode" | 663 | | - const auth = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}` | 664 | | - return { Authorization: auth } | 665 | | - })() | | 660 | + const headers = ServerAuth.headers({ password: args.password }) | 666 | 661 | const sdk = createOpencodeClient({ baseUrl: args.attach, directory, headers }) | 667 | 662 | return await execute(sdk) | 668 | 663 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/attach.ts +7-6Lines changed: 7 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32" | 5 | 5 | import { TuiConfig } from "@/cli/cmd/tui/config/tui" | 6 | 6 | import { errorMessage } from "@/util/error" | 7 | 7 | import { validateSession } from "./validate-session" | | 8 | +import { ServerAuth } from "@/server/auth" | 8 | 9 |
| 9 | 10 | export const AttachCommand = cmd({ | 10 | 11 | command: "attach <url>", | @@ -38,6 +39,11 @@ export const AttachCommand = cmd({ | 38 | 39 | alias: ["p"], | 39 | 40 | type: "string", | 40 | 41 | describe: "basic auth password (defaults to OPENCODE_SERVER_PASSWORD)", | | 42 | + }) | | 43 | + .option("username", { | | 44 | + alias: ["u"], | | 45 | + type: "string", | | 46 | + describe: "basic auth username (defaults to OPENCODE_SERVER_USERNAME or 'opencode')", | 41 | 47 | }), | 42 | 48 | handler: async (args) => { | 43 | 49 | const unguard = win32InstallCtrlCGuard() | @@ -60,12 +66,7 @@ export const AttachCommand = cmd({ | 60 | 66 | return args.dir | 61 | 67 | } | 62 | 68 | })() | 63 | | - const headers = (() => { | 64 | | - const password = args.password ?? process.env.OPENCODE_SERVER_PASSWORD | 65 | | - if (!password) return undefined | 66 | | - const auth = `Basic ${Buffer.from(`opencode:${password}`).toString("base64")}` | 67 | | - return { Authorization: auth } | 68 | | - })() | | 69 | + const headers = ServerAuth.headers({ password: args.password, username: args.username }) | 69 | 70 | const config = await TuiConfig.get() | 70 | 71 |
| 71 | 72 | try { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/worker.ts +2-9Lines changed: 2 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ import { Rpc } from "@/util/rpc" | 7 | 7 | import { upgrade } from "@/cli/upgrade" | 8 | 8 | import { Config } from "@/config/config" | 9 | 9 | import { GlobalBus } from "@/bus/global" | 10 | | -import { Flag } from "@opencode-ai/core/flag/flag" | | 10 | +import { ServerAuth } from "@/server/auth" | 11 | 11 | import { writeHeapSnapshot } from "node:v8" | 12 | 12 | import { Heap } from "@/cli/heap" | 13 | 13 | import { AppRuntime } from "@/effect/app-runtime" | @@ -50,7 +50,7 @@ let server: Awaited<ReturnType<typeof Server.listen>> | undefined | 50 | 50 | export const rpc = { | 51 | 51 | async fetch(input: { url: string; method: string; headers: Record<string, string>; body?: string }) { | 52 | 52 | const headers = { ...input.headers } | 53 | | - const auth = getAuthorizationHeader() | | 53 | + const auth = ServerAuth.header() | 54 | 54 | if (auth && !headers["authorization"] && !headers["Authorization"]) { | 55 | 55 | headers["Authorization"] = auth | 56 | 56 | } | @@ -102,10 +102,3 @@ export const rpc = { | 102 | 102 | } | 103 | 103 |
| 104 | 104 | Rpc.listen(rpc) | 105 | | - | 106 | | -function getAuthorizationHeader(): string | undefined { | 107 | | - const password = Flag.OPENCODE_SERVER_PASSWORD | 108 | | - if (!password) return undefined | 109 | | - const username = Flag.OPENCODE_SERVER_USERNAME ?? "opencode" | 110 | | - return `Basic ${btoa(`${username}:${password}`)}` | 111 | | -} |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/index.ts +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ import { Bus } from "../bus" | 10 | 10 | import * as Log from "@opencode-ai/core/util/log" | 11 | 11 | import { createOpencodeClient } from "@opencode-ai/sdk" | 12 | 12 | import { Flag } from "@opencode-ai/core/flag/flag" | | 13 | +import { ServerAuth } from "@/server/auth" | 13 | 14 | import { CodexAuthPlugin } from "./codex" | 14 | 15 | import { Session } from "@/session/session" | 15 | 16 | import { NamedError } from "@opencode-ai/core/util/error" | @@ -124,11 +125,7 @@ export const layer = Layer.effect( | 124 | 125 | const client = createOpencodeClient({ | 125 | 126 | baseUrl: "http://localhost:4096", | 126 | 127 | directory: ctx.directory, | 127 | | - headers: Flag.OPENCODE_SERVER_PASSWORD | 128 | | - ? { | 129 | | - Authorization: `Basic ${Buffer.from(`${Flag.OPENCODE_SERVER_USERNAME ?? "opencode"}:${Flag.OPENCODE_SERVER_PASSWORD}`).toString("base64")}`, | 130 | | - } | 131 | | - : undefined, | | 128 | + headers: ServerAuth.headers(), | 132 | 129 | fetch: async (...args) => Server.Default().app.fetch(...args), | 133 | 130 | }) | 134 | 131 | const cfg = yield* config.get() | |
Collapse file Copy file name to clipboard +48Lines changed: 48 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +export * as ServerAuth from "./auth" | | 2 | + | | 3 | +import { ConfigService } from "@/effect/config-service" | | 4 | +import { Flag } from "@opencode-ai/core/flag/flag" | | 5 | +import { Config as EffectConfig, Context, Option, Redacted } from "effect" | | 6 | + | | 7 | +export type Credentials = { | | 8 | + password?: string | | 9 | + username?: string | | 10 | +} | | 11 | + | | 12 | +export type DecodedCredentials = { | | 13 | + readonly username: string | | 14 | + readonly password: Redacted.Redacted | | 15 | +} | | 16 | + | | 17 | +export class Config extends ConfigService.Service<Config>()("@opencode/ServerAuthConfig", { | | 18 | + password: EffectConfig.string("OPENCODE_SERVER_PASSWORD").pipe(EffectConfig.option), | | 19 | + username: EffectConfig.string("OPENCODE_SERVER_USERNAME").pipe(EffectConfig.withDefault("opencode")), | | 20 | +}) {} | | 21 | + | | 22 | +export type Info = Context.Service.Shape<typeof Config> | | 23 | + | | 24 | +export function required(config: Info) { | | 25 | + return Option.isSome(config.password) && config.password.value !== "" | | 26 | +} | | 27 | + | | 28 | +export function authorized(credentials: DecodedCredentials, config: Info) { | | 29 | + return ( | | 30 | + Option.isSome(config.password) && | | 31 | + credentials.username === config.username && | | 32 | + Redacted.value(credentials.password) === config.password.value | | 33 | + ) | | 34 | +} | | 35 | + | | 36 | +export function header(credentials?: Credentials) { | | 37 | + const password = credentials?.password ?? Flag.OPENCODE_SERVER_PASSWORD | | 38 | + if (!password) return undefined | | 39 | + | | 40 | + const username = credentials?.username ?? Flag.OPENCODE_SERVER_USERNAME ?? "opencode" | | 41 | + return `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}` | | 42 | +} | | 43 | + | | 44 | +export function headers(credentials?: Credentials) { | | 45 | + const authorization = header(credentials) | | 46 | + if (!authorization) return undefined | | 47 | + return { Authorization: authorization } | | 48 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/routes/instance/httpapi/middleware/authorization.ts +13-36Lines changed: 13 additions & 36 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { ConfigService } from "@/effect/config-service" | 2 | | -import { Config, Context, Effect, Encoding, Layer, Option, Redacted } from "effect" | | 1 | +import { ServerAuth } from "@/server/auth" | | 2 | +import { Effect, Encoding, Layer, Redacted } from "effect" | 3 | 3 | import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http" | 4 | 4 | import { HttpApiError, HttpApiMiddleware, HttpApiSecurity } from "effect/unstable/httpapi" | 5 | 5 |
| @@ -18,41 +18,18 @@ export class Authorization extends HttpApiMiddleware.Service<Authorization>()( | 18 | 18 | }, | 19 | 19 | ) {} | 20 | 20 |
| 21 | | -export class ServerAuthConfig extends ConfigService.Service<ServerAuthConfig>()( | 22 | | - "@opencode/ExperimentalHttpApiServerAuthConfig", | 23 | | - { | 24 | | - password: Config.string("OPENCODE_SERVER_PASSWORD").pipe(Config.option), | 25 | | - username: Config.string("OPENCODE_SERVER_USERNAME").pipe(Config.withDefault("opencode")), | 26 | | - }, | 27 | | -) {} | 28 | | - | 29 | 21 | function validateCredential<A, E, R>( | 30 | 22 | effect: Effect.Effect<A, E, R>, | 31 | | - credential: { readonly username: string; readonly password: Redacted.Redacted }, | 32 | | - config: Context.Service.Shape<typeof ServerAuthConfig>, | | 23 | + credential: ServerAuth.DecodedCredentials, | | 24 | + config: ServerAuth.Info, | 33 | 25 | ) { | 34 | 26 | return Effect.gen(function* () { | 35 | | - if (!isAuthRequired(config)) return yield* effect | 36 | | - if (!isCredentialAuthorized(credential, config)) return yield* new HttpApiError.Unauthorized({}) | | 27 | + if (!ServerAuth.required(config)) return yield* effect | | 28 | + if (!ServerAuth.authorized(credential, config)) return yield* new HttpApiError.Unauthorized({}) | 37 | 29 | return yield* effect | 38 | 30 | }) | 39 | 31 | } | 40 | 32 |
| 41 | | -function isAuthRequired(config: Context.Service.Shape<typeof ServerAuthConfig>) { | 42 | | - return Option.isSome(config.password) && config.password.value !== "" | 43 | | -} | 44 | | - | 45 | | -function isCredentialAuthorized( | 46 | | - credential: { readonly username: string; readonly password: Redacted.Redacted }, | 47 | | - config: Context.Service.Shape<typeof ServerAuthConfig>, | 48 | | -) { | 49 | | - return ( | 50 | | - Option.isSome(config.password) && | 51 | | - credential.username === config.username && | 52 | | - Redacted.value(credential.password) === config.password.value | 53 | | - ) | 54 | | -} | 55 | | - | 56 | 33 | function decodeCredential(input: string) { | 57 | 34 | const emptyCredential = { | 58 | 35 | username: "", | @@ -78,11 +55,11 @@ function decodeCredential(input: string) { | 78 | 55 |
| 79 | 56 | function validateRawCredential<A, E, R>( | 80 | 57 | effect: Effect.Effect<A, E, R>, | 81 | | - credential: { readonly username: string; readonly password: Redacted.Redacted }, | 82 | | - config: Context.Service.Shape<typeof ServerAuthConfig>, | | 58 | + credential: ServerAuth.DecodedCredentials, | | 59 | + config: ServerAuth.Info, | 83 | 60 | ) { | 84 | | - if (!isAuthRequired(config)) return effect | 85 | | - if (!isCredentialAuthorized(credential, config)) | | 61 | + if (!ServerAuth.required(config)) return effect | | 62 | + if (!ServerAuth.authorized(credential, config)) | 86 | 63 | return Effect.succeed( | 87 | 64 | HttpServerResponse.empty({ | 88 | 65 | status: UNAUTHORIZED, | @@ -94,8 +71,8 @@ function validateRawCredential<A, E, R>( | 94 | 71 |
| 95 | 72 | export const authorizationRouterMiddleware = HttpRouter.middleware()( | 96 | 73 | Effect.gen(function* () { | 97 | | - const config = yield* ServerAuthConfig | 98 | | - if (!isAuthRequired(config)) return (effect) => effect | | 74 | + const config = yield* ServerAuth.Config | | 75 | + if (!ServerAuth.required(config)) return (effect) => effect | 99 | 76 |
| 100 | 77 | return (effect) => | 101 | 78 | Effect.gen(function* () { | @@ -122,7 +99,7 @@ export const authorizationRouterMiddleware = HttpRouter.middleware()( | 122 | 99 | export const authorizationLayer = Layer.effect( | 123 | 100 | Authorization, | 124 | 101 | Effect.gen(function* () { | 125 | | - const config = yield* ServerAuthConfig | | 102 | + const config = yield* ServerAuth.Config | 126 | 103 | return Authorization.of({ | 127 | 104 | basic: (effect, { credential }) => validateCredential(effect, credential, config), | 128 | 105 | authToken: (effect, { credential }) => | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/routes/instance/httpapi/server.ts +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,8 +46,9 @@ import { Worktree } from "@/worktree" | 46 | 46 | import { Workspace } from "@/control-plane/workspace" | 47 | 47 | import { isAllowedCorsOrigin, type CorsOptions } from "@/server/cors" | 48 | 48 | import { serveUIEffect } from "@/server/shared/ui" | | 49 | +import { ServerAuth } from "@/server/auth" | 49 | 50 | import { InstanceHttpApi, RootHttpApi } from "./api" | 50 | | -import { ServerAuthConfig, authorizationLayer, authorizationRouterMiddleware } from "./middleware/authorization" | | 51 | +import { authorizationLayer, authorizationRouterMiddleware } from "./middleware/authorization" | 51 | 52 | import { EventApi, eventHandlers } from "./event" | 52 | 53 | import { configHandlers } from "./handlers/config" | 53 | 54 | import { controlHandlers } from "./handlers/control" | @@ -97,7 +98,7 @@ const rootApiRoutes = HttpApiBuilder.layer(RootHttpApi).pipe(Layer.provide([cont | 97 | 98 | const instanceRouterLayer = authorizationRouterMiddleware | 98 | 99 | .combine(instanceRouterMiddleware) | 99 | 100 | .combine(workspaceRouterMiddleware) | 100 | | - .layer.pipe(Layer.provide(Socket.layerWebSocketConstructorGlobal), Layer.provide(ServerAuthConfig.defaultLayer)) | | 101 | + .layer.pipe(Layer.provide(Socket.layerWebSocketConstructorGlobal), Layer.provide(ServerAuth.Config.defaultLayer)) | 101 | 102 | const eventApiRoutes = HttpApiBuilder.layer(EventApi).pipe( | 102 | 103 | Layer.provide(eventHandlers), | 103 | 104 | Layer.provide(instanceRouterLayer), | @@ -125,7 +126,7 @@ const instanceApiRoutes = HttpApiBuilder.layer(InstanceHttpApi).pipe( | 125 | 126 | const rawInstanceRoutes = Layer.mergeAll(ptyConnectRoute).pipe(Layer.provide(instanceRouterLayer)) | 126 | 127 | const instanceRoutes = Layer.mergeAll(rawInstanceRoutes, instanceApiRoutes).pipe( | 127 | 128 | Layer.provide([ | 128 | | - authorizationLayer.pipe(Layer.provide(ServerAuthConfig.defaultLayer)), | | 129 | + authorizationLayer.pipe(Layer.provide(ServerAuth.Config.defaultLayer)), | 129 | 130 | workspaceRoutingLayer.pipe(Layer.provide(Socket.layerWebSocketConstructorGlobal)), | 130 | 131 | instanceContextLayer, | 131 | 132 | ]), | @@ -137,7 +138,7 @@ const uiRoute = HttpRouter.use((router) => | 137 | 138 | const client = yield* HttpClient.HttpClient | 138 | 139 | yield* router.add("*", "/*", (request) => serveUIEffect(request, { fs, client })) | 139 | 140 | }), | 140 | | -).pipe(Layer.provide(authorizationRouterMiddleware.layer.pipe(Layer.provide(ServerAuthConfig.defaultLayer)))) | | 141 | +).pipe(Layer.provide(authorizationRouterMiddleware.layer.pipe(Layer.provide(ServerAuth.Config.defaultLayer)))) | 141 | 142 |
| 142 | 143 | export function createRoutes(corsOptions?: CorsOptions) { | 143 | 144 | return Layer.mergeAll(rootApiRoutes, eventApiRoutes, instanceRoutes, uiRoute).pipe( | |
Collapse file Copy file name to clipboard +59Lines changed: 59 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { afterEach, describe, expect, test } from "bun:test" | | 2 | +import { Option, Redacted } from "effect" | | 3 | +import { Flag } from "@opencode-ai/core/flag/flag" | | 4 | +import { ServerAuth } from "../../src/server/auth" | | 5 | + | | 6 | +const original = { | | 7 | + OPENCODE_SERVER_PASSWORD: Flag.OPENCODE_SERVER_PASSWORD, | | 8 | + OPENCODE_SERVER_USERNAME: Flag.OPENCODE_SERVER_USERNAME, | | 9 | +} | | 10 | + | | 11 | +afterEach(() => { | | 12 | + Flag.OPENCODE_SERVER_PASSWORD = original.OPENCODE_SERVER_PASSWORD | | 13 | + Flag.OPENCODE_SERVER_USERNAME = original.OPENCODE_SERVER_USERNAME | | 14 | +}) | | 15 | + | | 16 | +describe("ServerAuth", () => { | | 17 | + test("does not emit auth headers without a password", () => { | | 18 | + Flag.OPENCODE_SERVER_PASSWORD = undefined | | 19 | + Flag.OPENCODE_SERVER_USERNAME = "alice" | | 20 | + | | 21 | + expect(ServerAuth.header()).toBeUndefined() | | 22 | + expect(ServerAuth.headers()).toBeUndefined() | | 23 | + }) | | 24 | + | | 25 | + test("defaults to the opencode username", () => { | | 26 | + Flag.OPENCODE_SERVER_PASSWORD = "secret" | | 27 | + Flag.OPENCODE_SERVER_USERNAME = undefined | | 28 | + | | 29 | + expect(ServerAuth.headers()).toEqual({ | | 30 | + Authorization: `Basic ${Buffer.from("opencode:secret").toString("base64")}`, | | 31 | + }) | | 32 | + }) | | 33 | + | | 34 | + test("uses the configured username", () => { | | 35 | + Flag.OPENCODE_SERVER_PASSWORD = "secret" | | 36 | + Flag.OPENCODE_SERVER_USERNAME = "alice" | | 37 | + | | 38 | + expect(ServerAuth.headers()).toEqual({ | | 39 | + Authorization: `Basic ${Buffer.from("alice:secret").toString("base64")}`, | | 40 | + }) | | 41 | + }) | | 42 | + | | 43 | + test("prefers explicit credentials", () => { | | 44 | + Flag.OPENCODE_SERVER_PASSWORD = "secret" | | 45 | + Flag.OPENCODE_SERVER_USERNAME = "alice" | | 46 | + | | 47 | + expect(ServerAuth.headers({ password: "cli-secret", username: "bob" })).toEqual({ | | 48 | + Authorization: `Basic ${Buffer.from("bob:cli-secret").toString("base64")}`, | | 49 | + }) | | 50 | + }) | | 51 | + | | 52 | + test("validates decoded credentials against effect config", () => { | | 53 | + const config = { password: Option.some("secret"), username: "alice" } | | 54 | + | | 55 | + expect(ServerAuth.required(config)).toBe(true) | | 56 | + expect(ServerAuth.authorized({ username: "alice", password: Redacted.make("secret") }, config)).toBe(true) | | 57 | + expect(ServerAuth.authorized({ username: "opencode", password: Redacted.make("secret") }, config)).toBe(false) | | 58 | + }) | | 59 | +}) |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/server/httpapi-authorization.test.ts +5-8Lines changed: 5 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,11 +3,8 @@ import { describe, expect } from "bun:test" | 3 | 3 | import { Effect, Layer, Option, Schema } from "effect" | 4 | 4 | import { HttpClient, HttpClientRequest, HttpRouter } from "effect/unstable/http" | 5 | 5 | import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi" | 6 | | -import { | 7 | | - Authorization, | 8 | | - ServerAuthConfig, | 9 | | - authorizationLayer, | 10 | | -} from "../../src/server/routes/instance/httpapi/middleware/authorization" | | 6 | +import { ServerAuth } from "../../src/server/auth" | | 7 | +import { Authorization, authorizationLayer } from "../../src/server/routes/instance/httpapi/middleware/authorization" | 11 | 8 | import { testEffect } from "../lib/effect" | 12 | 9 |
| 13 | 10 | const Api = HttpApi.make("test-authorization").add( | @@ -27,9 +24,9 @@ const apiLayer = HttpRouter.serve( | 27 | 24 | { disableListenLog: true, disableLogger: true }, | 28 | 25 | ).pipe(Layer.provideMerge(NodeHttpServer.layerTest)) | 29 | 26 |
| 30 | | -const noAuthLayer = ServerAuthConfig.layer({ password: Option.none(), username: "opencode" }) | 31 | | -const secretLayer = ServerAuthConfig.layer({ password: Option.some("secret"), username: "opencode" }) | 32 | | -const kitSecretLayer = ServerAuthConfig.layer({ password: Option.some("secret"), username: "kit" }) | | 27 | +const noAuthLayer = ServerAuth.Config.layer({ password: Option.none(), username: "opencode" }) | | 28 | +const secretLayer = ServerAuth.Config.layer({ password: Option.some("secret"), username: "opencode" }) | | 29 | +const kitSecretLayer = ServerAuth.Config.layer({ password: Option.some("secret"), username: "kit" }) | 33 | 30 |
| 34 | 31 | const it = testEffect(apiLayer.pipe(Layer.provide(noAuthLayer))) | 35 | 32 | const itSecret = testEffect(apiLayer.pipe(Layer.provide(secretLayer))) | |
|