Open the bot last visited, else the coordinator
`/admin/bots` sent the super admin to the coordinator and everyone else to their latest bot, which lost the thread each time the tab was reopened. The conversation pages now record where the browser is in two HttpOnly cookies (`cobble_last_visited_bot_id`, `..._workspace_id`, a year, `Secure` only over HTTPS), and the landing page opens that conversation again, in its workspace when it was one. A stale cookie can't loop: `grabReachableConversation` re-checks it with `grabUserConversation`, the gate the conversation pages use, so a revoked grant, a deleted bot or an archived workspace falls back to the coordinator (super admin) or the latest bot, first workspace, empty page. Signing out clears both cookies so the next user on that browser doesn't land in the previous one's conversation.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import parseLastVisitedBot from "./parse-last-visited-bot";
|
||||
|
||||
describe("parseLastVisitedBot", () => {
|
||||
test("a bot's own chat", () => {
|
||||
expect(parseLastVisitedBot({ bot_id: "3" })).toEqual({ bot_id: 3, workspace_id: null });
|
||||
expect(parseLastVisitedBot({ bot_id: 3, workspace_id: "" })).toEqual({
|
||||
bot_id: 3,
|
||||
workspace_id: null,
|
||||
});
|
||||
expect(parseLastVisitedBot({ bot_id: 3, workspace_id: null })).toEqual({
|
||||
bot_id: 3,
|
||||
workspace_id: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("a workspace conversation", () => {
|
||||
expect(parseLastVisitedBot({ bot_id: "3", workspace_id: "7" })).toEqual({
|
||||
bot_id: 3,
|
||||
workspace_id: 7,
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects ids that aren't positive whole numbers", () => {
|
||||
expect(parseLastVisitedBot({})).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "" })).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "0" })).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "-1" })).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "1.5" })).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "abc" })).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "1 OR 1=1" })).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "99999999999999999999" })).toBeNull();
|
||||
});
|
||||
|
||||
test("a bad workspace falls back to nothing, never to its own chat", () => {
|
||||
expect(parseLastVisitedBot({ bot_id: "3", workspace_id: "abc" })).toBeNull();
|
||||
expect(parseLastVisitedBot({ bot_id: "3", workspace_id: "0" })).toBeNull();
|
||||
});
|
||||
|
||||
test("trims what a cookie header may carry", () => {
|
||||
expect(parseLastVisitedBot({ bot_id: " 3 ", workspace_id: " 7 " })).toEqual({
|
||||
bot_id: 3,
|
||||
workspace_id: 7,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user