Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/mcp/src/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, it } from "vitest"
import { isApiKey } from "./auth"

describe("isApiKey", () => {
it("returns true for keys with the sm_ prefix and length > 3", () => {
expect(isApiKey("sm_valid_key")).toBe(true)
expect(isApiKey("sm_123")).toBe(true)
})

it("returns false for the bare prefix or missing prefix", () => {
expect(isApiKey("sm_")).toBe(false)
expect(isApiKey("")).toBe(false)
expect(isApiKey("oauth_token")).toBe(false)
})
})
2 changes: 1 addition & 1 deletion apps/mcp/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface AuthUser {
* Check if a token is an API key (starts with "sm_")
*/
export function isApiKey(token: string): boolean {
return token.startsWith("sm_")
return token.startsWith("sm_") && token.length > 3
}

/**
Expand Down