opengstack 0.13.7 → 0.13.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/bin/opengstack.js +35 -90
  2. package/package.json +2 -3
  3. package/scripts/install-skills.js +29 -58
  4. package/skills/browse/bin/find-browse +21 -0
  5. package/skills/browse/bin/remote-slug +14 -0
  6. package/skills/browse/scripts/build-node-server.sh +48 -0
  7. package/skills/browse/src/activity.ts +208 -0
  8. package/skills/browse/src/browser-manager.ts +959 -0
  9. package/skills/browse/src/buffers.ts +137 -0
  10. package/skills/browse/src/bun-polyfill.cjs +109 -0
  11. package/skills/browse/src/cli.ts +678 -0
  12. package/skills/browse/src/commands.ts +128 -0
  13. package/skills/browse/src/config.ts +150 -0
  14. package/skills/browse/src/cookie-import-browser.ts +625 -0
  15. package/skills/browse/src/cookie-picker-routes.ts +230 -0
  16. package/skills/browse/src/cookie-picker-ui.ts +688 -0
  17. package/skills/browse/src/find-browse.ts +61 -0
  18. package/skills/browse/src/meta-commands.ts +550 -0
  19. package/skills/browse/src/platform.ts +17 -0
  20. package/skills/browse/src/read-commands.ts +358 -0
  21. package/skills/browse/src/server.ts +1192 -0
  22. package/skills/browse/src/sidebar-agent.ts +280 -0
  23. package/skills/browse/src/sidebar-utils.ts +21 -0
  24. package/skills/browse/src/snapshot.ts +407 -0
  25. package/skills/browse/src/url-validation.ts +95 -0
  26. package/skills/browse/src/write-commands.ts +364 -0
  27. package/skills/browse/test/activity.test.ts +120 -0
  28. package/skills/browse/test/adversarial-security.test.ts +32 -0
  29. package/skills/browse/test/browser-manager-unit.test.ts +17 -0
  30. package/skills/browse/test/bun-polyfill.test.ts +72 -0
  31. package/skills/browse/test/commands.test.ts +2075 -0
  32. package/skills/browse/test/compare-board.test.ts +342 -0
  33. package/skills/browse/test/config.test.ts +316 -0
  34. package/skills/browse/test/cookie-import-browser.test.ts +519 -0
  35. package/skills/browse/test/cookie-picker-routes.test.ts +260 -0
  36. package/skills/browse/test/file-drop.test.ts +271 -0
  37. package/skills/browse/test/find-browse.test.ts +50 -0
  38. package/skills/browse/test/findport.test.ts +191 -0
  39. package/skills/browse/test/fixtures/basic.html +33 -0
  40. package/skills/browse/test/fixtures/cursor-interactive.html +22 -0
  41. package/skills/browse/test/fixtures/dialog.html +15 -0
  42. package/skills/browse/test/fixtures/empty.html +2 -0
  43. package/skills/browse/test/fixtures/forms.html +55 -0
  44. package/skills/browse/test/fixtures/iframe.html +30 -0
  45. package/skills/browse/test/fixtures/network-idle.html +30 -0
  46. package/skills/browse/test/fixtures/qa-eval-checkout.html +108 -0
  47. package/skills/browse/test/fixtures/qa-eval-spa.html +98 -0
  48. package/skills/browse/test/fixtures/qa-eval.html +51 -0
  49. package/skills/browse/test/fixtures/responsive.html +49 -0
  50. package/skills/browse/test/fixtures/snapshot.html +55 -0
  51. package/skills/browse/test/fixtures/spa.html +24 -0
  52. package/skills/browse/test/fixtures/states.html +17 -0
  53. package/skills/browse/test/fixtures/upload.html +25 -0
  54. package/skills/browse/test/gstack-config.test.ts +138 -0
  55. package/skills/browse/test/gstack-update-check.test.ts +514 -0
  56. package/skills/browse/test/handoff.test.ts +235 -0
  57. package/skills/browse/test/path-validation.test.ts +91 -0
  58. package/skills/browse/test/platform.test.ts +37 -0
  59. package/skills/browse/test/server-auth.test.ts +65 -0
  60. package/skills/browse/test/sidebar-agent-roundtrip.test.ts +226 -0
  61. package/skills/browse/test/sidebar-agent.test.ts +199 -0
  62. package/skills/browse/test/sidebar-integration.test.ts +320 -0
  63. package/skills/browse/test/sidebar-unit.test.ts +96 -0
  64. package/skills/browse/test/snapshot.test.ts +467 -0
  65. package/skills/browse/test/state-ttl.test.ts +35 -0
  66. package/skills/browse/test/test-server.ts +57 -0
  67. package/skills/browse/test/url-validation.test.ts +72 -0
  68. package/skills/browse/test/watch.test.ts +129 -0
  69. package/skills/careful/bin/check-careful.sh +112 -0
  70. package/skills/cso/ACKNOWLEDGEMENTS.md +14 -0
  71. package/skills/freeze/bin/check-freeze.sh +79 -0
  72. package/skills/qa/references/issue-taxonomy.md +85 -0
  73. package/skills/qa/templates/qa-report-template.md +126 -0
  74. package/skills/review/TODOS-format.md +62 -0
  75. package/skills/review/checklist.md +220 -0
  76. package/skills/review/design-checklist.md +132 -0
  77. package/skills/review/greptile-triage.md +220 -0
  78. /package/{autoplan → skills/autoplan}/SKILL.md +0 -0
  79. /package/{autoplan → skills/autoplan}/SKILL.md.tmpl +0 -0
  80. /package/{benchmark → skills/benchmark}/SKILL.md +0 -0
  81. /package/{benchmark → skills/benchmark}/SKILL.md.tmpl +0 -0
  82. /package/{browse → skills/browse}/SKILL.md +0 -0
  83. /package/{browse → skills/browse}/SKILL.md.tmpl +0 -0
  84. /package/{canary → skills/canary}/SKILL.md +0 -0
  85. /package/{canary → skills/canary}/SKILL.md.tmpl +0 -0
  86. /package/{careful → skills/careful}/SKILL.md +0 -0
  87. /package/{careful → skills/careful}/SKILL.md.tmpl +0 -0
  88. /package/{codex → skills/codex}/SKILL.md +0 -0
  89. /package/{codex → skills/codex}/SKILL.md.tmpl +0 -0
  90. /package/{connect-chrome → skills/connect-chrome}/SKILL.md +0 -0
  91. /package/{connect-chrome → skills/connect-chrome}/SKILL.md.tmpl +0 -0
  92. /package/{cso → skills/cso}/SKILL.md +0 -0
  93. /package/{cso → skills/cso}/SKILL.md.tmpl +0 -0
  94. /package/{design-consultation → skills/design-consultation}/SKILL.md +0 -0
  95. /package/{design-consultation → skills/design-consultation}/SKILL.md.tmpl +0 -0
  96. /package/{design-review → skills/design-review}/SKILL.md +0 -0
  97. /package/{design-review → skills/design-review}/SKILL.md.tmpl +0 -0
  98. /package/{design-shotgun → skills/design-shotgun}/SKILL.md +0 -0
  99. /package/{design-shotgun → skills/design-shotgun}/SKILL.md.tmpl +0 -0
  100. /package/{document-release → skills/document-release}/SKILL.md +0 -0
  101. /package/{document-release → skills/document-release}/SKILL.md.tmpl +0 -0
  102. /package/{freeze → skills/freeze}/SKILL.md +0 -0
  103. /package/{freeze → skills/freeze}/SKILL.md.tmpl +0 -0
  104. /package/{gstack-upgrade → skills/gstack-upgrade}/SKILL.md +0 -0
  105. /package/{gstack-upgrade → skills/gstack-upgrade}/SKILL.md.tmpl +0 -0
  106. /package/{guard → skills/guard}/SKILL.md +0 -0
  107. /package/{guard → skills/guard}/SKILL.md.tmpl +0 -0
  108. /package/{investigate → skills/investigate}/SKILL.md +0 -0
  109. /package/{investigate → skills/investigate}/SKILL.md.tmpl +0 -0
  110. /package/{land-and-deploy → skills/land-and-deploy}/SKILL.md +0 -0
  111. /package/{land-and-deploy → skills/land-and-deploy}/SKILL.md.tmpl +0 -0
  112. /package/{office-hours → skills/office-hours}/SKILL.md +0 -0
  113. /package/{office-hours → skills/office-hours}/SKILL.md.tmpl +0 -0
  114. /package/{plan-ceo-review → skills/plan-ceo-review}/SKILL.md +0 -0
  115. /package/{plan-ceo-review → skills/plan-ceo-review}/SKILL.md.tmpl +0 -0
  116. /package/{plan-design-review → skills/plan-design-review}/SKILL.md +0 -0
  117. /package/{plan-design-review → skills/plan-design-review}/SKILL.md.tmpl +0 -0
  118. /package/{plan-eng-review → skills/plan-eng-review}/SKILL.md +0 -0
  119. /package/{plan-eng-review → skills/plan-eng-review}/SKILL.md.tmpl +0 -0
  120. /package/{qa → skills/qa}/SKILL.md +0 -0
  121. /package/{qa → skills/qa}/SKILL.md.tmpl +0 -0
  122. /package/{qa-only → skills/qa-only}/SKILL.md +0 -0
  123. /package/{qa-only → skills/qa-only}/SKILL.md.tmpl +0 -0
  124. /package/{retro → skills/retro}/SKILL.md +0 -0
  125. /package/{retro → skills/retro}/SKILL.md.tmpl +0 -0
  126. /package/{review → skills/review}/SKILL.md +0 -0
  127. /package/{review → skills/review}/SKILL.md.tmpl +0 -0
  128. /package/{setup-browser-cookies → skills/setup-browser-cookies}/SKILL.md +0 -0
  129. /package/{setup-browser-cookies → skills/setup-browser-cookies}/SKILL.md.tmpl +0 -0
  130. /package/{setup-deploy → skills/setup-deploy}/SKILL.md +0 -0
  131. /package/{setup-deploy → skills/setup-deploy}/SKILL.md.tmpl +0 -0
  132. /package/{ship → skills/ship}/SKILL.md +0 -0
  133. /package/{ship → skills/ship}/SKILL.md.tmpl +0 -0
  134. /package/{unfreeze → skills/unfreeze}/SKILL.md +0 -0
  135. /package/{unfreeze → skills/unfreeze}/SKILL.md.tmpl +0 -0
@@ -0,0 +1,519 @@
1
+ /**
2
+ * Unit tests for cookie-import-browser.ts
3
+ *
4
+ * Uses a fixture SQLite database with cookies encrypted using a known test key.
5
+ * Mocks Keychain access to return the test password.
6
+ *
7
+ * Test key derivation (matches real Chromium pipeline):
8
+ * password = "test-keychain-password"
9
+ * key = PBKDF2(password, "saltysalt", 1003, 16, sha1)
10
+ *
11
+ * Encryption: AES-128-CBC with IV = 16 × 0x20, prefix "v10"
12
+ * First 32 bytes of plaintext = HMAC-SHA256 tag (random for tests)
13
+ * Remaining bytes = actual cookie value
14
+ */
15
+
16
+ import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
17
+ import { Database } from 'bun:sqlite';
18
+ import * as crypto from 'crypto';
19
+ import * as fs from 'fs';
20
+ import * as path from 'path';
21
+ import * as os from 'os';
22
+
23
+ // ─── Test Constants ─────────────────────────────────────────────
24
+
25
+ const TEST_PASSWORD = 'test-keychain-password';
26
+ const TEST_KEY = crypto.pbkdf2Sync(TEST_PASSWORD, 'saltysalt', 1003, 16, 'sha1');
27
+ const LINUX_V10_PASSWORD = 'peanuts';
28
+ const LINUX_V10_KEY = crypto.pbkdf2Sync(LINUX_V10_PASSWORD, 'saltysalt', 1, 16, 'sha1');
29
+ const LINUX_V11_PASSWORD = 'test-linux-secret';
30
+ const LINUX_V11_KEY = crypto.pbkdf2Sync(LINUX_V11_PASSWORD, 'saltysalt', 1, 16, 'sha1');
31
+ const IV = Buffer.alloc(16, 0x20);
32
+ const CHROMIUM_EPOCH_OFFSET = 11644473600000000n;
33
+
34
+ // Fixture DB path
35
+ const FIXTURE_DIR = path.join(import.meta.dir, 'fixtures');
36
+ const FIXTURE_DB = path.join(FIXTURE_DIR, 'test-cookies.db');
37
+ const LINUX_FIXTURE_DB = path.join(FIXTURE_DIR, 'test-cookies-linux.db');
38
+
39
+ // ─── Encryption Helper ──────────────────────────────────────────
40
+
41
+ function encryptCookieValue(
42
+ value: string,
43
+ options?: { key?: Buffer; prefix?: 'v10' | 'v11' },
44
+ ): Buffer {
45
+ const key = options?.key ?? TEST_KEY;
46
+ const prefix = options?.prefix ?? 'v10';
47
+ // 32-byte HMAC tag (random for test) + actual value
48
+ const hmacTag = crypto.randomBytes(32);
49
+ const plaintext = Buffer.concat([hmacTag, Buffer.from(value, 'utf-8')]);
50
+
51
+ // PKCS7 pad to AES block size (16 bytes)
52
+ const blockSize = 16;
53
+ const padLen = blockSize - (plaintext.length % blockSize);
54
+ const padded = Buffer.concat([plaintext, Buffer.alloc(padLen, padLen)]);
55
+
56
+ const cipher = crypto.createCipheriv('aes-128-cbc', key, IV);
57
+ cipher.setAutoPadding(false); // We padded manually
58
+ const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
59
+
60
+ return Buffer.concat([Buffer.from(prefix), encrypted]);
61
+ }
62
+
63
+ function chromiumEpoch(unixSeconds: number): bigint {
64
+ return BigInt(unixSeconds) * 1000000n + CHROMIUM_EPOCH_OFFSET;
65
+ }
66
+
67
+ // ─── Create Fixture Database ────────────────────────────────────
68
+
69
+ function createFixtureDb(dbPath: string): Database {
70
+ fs.mkdirSync(FIXTURE_DIR, { recursive: true });
71
+ if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath);
72
+
73
+ const db = new Database(dbPath);
74
+ db.run(`CREATE TABLE cookies (
75
+ host_key TEXT NOT NULL,
76
+ name TEXT NOT NULL,
77
+ value TEXT NOT NULL DEFAULT '',
78
+ encrypted_value BLOB NOT NULL DEFAULT x'',
79
+ path TEXT NOT NULL DEFAULT '/',
80
+ expires_utc INTEGER NOT NULL DEFAULT 0,
81
+ is_secure INTEGER NOT NULL DEFAULT 0,
82
+ is_httponly INTEGER NOT NULL DEFAULT 0,
83
+ has_expires INTEGER NOT NULL DEFAULT 0,
84
+ samesite INTEGER NOT NULL DEFAULT 1
85
+ )`);
86
+ return db;
87
+ }
88
+
89
+ function createMacFixtureDb() {
90
+ const db = createFixtureDb(FIXTURE_DB);
91
+ const insert = db.prepare(`INSERT INTO cookies
92
+ (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, has_expires, samesite)
93
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
94
+
95
+ const futureExpiry = Number(chromiumEpoch(Math.floor(Date.now() / 1000) + 86400 * 365));
96
+ const pastExpiry = Number(chromiumEpoch(Math.floor(Date.now() / 1000) - 86400));
97
+
98
+ // Domain 1: .github.com — 3 encrypted cookies
99
+ insert.run('.github.com', 'session_id', '', encryptCookieValue('abc123'), '/', futureExpiry, 1, 1, 1, 1);
100
+ insert.run('.github.com', 'user_token', '', encryptCookieValue('token-xyz'), '/', futureExpiry, 1, 0, 1, 0);
101
+ insert.run('.github.com', 'theme', '', encryptCookieValue('dark'), '/', futureExpiry, 0, 0, 1, 2);
102
+
103
+ // Domain 2: .google.com — 2 cookies
104
+ insert.run('.google.com', 'NID', '', encryptCookieValue('google-nid-value'), '/', futureExpiry, 1, 1, 1, 0);
105
+ insert.run('.google.com', 'SID', '', encryptCookieValue('google-sid-value'), '/', futureExpiry, 1, 1, 1, 1);
106
+
107
+ // Domain 3: .example.com — 1 unencrypted cookie (value field set, no encrypted_value)
108
+ insert.run('.example.com', 'plain_cookie', 'hello-world', Buffer.alloc(0), '/', futureExpiry, 0, 0, 1, 1);
109
+
110
+ // Domain 4: .expired.com — 1 expired cookie (should be filtered out)
111
+ insert.run('.expired.com', 'old', '', encryptCookieValue('expired-value'), '/', pastExpiry, 0, 0, 1, 1);
112
+
113
+ // Domain 5: .session.com — session cookie (has_expires=0)
114
+ insert.run('.session.com', 'sess', '', encryptCookieValue('session-value'), '/', 0, 1, 1, 0, 1);
115
+
116
+ // Domain 6: .corrupt.com — cookie with garbage encrypted_value
117
+ insert.run('.corrupt.com', 'bad', '', Buffer.from('v10' + 'not-valid-ciphertext-at-all'), '/', futureExpiry, 0, 0, 1, 1);
118
+
119
+ // Domain 7: .mixed.com — one good, one corrupt
120
+ insert.run('.mixed.com', 'good', '', encryptCookieValue('mixed-good'), '/', futureExpiry, 0, 0, 1, 1);
121
+ insert.run('.mixed.com', 'bad', '', Buffer.from('v10' + 'garbage-data-here!!!'), '/', futureExpiry, 0, 0, 1, 1);
122
+
123
+ db.close();
124
+ }
125
+
126
+ function createLinuxFixtureDb() {
127
+ const db = createFixtureDb(LINUX_FIXTURE_DB);
128
+ const insert = db.prepare(`INSERT INTO cookies
129
+ (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, has_expires, samesite)
130
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
131
+
132
+ const futureExpiry = Number(chromiumEpoch(Math.floor(Date.now() / 1000) + 86400 * 365));
133
+
134
+ insert.run('.linux-v10.com', 'sid', '', encryptCookieValue('linux-v10-value', { key: LINUX_V10_KEY, prefix: 'v10' }), '/', futureExpiry, 1, 1, 1, 1);
135
+ insert.run('.linux-v11.com', 'auth', '', encryptCookieValue('linux-v11-value', { key: LINUX_V11_KEY, prefix: 'v11' }), '/', futureExpiry, 1, 1, 1, 1);
136
+ insert.run('.linux-plain.com', 'plain', 'plain-linux', Buffer.alloc(0), '/', futureExpiry, 0, 0, 1, 1);
137
+
138
+ db.close();
139
+ }
140
+
141
+ // ─── Mock Setup ─────────────────────────────────────────────────
142
+ // We need to mock:
143
+ // 1. The Keychain access (getKeychainPassword) to return TEST_PASSWORD
144
+ // 2. The cookie DB path resolution to use our fixture DB
145
+
146
+ // We'll import the module after setting up the mocks
147
+ let findInstalledBrowsers: any;
148
+ let listDomains: any;
149
+ let importCookies: any;
150
+ let CookieImportError: any;
151
+ let originalSpawn: typeof Bun.spawn;
152
+
153
+ beforeAll(async () => {
154
+ createMacFixtureDb();
155
+ createLinuxFixtureDb();
156
+
157
+ // Mock Bun.spawn to return test password for keychain access
158
+ originalSpawn = Bun.spawn;
159
+ // @ts-ignore - monkey-patching for test
160
+ Bun.spawn = function(cmd: any, opts: any) {
161
+ // Intercept security find-generic-password calls
162
+ if (Array.isArray(cmd) && cmd[0] === 'security' && cmd[1] === 'find-generic-password') {
163
+ // Return test password for any known test service
164
+ return {
165
+ stdout: new ReadableStream({
166
+ start(controller) {
167
+ controller.enqueue(new TextEncoder().encode(TEST_PASSWORD + '\n'));
168
+ controller.close();
169
+ }
170
+ }),
171
+ stderr: new ReadableStream({
172
+ start(controller) { controller.close(); }
173
+ }),
174
+ exited: Promise.resolve(0),
175
+ kill: () => {},
176
+ };
177
+ }
178
+ if (Array.isArray(cmd) && cmd[0] === 'secret-tool' && cmd[1] === 'lookup') {
179
+ return {
180
+ stdout: new ReadableStream({
181
+ start(controller) {
182
+ controller.enqueue(new TextEncoder().encode(LINUX_V11_PASSWORD + '\n'));
183
+ controller.close();
184
+ }
185
+ }),
186
+ stderr: new ReadableStream({
187
+ start(controller) { controller.close(); }
188
+ }),
189
+ exited: Promise.resolve(0),
190
+ kill: () => {},
191
+ };
192
+ }
193
+ // Pass through other spawn calls
194
+ return originalSpawn(cmd, opts);
195
+ };
196
+
197
+ // Import the module (uses our mocked Bun.spawn)
198
+ const mod = await import('../src/cookie-import-browser');
199
+ findInstalledBrowsers = mod.findInstalledBrowsers;
200
+ listDomains = mod.listDomains;
201
+ importCookies = mod.importCookies;
202
+ CookieImportError = mod.CookieImportError;
203
+ });
204
+
205
+ afterAll(() => {
206
+ // Restore Bun.spawn
207
+ // @ts-ignore - monkey-patching for test
208
+ Bun.spawn = originalSpawn;
209
+ // Clean up fixture DB
210
+ try { fs.unlinkSync(FIXTURE_DB); } catch {}
211
+ try { fs.unlinkSync(LINUX_FIXTURE_DB); } catch {}
212
+ try { fs.rmdirSync(FIXTURE_DIR); } catch {}
213
+ });
214
+
215
+ // ─── Helper: Override DB path for tests ─────────────────────────
216
+ // The real code resolves paths via ~/Library/Application Support/<browser>/Default/Cookies
217
+ // We need to test against our fixture DB directly. We'll test the pure decryption functions
218
+ // by calling importCookies with a browser that points to our fixture.
219
+ // Since the module uses a hardcoded registry, we test the decryption logic via a different approach:
220
+ // We'll directly call the internal decryption by setting up the DB in the expected location.
221
+
222
+ // For the unit tests below, we test the decryption pipeline by:
223
+ // 1. Creating encrypted cookies with known values
224
+ // 2. Decrypting them with the module's decryption logic
225
+ // The actual DB path resolution is tested separately.
226
+
227
+ async function withInstalledProfile<T>(
228
+ relativeBrowserDir: string,
229
+ sourceDb: string,
230
+ run: () => Promise<T>,
231
+ profile = 'Default',
232
+ ): Promise<T> {
233
+ const homeDir = os.homedir();
234
+ const profileDir = path.join(homeDir, relativeBrowserDir, profile);
235
+ const cookiesPath = path.join(profileDir, 'Cookies');
236
+ const backupPath = path.join(profileDir, `Cookies.backup-${crypto.randomUUID()}`);
237
+ const hadOriginal = fs.existsSync(cookiesPath);
238
+
239
+ fs.mkdirSync(profileDir, { recursive: true });
240
+ if (hadOriginal) fs.copyFileSync(cookiesPath, backupPath);
241
+ fs.copyFileSync(sourceDb, cookiesPath);
242
+
243
+ try {
244
+ return await run();
245
+ } finally {
246
+ if (hadOriginal) {
247
+ fs.copyFileSync(backupPath, cookiesPath);
248
+ fs.unlinkSync(backupPath);
249
+ } else {
250
+ try { fs.unlinkSync(cookiesPath); } catch {}
251
+ try { fs.rmdirSync(profileDir); } catch {}
252
+ }
253
+ }
254
+ }
255
+
256
+ // ─── Tests ──────────────────────────────────────────────────────
257
+
258
+ describe('Cookie Import Browser', () => {
259
+
260
+ describe('Decryption Pipeline', () => {
261
+ test('encrypts and decrypts round-trip correctly', () => {
262
+ // Verify our test helper produces valid ciphertext
263
+ const encrypted = encryptCookieValue('hello-world');
264
+ expect(encrypted.slice(0, 3).toString()).toBe('v10');
265
+
266
+ // Decrypt manually to verify
267
+ const ciphertext = encrypted.slice(3);
268
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
269
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
270
+ // Skip 32-byte HMAC tag
271
+ const value = plaintext.slice(32).toString('utf-8');
272
+ expect(value).toBe('hello-world');
273
+ });
274
+
275
+ test('handles empty encrypted_value', () => {
276
+ const encrypted = encryptCookieValue('');
277
+ const ciphertext = encrypted.slice(3);
278
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
279
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
280
+ // 32-byte tag + empty value → slice(32) = empty
281
+ expect(plaintext.length).toBe(32); // just the HMAC tag, padded to block boundary? Actually 32 + 0 padded = 48
282
+ // With PKCS7 padding: 32 bytes + 16 bytes of padding = 48 bytes padded → decrypts to 32 bytes + padding removed = 32 bytes
283
+ });
284
+
285
+ test('handles special characters in cookie values', () => {
286
+ const specialValue = 'a=b&c=d; path=/; expires=Thu, 01 Jan 2099';
287
+ const encrypted = encryptCookieValue(specialValue);
288
+ const ciphertext = encrypted.slice(3);
289
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
290
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
291
+ expect(plaintext.slice(32).toString('utf-8')).toBe(specialValue);
292
+ });
293
+ });
294
+
295
+ describe('Fixture DB Structure', () => {
296
+ test('fixture DB has correct domain counts', () => {
297
+ const db = new Database(FIXTURE_DB, { readonly: true });
298
+ const rows = db.query(
299
+ `SELECT host_key, COUNT(*) as count FROM cookies GROUP BY host_key ORDER BY count DESC`
300
+ ).all() as any[];
301
+ db.close();
302
+
303
+ const counts = Object.fromEntries(rows.map((r: any) => [r.host_key, r.count]));
304
+ expect(counts['.github.com']).toBe(3);
305
+ expect(counts['.google.com']).toBe(2);
306
+ expect(counts['.example.com']).toBe(1);
307
+ expect(counts['.expired.com']).toBe(1);
308
+ expect(counts['.session.com']).toBe(1);
309
+ expect(counts['.corrupt.com']).toBe(1);
310
+ expect(counts['.mixed.com']).toBe(2);
311
+ });
312
+
313
+ test('encrypted cookies in fixture have v10 prefix', () => {
314
+ const db = new Database(FIXTURE_DB, { readonly: true });
315
+ const rows = db.query(
316
+ `SELECT name, encrypted_value FROM cookies WHERE host_key = '.github.com'`
317
+ ).all() as any[];
318
+ db.close();
319
+
320
+ for (const row of rows) {
321
+ const ev = Buffer.from(row.encrypted_value);
322
+ expect(ev.slice(0, 3).toString()).toBe('v10');
323
+ }
324
+ });
325
+
326
+ test('decrypts all github.com cookies from fixture DB', () => {
327
+ const db = new Database(FIXTURE_DB, { readonly: true });
328
+ const rows = db.query(
329
+ `SELECT name, value, encrypted_value FROM cookies WHERE host_key = '.github.com'`
330
+ ).all() as any[];
331
+ db.close();
332
+
333
+ const expected: Record<string, string> = {
334
+ 'session_id': 'abc123',
335
+ 'user_token': 'token-xyz',
336
+ 'theme': 'dark',
337
+ };
338
+
339
+ for (const row of rows) {
340
+ const ev = Buffer.from(row.encrypted_value);
341
+ if (ev.length === 0) continue;
342
+ const ciphertext = ev.slice(3);
343
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
344
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
345
+ const value = plaintext.slice(32).toString('utf-8');
346
+ expect(value).toBe(expected[row.name]);
347
+ }
348
+ });
349
+
350
+ test('unencrypted cookie uses value field directly', () => {
351
+ const db = new Database(FIXTURE_DB, { readonly: true });
352
+ const row = db.query(
353
+ `SELECT value, encrypted_value FROM cookies WHERE host_key = '.example.com'`
354
+ ).get() as any;
355
+ db.close();
356
+
357
+ expect(row.value).toBe('hello-world');
358
+ expect(Buffer.from(row.encrypted_value).length).toBe(0);
359
+ });
360
+ });
361
+
362
+ describe('sameSite Mapping', () => {
363
+ test('maps sameSite values correctly', () => {
364
+ // Read from fixture DB and verify mapping
365
+ const db = new Database(FIXTURE_DB, { readonly: true });
366
+
367
+ // samesite=0 → None
368
+ const none = db.query(`SELECT samesite FROM cookies WHERE name = 'user_token'`).get() as any;
369
+ expect(none.samesite).toBe(0);
370
+
371
+ // samesite=1 → Lax
372
+ const lax = db.query(`SELECT samesite FROM cookies WHERE name = 'session_id'`).get() as any;
373
+ expect(lax.samesite).toBe(1);
374
+
375
+ // samesite=2 → Strict
376
+ const strict = db.query(`SELECT samesite FROM cookies WHERE name = 'theme'`).get() as any;
377
+ expect(strict.samesite).toBe(2);
378
+
379
+ db.close();
380
+ });
381
+ });
382
+
383
+ describe('Chromium Epoch Conversion', () => {
384
+ test('converts Chromium epoch to Unix timestamp correctly', () => {
385
+ // Round-trip: pick a known Unix timestamp, convert to Chromium, convert back
386
+ const knownUnix = 1704067200; // 2024-01-01T00:00:00Z
387
+ const chromiumTs = BigInt(knownUnix) * 1000000n + CHROMIUM_EPOCH_OFFSET;
388
+ const unixTs = Number((chromiumTs - CHROMIUM_EPOCH_OFFSET) / 1000000n);
389
+ expect(unixTs).toBe(knownUnix);
390
+ });
391
+
392
+ test('session cookies (has_expires=0) get expires=-1', () => {
393
+ const db = new Database(FIXTURE_DB, { readonly: true });
394
+ const row = db.query(
395
+ `SELECT has_expires, expires_utc FROM cookies WHERE host_key = '.session.com'`
396
+ ).get() as any;
397
+ db.close();
398
+ expect(row.has_expires).toBe(0);
399
+ // When has_expires=0, the module should return expires=-1
400
+ });
401
+ });
402
+
403
+ describe('Error Handling', () => {
404
+ test('CookieImportError has correct properties', () => {
405
+ const err = new CookieImportError('test message', 'test_code', 'retry');
406
+ expect(err.message).toBe('test message');
407
+ expect(err.code).toBe('test_code');
408
+ expect(err.action).toBe('retry');
409
+ expect(err.name).toBe('CookieImportError');
410
+ expect(err instanceof Error).toBe(true);
411
+ });
412
+
413
+ test('CookieImportError without action', () => {
414
+ const err = new CookieImportError('no action', 'some_code');
415
+ expect(err.action).toBeUndefined();
416
+ });
417
+ });
418
+
419
+ describe('Browser Registry', () => {
420
+ test('findInstalledBrowsers returns array', () => {
421
+ const browsers = findInstalledBrowsers();
422
+ expect(Array.isArray(browsers)).toBe(true);
423
+ // Each entry should have the right shape
424
+ for (const b of browsers) {
425
+ expect(b).toHaveProperty('name');
426
+ expect(b).toHaveProperty('dataDir');
427
+ expect(b).toHaveProperty('keychainService');
428
+ expect(b).toHaveProperty('aliases');
429
+ }
430
+ });
431
+
432
+ test('detects linux-style Chromium profiles under ~/.config', async () => {
433
+ await withInstalledProfile('.config/chromium', LINUX_FIXTURE_DB, async () => {
434
+ const browsers = findInstalledBrowsers();
435
+ const names = browsers.map((browser: any) => browser.name);
436
+
437
+ expect(names).toContain('Chromium');
438
+ });
439
+ });
440
+ });
441
+
442
+ describe('Real Profile Imports', () => {
443
+ test('imports Linux v10 cookies from ~/.config/chromium', async () => {
444
+ await withInstalledProfile('.config/chromium', LINUX_FIXTURE_DB, async () => {
445
+ const result = await importCookies('chromium', ['.linux-v10.com'], 'GstackLinuxV10');
446
+
447
+ expect(result.count).toBe(1);
448
+ expect(result.failed).toBe(0);
449
+ expect(result.cookies[0].name).toBe('sid');
450
+ expect(result.cookies[0].value).toBe('linux-v10-value');
451
+ }, 'GstackLinuxV10');
452
+ });
453
+
454
+ test('imports Linux v11 cookies when secret-tool returns a key', async () => {
455
+ await withInstalledProfile('.config/chromium', LINUX_FIXTURE_DB, async () => {
456
+ const result = await importCookies('chromium', ['.linux-v11.com'], 'GstackLinuxV11');
457
+
458
+ expect(result.count).toBe(1);
459
+ expect(result.failed).toBe(0);
460
+ expect(result.cookies[0].name).toBe('auth');
461
+ expect(result.cookies[0].value).toBe('linux-v11-value');
462
+ }, 'GstackLinuxV11');
463
+ });
464
+
465
+ test('lists domains from Linux Chromium profiles', async () => {
466
+ await withInstalledProfile('.config/chromium', LINUX_FIXTURE_DB, async () => {
467
+ const result = listDomains('chromium', 'GstackLinuxDomains');
468
+ const domains = result.domains.map((entry: any) => entry.domain);
469
+
470
+ expect(result.browser).toBe('Chromium');
471
+ expect(domains).toContain('.linux-v10.com');
472
+ expect(domains).toContain('.linux-v11.com');
473
+ expect(domains).toContain('.linux-plain.com');
474
+ }, 'GstackLinuxDomains');
475
+ });
476
+ });
477
+
478
+ describe('Corrupt Data Handling', () => {
479
+ test('garbage ciphertext produces decryption error', () => {
480
+ const garbage = Buffer.from('v10' + 'this-is-not-valid-ciphertext!!');
481
+ const ciphertext = garbage.slice(3);
482
+ expect(() => {
483
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
484
+ Buffer.concat([decipher.update(ciphertext), decipher.final()]);
485
+ }).toThrow();
486
+ });
487
+ });
488
+
489
+ describe('Profile Validation', () => {
490
+ test('rejects path traversal in profile names', () => {
491
+ // The validateProfile function should reject profiles with / or ..
492
+ // We can't call it directly (internal), but we can test via listDomains
493
+ // which calls validateProfile
494
+ expect(() => listDomains('chrome', '../etc')).toThrow(/Invalid profile/);
495
+ expect(() => listDomains('chrome', 'Default/../../etc')).toThrow(/Invalid profile/);
496
+ });
497
+
498
+ test('rejects control characters in profile names', () => {
499
+ expect(() => listDomains('chrome', 'Default\x00evil')).toThrow(/Invalid profile/);
500
+ });
501
+ });
502
+
503
+ describe('Unknown Browser', () => {
504
+ test('throws for unknown browser name', () => {
505
+ expect(() => listDomains('firefox')).toThrow(/Unknown browser.*firefox/i);
506
+ });
507
+
508
+ test('error includes list of supported browsers', () => {
509
+ try {
510
+ listDomains('firefox');
511
+ throw new Error('Should have thrown');
512
+ } catch (err: any) {
513
+ expect(err.code).toBe('unknown_browser');
514
+ expect(err.message).toContain('comet');
515
+ expect(err.message).toContain('chrome');
516
+ }
517
+ });
518
+ });
519
+ });