Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 normalizeLinuxPasswordStorePreference,
5 resolveLinuxPasswordStoreSwitch,
6 resolveLinuxSecretStorageUnavailableMessage,
7} from "./linuxSecretStorage.ts";
8
9const autoSwitch = (env: NodeJS.ProcessEnv) =>
10 resolveLinuxPasswordStoreSwitch({ preference: "auto", env });
11
12describe("linuxSecretStorage", () => {
13 it("preserves explicit supported password-store preferences", () => {
14 expect(normalizeLinuxPasswordStorePreference("gnome-libsecret")).toBe("gnome-libsecret");
15 expect(normalizeLinuxPasswordStorePreference("kwallet")).toBe("kwallet");
16 expect(normalizeLinuxPasswordStorePreference("kwallet5")).toBe("kwallet5");
17 expect(normalizeLinuxPasswordStorePreference("kwallet6")).toBe("kwallet6");
18 });
19
20 it("falls back to auto for missing or unsupported preferences", () => {
21 expect(normalizeLinuxPasswordStorePreference(undefined)).toBe("auto");
22 expect(normalizeLinuxPasswordStorePreference("basic")).toBe("auto");
23 });
24
25 it("uses explicit preferences instead of the auto heuristic", () => {
26 for (const preference of ["gnome-libsecret", "kwallet", "kwallet5", "kwallet6"] as const) {
27 expect(
28 resolveLinuxPasswordStoreSwitch({ preference, env: { XDG_CURRENT_DESKTOP: "niri" } }),
29 ).toBe(preference);
30 // An explicit preference also wins where auto would have stayed out of the way.
31 expect(
32 resolveLinuxPasswordStoreSwitch({ preference, env: { XDG_CURRENT_DESKTOP: "KDE" } }),
33 ).toBe(preference);
34 }
35 });
36
37 it("leaves canonical KDE sessions to Electron's own wallet selection", () => {
38 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "KDE" })).toBeNull();
39 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "KDE", KDE_SESSION_VERSION: "6" })).toBeNull();
40 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "KDE", KDE_SESSION_VERSION: "5" })).toBeNull();
41 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "KDE:plasma" })).toBeNull();
42 });
43
44 it("does not force a password-store for desktops Electron already recognizes", () => {
45 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "GNOME" })).toBeNull();
46 for (const desktop of ["Deepin", "Pantheon", "UKUI", "Unity", "X-Cinnamon", "XFCE"]) {
47 expect(autoSwitch({ XDG_CURRENT_DESKTOP: desktop })).toBeNull();
48 }
49 });
50
51 it("recognizes a known desktop later in a colon-separated XDG_CURRENT_DESKTOP list", () => {
52 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "niri:GNOME" })).toBeNull();
53 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "ubuntu:GNOME" })).toBeNull();
54 });
55
56 it("forces gnome-libsecret for unrecognized Linux desktop sessions", () => {
57 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "niri" })).toBe("gnome-libsecret");
58 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "Hyprland" })).toBe("gnome-libsecret");
59 expect(autoSwitch({})).toBe("gnome-libsecret");
60 });
61
62 it("forces gnome-libsecret for desktops Electron recognizes but leaves on basic text", () => {
63 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "LXQt" })).toBe("gnome-libsecret");
64 // Chromium stops at the first recognized value, so a later name cannot rescue the session.
65 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "LXQt:GNOME" })).toBe("gnome-libsecret");
66 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "LXQt:KDE" })).toBe("gnome-libsecret");
67 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "LXQt:plasma" })).toBe("gnome-libsecret");
68 });
69
70 it("does not treat lowercase desktop names as ones Electron recognizes", () => {
71 // Chromium matches these case-sensitively, so lowercase spellings reach basic text.
72 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "gnome" })).toBe("gnome-libsecret");
73 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "xfce" })).toBe("gnome-libsecret");
74 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "kde", KDE_SESSION_VERSION: "6" })).toBe(
75 "gnome-libsecret",
76 );
77 });
78
79 it("overrides KDE sessions identified only by legacy variables", () => {
80 // Chromium reaches KWallet4 for some of these, such as DESKTOP_SESSION=kde with a version, and
81 // basic text for the rest. Either way these are the variables a previous session leaves behind,
82 // so they are treated as unproven and forced to a real keyring rather than a guessed wallet.
83 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "plasma" })).toBe("gnome-libsecret");
84 for (const session of [
85 "kde",
86 "kde-plasma",
87 "kde4",
88 "plasma",
89 "plasmawayland",
90 "plasmawayland-dev",
91 "plasmax11",
92 "plasmax11-dev",
93 ]) {
94 expect(autoSwitch({ DESKTOP_SESSION: session })).toBe("gnome-libsecret");
95 expect(autoSwitch({ XDG_SESSION_DESKTOP: session })).toBe("gnome-libsecret");
96 expect(autoSwitch({ GDMSESSION: session })).toBe("gnome-libsecret");
97 }
98 expect(autoSwitch({ DESKTOP_SESSION: "kde", KDE_SESSION_VERSION: "6" })).toBe(
99 "gnome-libsecret",
100 );
101 expect(autoSwitch({ KDE_SESSION_VERSION: "6" })).toBe("gnome-libsecret");
102 expect(autoSwitch({ KDE_FULL_SESSION: "true", KDE_SESSION_VERSION: "6" })).toBe(
103 "gnome-libsecret",
104 );
105 });
106
107 it("ignores stale session hints when XDG_CURRENT_DESKTOP is authoritative", () => {
108 expect(
109 autoSwitch({ XDG_CURRENT_DESKTOP: "niri", DESKTOP_SESSION: "gnome", GDMSESSION: "gnome" }),
110 ).toBe("gnome-libsecret");
111 // A previous KDE session left these behind; the compositor running now is not KDE.
112 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "niri", KDE_SESSION_VERSION: "6" })).toBe(
113 "gnome-libsecret",
114 );
115 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "niri", XDG_SESSION_DESKTOP: "GNOME" })).toBe(
116 "gnome-libsecret",
117 );
118 expect(autoSwitch({ XDG_CURRENT_DESKTOP: "niri:plasma" })).toBe("gnome-libsecret");
119 expect(
120 autoSwitch({
121 XDG_CURRENT_DESKTOP: "Hyprland",
122 XDG_SESSION_DESKTOP: "KDE",
123 KDE_SESSION_VERSION: "6",
124 }),
125 ).toBe("gnome-libsecret");
126 });
127
128 it("uses GNOME Keyring remediation for libsecret and unknown backends", () => {
129 expect(
130 resolveLinuxSecretStorageUnavailableMessage({
131 configuredPreference: "auto",
132 selectedBackend: "gnome_libsecret",
133 env: { XDG_CURRENT_DESKTOP: "niri" },
134 }),
135 ).toContain("GNOME Keyring");
136 });
137
138 it("prefers explicit libsecret selection over KDE desktop heuristics", () => {
139 expect(
140 resolveLinuxSecretStorageUnavailableMessage({
141 configuredPreference: "gnome-libsecret",
142 selectedBackend: "unknown",
143 env: { XDG_CURRENT_DESKTOP: "KDE" },
144 }),
145 ).toContain("GNOME Keyring");
146 expect(
147 resolveLinuxSecretStorageUnavailableMessage({
148 configuredPreference: "auto",
149 selectedBackend: "gnome_libsecret",
150 env: { XDG_CURRENT_DESKTOP: "KDE" },
151 }),
152 ).toContain("GNOME Keyring");
153 });
154
155 it("prefers explicit KWallet preference over selected gnome-libsecret backend", () => {
156 expect(
157 resolveLinuxSecretStorageUnavailableMessage({
158 configuredPreference: "kwallet6",
159 selectedBackend: "gnome_libsecret",
160 env: { XDG_CURRENT_DESKTOP: "niri" },
161 }),
162 ).toContain("KWallet");
163 expect(
164 resolveLinuxSecretStorageUnavailableMessage({
165 configuredPreference: "kwallet",
166 selectedBackend: "gnome-libsecret",
167 env: {},
168 }),
169 ).toContain("KWallet");
170 });
171
172 it("uses KWallet remediation wording for KDE-looking sessions", () => {
173 expect(
174 resolveLinuxSecretStorageUnavailableMessage({
175 configuredPreference: "auto",
176 selectedBackend: "kwallet6",
177 env: {},
178 }),
179 ).toContain("KWallet");
180 expect(
181 resolveLinuxSecretStorageUnavailableMessage({
182 configuredPreference: "auto",
183 selectedBackend: "unknown",
184 env: { XDG_CURRENT_DESKTOP: "KDE" },
185 }),
186 ).toContain("KWallet");
187 expect(
188 resolveLinuxSecretStorageUnavailableMessage({
189 configuredPreference: "auto",
190 selectedBackend: "unknown",
191 env: { DESKTOP_SESSION: "plasmawayland" },
192 }),
193 ).toContain("KWallet");
194 // A desktop name outranks a bare KDE marker when choosing the wording.
195 expect(
196 resolveLinuxSecretStorageUnavailableMessage({
197 configuredPreference: "auto",
198 selectedBackend: "unknown",
199 env: { GDMSESSION: "gnome", KDE_FULL_SESSION: "true" },
200 }),
201 ).toContain("GNOME Keyring");
202 });
203});