Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

cliAuthFormat.test.ts

88 lines2.6 KB

1import { expect, it } from "@effect/vitest";
2import { DateTime } from "effect";
3​
4import {
5 formatIssuedPairingCredential,
6 formatIssuedSession,
7 formatPairingCredentialList,
8 formatSessionList,
9} from "./cliAuthFormat.ts";
10​
11it("formats issued pairing credentials with the secret and optional pair URL", () => {
12 const output = formatIssuedPairingCredential(
13 {
14 id: "pairing-1",
15 credential: "secret-pairing-token",
16 role: "client",
17 subject: "one-time-token",
18 createdAt: DateTime.fromDateUnsafe(new Date("2026-04-08T09:00:00.000Z")),
19 expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
20 },
21 { baseUrl: "https://example.com", json: false },
22 );
23​
24 expect(output).toContain("secret-pairing-token");
25 expect(output).toContain("https://example.com/pair#token=secret-pairing-token");
26});
27​
28it("formats pairing listings without exposing the secret token", () => {
29 const output = formatPairingCredentialList(
30 [
31 {
32 id: "pairing-1",
33 credential: "secret-pairing-token",
34 subject: "one-time-token",
35 label: "Phone",
36 role: "client",
37 createdAt: DateTime.fromDateUnsafe(new Date("2026-04-08T09:00:00.000Z")),
38 expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
39 },
40 ],
41 { json: false },
42 );
43​
44 expect(output).toContain("pairing-1");
45 expect(output).not.toContain("secret-pairing-token");
46});
47​
48it("formats issued sessions with the bearer token but omits tokens from listings", () => {
49 const issuedOutput = formatIssuedSession(
50 {
51 sessionId: "session-1" as never,
52 token: "secret-session-token",
53 method: "bearer-session-token",
54 role: "owner",
55 subject: "cli-issued-session",
56 client: {
57 label: "deploy-bot",
58 deviceType: "bot",
59 },
60 expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
61 },
62 { json: false },
63 );
64​
65 const listedOutput = formatSessionList(
66 [
67 {
68 sessionId: "session-1" as never,
69 method: "bearer-session-token",
70 role: "owner",
71 subject: "cli-issued-session",
72 client: {
73 label: "deploy-bot",
74 deviceType: "bot",
75 },
76 connected: false,
77 current: false,
78 issuedAt: DateTime.fromDateUnsafe(new Date("2026-04-08T09:00:00.000Z")),
79 expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
80 lastConnectedAt: null,
81 },
82 ],
83 { json: false },
84 );
85​
86 expect(issuedOutput).toContain("secret-session-token");
87 expect(listedOutput).not.toContain("secret-session-token");
88});