Repository navigation
fix(cli): allow nullable/optional apiKey in cliMitmStartSchema #2857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 3 commits into
cheaper-inference:release/v3.8.6
from
herjarsa:configure-mitm-proxy-antigravity
May 29, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { cliMitmStartSchema } from "../../src/shared/validation/schemas.ts"; | ||
| import { validateBody } from "../../src/shared/validation/helpers.ts"; | ||
| import { resolveApiKey } from "../../src/shared/services/apiKeyResolver.ts"; | ||
|
|
||
| test("cliMitmStartSchema accepts a non-empty string apiKey", () => { | ||
| const result = validateBody(cliMitmStartSchema, { | ||
| apiKey: "sk-test-key-value", | ||
| sudoPassword: "password123", | ||
| }); | ||
| assert.equal(result.success, true); | ||
| if (result.success) { | ||
| assert.equal(result.data.apiKey, "sk-test-key-value"); | ||
| assert.equal(result.data.sudoPassword, "password123"); | ||
| } | ||
| }); | ||
|
|
||
| test("cliMitmStartSchema accepts a null apiKey", () => { | ||
| const result = validateBody(cliMitmStartSchema, { | ||
| apiKey: null, | ||
| sudoPassword: "", | ||
| }); | ||
| assert.equal(result.success, true); | ||
| if (result.success) { | ||
| assert.equal(result.data.apiKey, null); | ||
| assert.equal(result.data.sudoPassword, ""); | ||
| } | ||
| }); | ||
|
|
||
| test("cliMitmStartSchema accepts an omitted apiKey", () => { | ||
| const result = validateBody(cliMitmStartSchema, { | ||
| sudoPassword: "", | ||
| }); | ||
| assert.equal(result.success, true); | ||
| if (result.success) { | ||
| assert.equal(result.data.apiKey, undefined); | ||
| } | ||
| }); | ||
|
Comment on lines
+31
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure the new test("cliMitmStartSchema accepts an omitted apiKey", () => {
const result = validateBody(cliMitmStartSchema, {
sudoPassword: "",
});
assert.equal(result.success, true);
if (result.success) {
assert.equal(result.data.apiKey, undefined);
}
});
test("cliMitmStartSchema accepts a keyId instead of apiKey", () => {
const result = validateBody(cliMitmStartSchema, {
keyId: "key_12345",
sudoPassword: "",
});
assert.equal(result.success, true);
if (result.success) {
assert.equal(result.data.keyId, "key_12345");
assert.equal(result.data.apiKey, undefined);
}
}); |
||
|
|
||
| test("cliMitmStartSchema accepts and parses keyId correctly", () => { | ||
| const result = validateBody(cliMitmStartSchema, { | ||
| keyId: "api-key-id-123", | ||
| sudoPassword: "password", | ||
| }); | ||
| assert.equal(result.success, true); | ||
| if (result.success) { | ||
| assert.equal(result.data.keyId, "api-key-id-123"); | ||
| assert.equal(result.data.apiKey, undefined); | ||
| } | ||
| }); | ||
|
|
||
| test("cliMitmStartSchema accepts null keyId", () => { | ||
| const result = validateBody(cliMitmStartSchema, { | ||
| keyId: null, | ||
| sudoPassword: "", | ||
| }); | ||
| assert.equal(result.success, true); | ||
| if (result.success) { | ||
| assert.equal(result.data.keyId, null); | ||
| } | ||
| }); | ||
|
|
||
| // Regression test: null apiKey + unresolvable keyId must yield the sentinel 'sk_omniroute', | ||
| // which the route guard must reject with a 400 rather than letting it pass to startMitm. | ||
| test("resolveApiKey returns sentinel when apiKey is null and keyId is null", async () => { | ||
| const result = await resolveApiKey(null, null); | ||
| assert.equal( | ||
| result, | ||
| "sk_omniroute", | ||
| "resolveApiKey should return the sentinel when no real key is available" | ||
| ); | ||
| }); | ||
|
|
||
| test("sentinel guard condition catches sk_omniroute and null", () => { | ||
| const SENTINEL = "sk_omniroute"; | ||
| // Simulate what the route guard checks: (!apiKey || apiKey === 'sk_omniroute') | ||
| const shouldReject = (apiKey: string | null | undefined): boolean => | ||
| !apiKey || apiKey === SENTINEL; | ||
|
|
||
| assert.equal(shouldReject(null), true, "null apiKey must be rejected"); | ||
| assert.equal(shouldReject(undefined), true, "undefined apiKey must be rejected"); | ||
| assert.equal(shouldReject("sk_omniroute"), true, "sentinel must be rejected"); | ||
| assert.equal(shouldReject("sk-real-key-abc"), false, "real key must be allowed"); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Zod's
z.object()strips unrecognized keys by default during parsing, anykeyIdsent by the frontend will be stripped from the validated output. To allow the backend to receive and resolve thekeyIdas described in the PR description,keyIdshould be explicitly defined in the schema.