opengstack 0.13.10 → 0.14.2
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.
- package/AGENTS.md +4 -4
- package/CLAUDE.md +127 -110
- package/README.md +10 -5
- package/SKILL.md +500 -70
- package/bin/opengstack.js +69 -69
- package/{skills/land-and-deploy/SKILL.md → commands/autoplan.md} +7 -25
- package/{skills/benchmark/SKILL.md → commands/benchmark.md} +84 -108
- package/{skills/browse/SKILL.md → commands/browse.md} +60 -81
- package/{skills/ship/SKILL.md → commands/canary.md} +7 -27
- package/{skills/careful/SKILL.md → commands/careful.md} +2 -22
- package/{skills/canary/SKILL.md → commands/codex.md} +7 -26
- package/{skills/connect-chrome/SKILL.md → commands/connect-chrome.md} +7 -24
- package/commands/cso.md +70 -0
- package/commands/design-consultation.md +70 -0
- package/commands/design-review.md +70 -0
- package/commands/design-shotgun.md +70 -0
- package/commands/document-release.md +70 -0
- package/{skills/freeze/SKILL.md → commands/freeze.md} +3 -29
- package/{skills/guard/SKILL.md → commands/guard.md} +4 -35
- package/commands/investigate.md +70 -0
- package/commands/land-and-deploy.md +70 -0
- package/commands/office-hours.md +70 -0
- package/{skills/gstack-upgrade/SKILL.md → commands/opengstack-upgrade.md} +64 -79
- package/commands/plan-ceo-review.md +70 -0
- package/commands/plan-design-review.md +70 -0
- package/commands/plan-eng-review.md +70 -0
- package/commands/qa-only.md +70 -0
- package/commands/qa.md +70 -0
- package/commands/retro.md +70 -0
- package/commands/review.md +70 -0
- package/{skills/setup-browser-cookies/SKILL.md → commands/setup-browser-cookies.md} +22 -40
- package/commands/setup-deploy.md +70 -0
- package/commands/ship.md +70 -0
- package/commands/unfreeze.md +25 -0
- package/docs/designs/CHROME_VS_CHROMIUM_EXPLORATION.md +9 -9
- package/docs/designs/CONDUCTOR_CHROME_SIDEBAR_INTEGRATION.md +2 -2
- package/docs/designs/CONDUCTOR_SESSION_API.md +16 -16
- package/docs/designs/DESIGN_SHOTGUN.md +74 -74
- package/docs/designs/DESIGN_TOOLS_V1.md +111 -111
- package/docs/skills.md +483 -202
- package/package.json +42 -43
- package/scripts/analytics.ts +188 -0
- package/scripts/dev-skill.ts +83 -0
- package/scripts/discover-skills.ts +39 -0
- package/scripts/eval-compare.ts +97 -0
- package/scripts/eval-list.ts +117 -0
- package/scripts/eval-select.ts +86 -0
- package/scripts/eval-summary.ts +188 -0
- package/scripts/eval-watch.ts +172 -0
- package/scripts/gen-skill-docs.ts +473 -0
- package/scripts/resolvers/browse.ts +129 -0
- package/scripts/resolvers/codex-helpers.ts +133 -0
- package/scripts/resolvers/composition.ts +48 -0
- package/scripts/resolvers/confidence.ts +37 -0
- package/scripts/resolvers/constants.ts +50 -0
- package/scripts/resolvers/design.ts +950 -0
- package/scripts/resolvers/index.ts +59 -0
- package/scripts/resolvers/learnings.ts +96 -0
- package/scripts/resolvers/preamble.ts +505 -0
- package/scripts/resolvers/review.ts +884 -0
- package/scripts/resolvers/testing.ts +573 -0
- package/scripts/resolvers/types.ts +45 -0
- package/scripts/resolvers/utility.ts +421 -0
- package/scripts/skill-check.ts +190 -0
- package/scripts/cleanup.py +0 -100
- package/scripts/filter-skills.sh +0 -114
- package/scripts/filter_skills.py +0 -164
- package/scripts/install-skills.js +0 -60
- package/skills/autoplan/SKILL.md +0 -96
- package/skills/autoplan/SKILL.md.tmpl +0 -694
- package/skills/benchmark/SKILL.md.tmpl +0 -222
- package/skills/browse/SKILL.md.tmpl +0 -131
- package/skills/browse/bin/find-browse +0 -21
- package/skills/browse/bin/remote-slug +0 -14
- package/skills/browse/scripts/build-node-server.sh +0 -48
- package/skills/browse/src/activity.ts +0 -208
- package/skills/browse/src/browser-manager.ts +0 -959
- package/skills/browse/src/buffers.ts +0 -137
- package/skills/browse/src/bun-polyfill.cjs +0 -109
- package/skills/browse/src/cli.ts +0 -678
- package/skills/browse/src/commands.ts +0 -128
- package/skills/browse/src/config.ts +0 -150
- package/skills/browse/src/cookie-import-browser.ts +0 -625
- package/skills/browse/src/cookie-picker-routes.ts +0 -230
- package/skills/browse/src/cookie-picker-ui.ts +0 -688
- package/skills/browse/src/find-browse.ts +0 -61
- package/skills/browse/src/meta-commands.ts +0 -550
- package/skills/browse/src/platform.ts +0 -17
- package/skills/browse/src/read-commands.ts +0 -358
- package/skills/browse/src/server.ts +0 -1192
- package/skills/browse/src/sidebar-agent.ts +0 -280
- package/skills/browse/src/sidebar-utils.ts +0 -21
- package/skills/browse/src/snapshot.ts +0 -407
- package/skills/browse/src/url-validation.ts +0 -95
- package/skills/browse/src/write-commands.ts +0 -364
- package/skills/browse/test/activity.test.ts +0 -120
- package/skills/browse/test/adversarial-security.test.ts +0 -32
- package/skills/browse/test/browser-manager-unit.test.ts +0 -17
- package/skills/browse/test/bun-polyfill.test.ts +0 -72
- package/skills/browse/test/commands.test.ts +0 -2075
- package/skills/browse/test/compare-board.test.ts +0 -342
- package/skills/browse/test/config.test.ts +0 -316
- package/skills/browse/test/cookie-import-browser.test.ts +0 -519
- package/skills/browse/test/cookie-picker-routes.test.ts +0 -260
- package/skills/browse/test/file-drop.test.ts +0 -271
- package/skills/browse/test/find-browse.test.ts +0 -50
- package/skills/browse/test/findport.test.ts +0 -191
- package/skills/browse/test/fixtures/basic.html +0 -33
- package/skills/browse/test/fixtures/cursor-interactive.html +0 -22
- package/skills/browse/test/fixtures/dialog.html +0 -15
- package/skills/browse/test/fixtures/empty.html +0 -2
- package/skills/browse/test/fixtures/forms.html +0 -55
- package/skills/browse/test/fixtures/iframe.html +0 -30
- package/skills/browse/test/fixtures/network-idle.html +0 -30
- package/skills/browse/test/fixtures/qa-eval-checkout.html +0 -108
- package/skills/browse/test/fixtures/qa-eval-spa.html +0 -98
- package/skills/browse/test/fixtures/qa-eval.html +0 -51
- package/skills/browse/test/fixtures/responsive.html +0 -49
- package/skills/browse/test/fixtures/snapshot.html +0 -55
- package/skills/browse/test/fixtures/spa.html +0 -24
- package/skills/browse/test/fixtures/states.html +0 -17
- package/skills/browse/test/fixtures/upload.html +0 -25
- package/skills/browse/test/gstack-config.test.ts +0 -138
- package/skills/browse/test/gstack-update-check.test.ts +0 -514
- package/skills/browse/test/handoff.test.ts +0 -235
- package/skills/browse/test/path-validation.test.ts +0 -91
- package/skills/browse/test/platform.test.ts +0 -37
- package/skills/browse/test/server-auth.test.ts +0 -65
- package/skills/browse/test/sidebar-agent-roundtrip.test.ts +0 -226
- package/skills/browse/test/sidebar-agent.test.ts +0 -199
- package/skills/browse/test/sidebar-integration.test.ts +0 -320
- package/skills/browse/test/sidebar-unit.test.ts +0 -96
- package/skills/browse/test/snapshot.test.ts +0 -467
- package/skills/browse/test/state-ttl.test.ts +0 -35
- package/skills/browse/test/test-server.ts +0 -57
- package/skills/browse/test/url-validation.test.ts +0 -72
- package/skills/browse/test/watch.test.ts +0 -129
- package/skills/canary/SKILL.md.tmpl +0 -212
- package/skills/careful/SKILL.md.tmpl +0 -56
- package/skills/careful/bin/check-careful.sh +0 -112
- package/skills/codex/SKILL.md +0 -90
- package/skills/codex/SKILL.md.tmpl +0 -417
- package/skills/connect-chrome/SKILL.md.tmpl +0 -195
- package/skills/cso/ACKNOWLEDGEMENTS.md +0 -14
- package/skills/cso/SKILL.md +0 -93
- package/skills/cso/SKILL.md.tmpl +0 -606
- package/skills/design-consultation/SKILL.md +0 -94
- package/skills/design-consultation/SKILL.md.tmpl +0 -415
- package/skills/design-review/SKILL.md +0 -94
- package/skills/design-review/SKILL.md.tmpl +0 -290
- package/skills/design-shotgun/SKILL.md +0 -91
- package/skills/design-shotgun/SKILL.md.tmpl +0 -285
- package/skills/document-release/SKILL.md +0 -91
- package/skills/document-release/SKILL.md.tmpl +0 -359
- package/skills/freeze/SKILL.md.tmpl +0 -77
- package/skills/freeze/bin/check-freeze.sh +0 -79
- package/skills/gstack-upgrade/SKILL.md.tmpl +0 -222
- package/skills/guard/SKILL.md.tmpl +0 -77
- package/skills/investigate/SKILL.md +0 -105
- package/skills/investigate/SKILL.md.tmpl +0 -194
- package/skills/land-and-deploy/SKILL.md.tmpl +0 -881
- package/skills/office-hours/SKILL.md +0 -96
- package/skills/office-hours/SKILL.md.tmpl +0 -645
- package/skills/plan-ceo-review/SKILL.md +0 -94
- package/skills/plan-ceo-review/SKILL.md.tmpl +0 -811
- package/skills/plan-design-review/SKILL.md +0 -92
- package/skills/plan-design-review/SKILL.md.tmpl +0 -446
- package/skills/plan-eng-review/SKILL.md +0 -93
- package/skills/plan-eng-review/SKILL.md.tmpl +0 -303
- package/skills/qa/SKILL.md +0 -95
- package/skills/qa/SKILL.md.tmpl +0 -316
- package/skills/qa/references/issue-taxonomy.md +0 -85
- package/skills/qa/templates/qa-report-template.md +0 -126
- package/skills/qa-only/SKILL.md +0 -89
- package/skills/qa-only/SKILL.md.tmpl +0 -101
- package/skills/retro/SKILL.md +0 -89
- package/skills/retro/SKILL.md.tmpl +0 -820
- package/skills/review/SKILL.md +0 -92
- package/skills/review/SKILL.md.tmpl +0 -281
- package/skills/review/TODOS-format.md +0 -62
- package/skills/review/checklist.md +0 -220
- package/skills/review/design-checklist.md +0 -132
- package/skills/review/greptile-triage.md +0 -220
- package/skills/setup-browser-cookies/SKILL.md.tmpl +0 -81
- package/skills/setup-deploy/SKILL.md +0 -92
- package/skills/setup-deploy/SKILL.md.tmpl +0 -215
- package/skills/ship/SKILL.md.tmpl +0 -636
- package/skills/unfreeze/SKILL.md +0 -37
- package/skills/unfreeze/SKILL.md.tmpl +0 -36
|
@@ -1,519 +0,0 @@
|
|
|
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
|
-
});
|