25 lines
794 B
TypeScript
25 lines
794 B
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { newSessionId } from "./session_id.ts";
|
|
|
|
describe("newSessionId", () => {
|
|
it("accepts valid UUIDs", () => {
|
|
expect(newSessionId("550e8400-e29b-41d4-a716-446655440000").ok).toBe(true);
|
|
expect(newSessionId("my-session_123").ok).toBe(true);
|
|
});
|
|
|
|
it("rejects path traversal", () => {
|
|
expect(newSessionId("../etc/passwd").ok).toBe(false);
|
|
expect(newSessionId("foo/../../bar").ok).toBe(false);
|
|
expect(newSessionId("foo\\..\\bar").ok).toBe(false);
|
|
});
|
|
|
|
it("rejects empty", () => {
|
|
expect(newSessionId("").ok).toBe(false);
|
|
});
|
|
|
|
it("returns the id string on success", () => {
|
|
const res = newSessionId("abc-123");
|
|
expect(res.ok).toBe(true);
|
|
if (res.ok) expect(res.value).toBe("abc-123");
|
|
});
|
|
}); |