Dashboard: Connect dialog with the API key and opencode setup
The API key button is Connect again. Besides the key, it walks through adding this server to opencode: type the API's address (remembered in the browser; prefilled on a LAN visit) and it fills in a command that saves the key to a 0600 file without it touching shell history, and the provider block from the same builder as `llmhost opencode-config`. GET /api/connect replaces /api/key, behind the same sign-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6fd82448c5
commit
04ff14c58f
4 changed files with 93 additions and 18 deletions
|
|
@ -98,10 +98,17 @@ check("config reports key mode", st == 200 and json.loads(body)["mode"] == "key"
|
|||
check("status without key -> 401", req(srv, "GET", "/api/status")[0] == 401)
|
||||
check("status with key -> 200", req(srv, "GET", "/api/status", {"Authorization": f"Bearer {KEY}"})[0] == 200)
|
||||
check("no /auth/login without OIDC", req(srv, "GET", "/auth/login")[0] == 404)
|
||||
check("/api/key needs the key", req(srv, "GET", "/api/key")[0] == 401)
|
||||
st, h, body, _ = req(srv, "GET", "/api/key", {"Authorization": f"Bearer {KEY}"})
|
||||
check("/api/key returns it", st == 200 and json.loads(body) == {"key": KEY}, body)
|
||||
check("/api/key isn't cached", h.get("cache-control") == "no-store", h)
|
||||
paths.save_config(harness.config())
|
||||
check("/api/connect needs the key", req(srv, "GET", "/api/connect")[0] == 401)
|
||||
st, h, body, _ = req(srv, "GET", "/api/connect", {"Authorization": f"Bearer {KEY}"})
|
||||
cx = json.loads(body)
|
||||
check("/api/connect returns the key", st == 200 and cx["key"] == KEY, body[:200])
|
||||
check("/api/connect isn't cached", h.get("cache-control") == "no-store", h)
|
||||
blk = cx["opencode"]
|
||||
check("opencode block is the openai-compatible provider", blk["npm"] == "@ai-sdk/openai-compatible", blk)
|
||||
check("opencode block offers the one alias", list(blk["models"]) == [cx["model"]] == ["default"], blk["models"])
|
||||
check("opencode block leaves the address to the page", "LABEL" in blk["name"] and "HOST" in blk["options"]["baseURL"], blk)
|
||||
check("the key isn't inlined in the block", KEY not in json.dumps(blk))
|
||||
srv.shutdown()
|
||||
|
||||
print("\n2. OIDC mode refuses the key and unsigned visitors")
|
||||
|
|
@ -169,10 +176,10 @@ st, _, _, _ = req(srv, "POST", "/api/stats/reset", {**PUB_HOST, "Cookie": sess,
|
|||
check("POST from another origin -> 403", st == 403, st)
|
||||
st, _, _, _ = req(srv, "POST", "/api/stats/reset", {**PUB_HOST, "Cookie": sess, "Origin": PUBLIC})
|
||||
check("POST from the dashboard's origin -> 200", st == 200, st)
|
||||
check("/api/key refused without a session", req(srv, "GET", "/api/key", PUB_HOST)[0] == 401)
|
||||
check("/api/key refused for the key alone", req(srv, "GET", "/api/key", {**PUB_HOST, "Authorization": f"Bearer {KEY}"})[0] == 401)
|
||||
st, _, body, _ = req(srv, "GET", "/api/key", {**PUB_HOST, "Cookie": sess})
|
||||
check("signed in: /api/key returns it", st == 200 and json.loads(body) == {"key": KEY}, body)
|
||||
check("/api/connect refused without a session", req(srv, "GET", "/api/connect", PUB_HOST)[0] == 401)
|
||||
check("/api/connect refused for the key alone", req(srv, "GET", "/api/connect", {**PUB_HOST, "Authorization": f"Bearer {KEY}"})[0] == 401)
|
||||
st, _, body, _ = req(srv, "GET", "/api/connect", {**PUB_HOST, "Cookie": sess})
|
||||
check("signed in: /api/connect returns the key", st == 200 and json.loads(body)["key"] == KEY, body[:200])
|
||||
check("only the session's hash is stored", sess.split("=", 1)[1] not in o.sessions)
|
||||
|
||||
print("\n5. sign-ins that must fail")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue