mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-26 06:04:08 +00:00
Merge 7fc3dc2d7d into f355dc8039
This commit is contained in:
commit
9e7e469c5d
3 changed files with 34 additions and 3 deletions
|
|
@ -214,6 +214,34 @@ describe("MCP authentication", () => {
|
|||
expect(error).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("rejects an API key whose session has no organization", async () => {
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {})
|
||||
const error = vi.spyOn(console, "error").mockImplementation(() => {})
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn().mockResolvedValue(
|
||||
Response.json({
|
||||
user: { id: "user_test", email: "test@example.com", name: "Test" },
|
||||
org: null,
|
||||
session: null,
|
||||
role: null,
|
||||
accessType: "full",
|
||||
containerTags: null,
|
||||
scope: { type: "full", permission: "write" },
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
await expect(
|
||||
validateApiKey("sm_noorg_key_0123456789abcdef", API_URL),
|
||||
).resolves.toBeNull()
|
||||
expect(warn).toHaveBeenCalledTimes(1)
|
||||
expect(warn).toHaveBeenCalledWith(
|
||||
"API key rejected: session has no organization",
|
||||
)
|
||||
expect(error).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("rejects malformed API keys without an API request", async () => {
|
||||
const fetchSpy = vi.fn()
|
||||
vi.stubGlobal("fetch", fetchSpy)
|
||||
|
|
|
|||
|
|
@ -117,7 +117,10 @@ export async function validateApiKey(
|
|||
try {
|
||||
const session = await fetchSession(token, apiUrl)
|
||||
const organizationId = session.org?.id
|
||||
if (!organizationId) return null
|
||||
if (!organizationId) {
|
||||
console.warn("API key rejected: session has no organization")
|
||||
return null
|
||||
}
|
||||
|
||||
const user: AuthUser = {
|
||||
userId: session.user.id,
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ export const sessionInfoSchema = z
|
|||
email: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
}),
|
||||
org: z.looseObject({ id: z.string().min(1) }).optional(),
|
||||
role: z.string().optional(),
|
||||
org: z.looseObject({ id: z.string().min(1) }).nullish(),
|
||||
role: z.string().nullish(),
|
||||
accessType: z.enum(["full", "restricted"]).optional(),
|
||||
containerTags: z.array(sessionNamespaceAccessSchema).nullable().optional(),
|
||||
scope: sessionScopeSchema.optional(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue