Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2import { EnvironmentId } from "@t3tools/contracts";
3
4import {
5 isRelayManagedConnection,
6 authClientMetadata,
7 redactPairingCredential,
8 toStableSavedRemoteConnection,
9} from "./connection";
10
11vi.mock("./runtime", () => ({
12 runtime: {
13 runPromise: vi.fn(),
14 },
15}));
16
17vi.mock("react-native", () => ({
18 Platform: {
19 OS: "ios",
20 },
21}));
22
23describe("mobile remote connection records", () => {
24 it("identifies mobile token exchanges for authorized-client presentation", () => {
25 expect(authClientMetadata()).toEqual({
26 label: "T3 Code Mobile",
27 deviceType: "mobile",
28 os: "iOS",
29 });
30 });
31
32 it("removes one-time bootstrap credentials before persisting pairing URLs", () => {
33 expect(redactPairingCredential("https://desktop.example/#token=bootstrap-token")).toBe(
34 "https://desktop.example/",
35 );
36 expect(redactPairingCredential("https://desktop.example/?token=bootstrap-token")).toBe(
37 "https://desktop.example/",
38 );
39 });
40
41 it("removes hosted pairing credentials while keeping the advertised host", () => {
42 expect(
43 redactPairingCredential(
44 "https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.example&token=bootstrap-token&label=Desktop",
45 ),
46 ).toBe("https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.example&label=Desktop");
47 });
48
49 it("recognizes explicitly managed relay connections", () => {
50 expect(isRelayManagedConnection({ relayManaged: true })).toBe(true);
51 });
52
53 it("keeps existing DPoP tunnel records read-only after upgrading", () => {
54 expect(isRelayManagedConnection({ authenticationMethod: "dpop" })).toBe(true);
55 expect(isRelayManagedConnection({ authenticationMethod: "bearer" })).toBe(false);
56 });
57
58 it("drops short-lived managed environment credentials from stable records", () => {
59 const connection = {
60 environmentId: EnvironmentId.make("environment-1"),
61 environmentLabel: "Desktop",
62 pairingUrl: "https://desktop.example/",
63 displayUrl: "https://desktop.example/",
64 httpBaseUrl: "https://desktop.example/",
65 wsBaseUrl: "wss://desktop.example/",
66 bearerToken: null,
67 authenticationMethod: "dpop",
68 dpopAccessToken: "short-lived-token",
69 relayManaged: true,
70 } as const;
71
72 expect(toStableSavedRemoteConnection(connection)).not.toHaveProperty("dpopAccessToken");
73 });
74});