fix(auth): stop the API key placeholder from shadowing Oh My Pi /login credentials (#78)
Oh My Pi kept the unresolved $COMMAND_CODE_API_KEY placeholder as a literal config API key that shadowed its /login credential store and was sent as the Bearer token (401). The placeholder is now registered only on pi, where it keeps the API-key auth method and --api-key working next to OAuth; on OMP the provider omits apiKey unless a real key is configured. Host-supplied placeholders are resolved or stripped on every stream path, and the legacy generate transport uses the same rule. Stored /login OAuth and API-key credentials, --api-key, and env keys are now covered end to end on both pi and Oh My Pi, and CI runs the pi suite against a real binary. Co-authored-by: ebreen <ebreen@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
messagesToCC,
|
||||
parseStreamEventLine,
|
||||
pickCommandCodeApiKey,
|
||||
withResolvedCommandCodeApiKey,
|
||||
projectSlugFromPath,
|
||||
textContent,
|
||||
toJsonSchema,
|
||||
@@ -148,6 +149,42 @@ describe("pickCommandCodeApiKey()", () => {
|
||||
it("trims a real registry key", () => {
|
||||
assert.equal(pickCommandCodeApiKey(" real-registry-key ", "file-key"), "real-registry-key")
|
||||
})
|
||||
|
||||
it("never returns a placeholder as the host fallback", () => {
|
||||
assert.equal(pickCommandCodeApiKey(undefined, "$COMMAND_CODE_API_KEY"), undefined)
|
||||
assert.equal(pickCommandCodeApiKey("$COMMAND_CODE_API_KEY", "$COMMANDCODE_API_KEY"), undefined)
|
||||
assert.equal(pickCommandCodeApiKey("COMMAND_CODE_API_KEY", "COMMANDCODE_API_KEY"), undefined)
|
||||
})
|
||||
|
||||
it("omits a placeholder from registerProvider when no real key is configured", () => {
|
||||
assert.equal(pickCommandCodeApiKey(undefined, undefined), undefined)
|
||||
assert.equal(pickCommandCodeApiKey("$COMMAND_CODE_API_KEY", undefined), undefined)
|
||||
assert.equal(pickCommandCodeApiKey("user_real-key", undefined), "user_real-key")
|
||||
})
|
||||
})
|
||||
|
||||
describe("withResolvedCommandCodeApiKey()", () => {
|
||||
it("replaces a host placeholder with the configured key", () => {
|
||||
assert.deepEqual(
|
||||
withResolvedCommandCodeApiKey({ apiKey: "$COMMAND_CODE_API_KEY", extra: true }, "file-key"),
|
||||
{ apiKey: "file-key", extra: true },
|
||||
)
|
||||
})
|
||||
|
||||
it("drops a placeholder when no configured key exists", () => {
|
||||
assert.deepEqual(
|
||||
withResolvedCommandCodeApiKey({ apiKey: "$COMMAND_CODE_API_KEY" }, undefined),
|
||||
{
|
||||
apiKey: undefined,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it("keeps a real host key and injects a configured key when the host omitted one", () => {
|
||||
const options = { apiKey: "host-key" }
|
||||
assert.equal(withResolvedCommandCodeApiKey(options, "file-key"), options)
|
||||
assert.deepEqual(withResolvedCommandCodeApiKey(undefined, "file-key"), { apiKey: "file-key" })
|
||||
})
|
||||
})
|
||||
|
||||
describe("projectSlugFromPath()", () => {
|
||||
|
||||
Reference in New Issue
Block a user