Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { deriveAuthClientMetadata, resolveSessionCookieName } from "./utils.ts";
4
5describe("deriveAuthClientMetadata", () => {
6 it("labels Electron user agents as Electron instead of Chrome", () => {
7 const metadata = deriveAuthClientMetadata({
8 request: {
9 headers: {
10 "user-agent":
11 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) t3code/0.0.15 Chrome/136.0.7103.93 Electron/36.3.2 Safari/537.36",
12 },
13 source: {
14 remoteAddress: "::ffff:127.0.0.1",
15 },
16 } as never,
17 });
18
19 expect(metadata).toMatchObject({
20 browser: "Electron",
21 deviceType: "desktop",
22 ipAddress: "127.0.0.1",
23 os: "macOS",
24 });
25 });
26
27 it("applies client-presented display identity without replacing transport metadata", () => {
28 const metadata = deriveAuthClientMetadata({
29 request: {
30 headers: {
31 "user-agent":
32 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 Chrome/136.0.7103.93 Electron/36.3.2 Safari/537.36",
33 },
34 source: {
35 remoteAddress: "::ffff:192.168.213.72",
36 },
37 } as never,
38 presented: {
39 label: "T3 Code Mobile",
40 deviceType: "mobile",
41 os: "iOS",
42 },
43 });
44
45 expect(metadata).toMatchObject({
46 label: "T3 Code Mobile",
47 browser: "Electron",
48 deviceType: "mobile",
49 ipAddress: "192.168.213.72",
50 os: "iOS",
51 });
52 expect(metadata.userAgent).toContain("Electron/36.3.2");
53 });
54});
55
56describe("session cookie isolation", () => {
57 it("isolates loopback web servers by port and server state", () => {
58 const first = resolveSessionCookieName({
59 mode: "web",
60 port: 5775,
61 host: "127.0.0.1",
62 instanceKey: "/tmp/t3-agent-one",
63 environmentId: "environment-one",
64 development: true,
65 });
66 const second = resolveSessionCookieName({
67 mode: "web",
68 port: 5775,
69 host: "127.0.0.1",
70 instanceKey: "/tmp/t3-agent-two",
71 environmentId: "environment-two",
72 development: true,
73 });
74
75 expect(first).toMatch(/^t3_session_5775_[a-f0-9]{12}$/);
76 expect(second).toMatch(/^t3_session_5775_[a-f0-9]{12}$/);
77 expect(first).not.toBe(second);
78 });
79
80 // regression: #8085 isolate remote web session cookies
81 it("isolates remote web servers by server state", () => {
82 const first = resolveSessionCookieName({
83 mode: "web",
84 port: 3773,
85 host: "192.168.1.50",
86 instanceKey: "/srv/t3-one",
87 environmentId: "environment-one",
88 development: false,
89 });
90 const second = resolveSessionCookieName({
91 mode: "web",
92 port: 5775,
93 host: "192.168.1.50",
94 instanceKey: "/srv/t3-two",
95 environmentId: "environment-two",
96 development: false,
97 });
98
99 expect(first).toMatch(/^t3_session_[a-f0-9]{12}$/);
100 expect(second).toMatch(/^t3_session_[a-f0-9]{12}$/);
101 expect(first).not.toBe(second);
102 });
103
104 it("keeps a remote web server cookie stable across port changes", () => {
105 const first = resolveSessionCookieName({
106 mode: "web",
107 port: 8080,
108 host: "0.0.0.0",
109 instanceKey: "/srv/t3",
110 environmentId: "environment-one",
111 development: false,
112 });
113 const second = resolveSessionCookieName({
114 mode: "web",
115 port: 9090,
116 host: "app.example.com",
117 instanceKey: "/srv/t3",
118 environmentId: "environment-one",
119 development: false,
120 });
121
122 expect(first).toBe(second);
123 });
124});