From fb86bd368ea14dfa1335cf74a17a49ee240c47ce Mon Sep 17 00:00:00 2001 From: Roger Date: Mon, 26 Oct 2026 16:22:58 +0800 Subject: [PATCH] test: pin today's output with compatibility goldens (#649) Phase 0, part 2: freeze the output files, keys.json, and archives today's code writes, so every later phase can prove it changes nothing. --- cmd/hack-browser-data/archive_golden_test.go | 118 ++ .../chromium_fixture_test.go | 483 +++++++ cmd/hack-browser-data/export_golden_test.go | 378 ++++++ cmd/hack-browser-data/extract_golden_test.go | 43 + cmd/hack-browser-data/flags_test.go | 17 +- cmd/hack-browser-data/golden_test.go | 94 ++ cmd/hack-browser-data/keys_golden_test.go | 256 ++++ cmd/hack-browser-data/restore_golden_test.go | 113 ++ rfcs/011-testing-and-quality.md | 2 + testdata/archive-all.golden | 31 + testdata/archive-cookie.golden | 8 + testdata/export-cookie-editor.golden | 72 ++ testdata/export-csv.golden | 61 + testdata/export-json.golden | 397 ++++++ testdata/export-zip.golden | 9 + testdata/extract-cookie-editor.golden | 191 +++ testdata/extract-csv.golden | 128 ++ testdata/extract-json.golden | 1133 +++++++++++++++++ .../testdata => testdata}/flags.golden | 0 testdata/keys-empty.golden | 9 + testdata/keys.golden | 71 ++ testdata/restore-zip.golden | 9 + 22 files changed, 3607 insertions(+), 16 deletions(-) create mode 100644 cmd/hack-browser-data/archive_golden_test.go create mode 100644 cmd/hack-browser-data/chromium_fixture_test.go create mode 100644 cmd/hack-browser-data/export_golden_test.go create mode 100644 cmd/hack-browser-data/extract_golden_test.go create mode 100644 cmd/hack-browser-data/golden_test.go create mode 100644 cmd/hack-browser-data/keys_golden_test.go create mode 100644 cmd/hack-browser-data/restore_golden_test.go create mode 100644 testdata/archive-all.golden create mode 100644 testdata/archive-cookie.golden create mode 100644 testdata/export-cookie-editor.golden create mode 100644 testdata/export-csv.golden create mode 100644 testdata/export-json.golden create mode 100644 testdata/export-zip.golden create mode 100644 testdata/extract-cookie-editor.golden create mode 100644 testdata/extract-csv.golden create mode 100644 testdata/extract-json.golden rename {cmd/hack-browser-data/testdata => testdata}/flags.golden (100%) create mode 100644 testdata/keys-empty.golden create mode 100644 testdata/keys.golden create mode 100644 testdata/restore-zip.golden diff --git a/cmd/hack-browser-data/archive_golden_test.go b/cmd/hack-browser-data/archive_golden_test.go new file mode 100644 index 0000000..f8553a1 --- /dev/null +++ b/cmd/hack-browser-data/archive_golden_test.go @@ -0,0 +1,118 @@ +package main + +import ( + "archive/zip" + "fmt" + "os" + "path" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/moond4rk/hackbrowserdata/browser" + "github.com/moond4rk/hackbrowserdata/browser/chromium" + "github.com/moond4rk/hackbrowserdata/types" +) + +const archiveLayoutKey = "chrome" + +var archiveLayoutProfileFiles = []string{ + "Preferences", + "Login Data", + "Network/Cookies", + "History", + "Bookmarks", + "Web Data", + "Secure Preferences", + "Local Storage/leveldb/000003.log", + "Local Storage/leveldb/CURRENT", + "Local Storage/leveldb/LOCK", + "Local Storage/leveldb/MANIFEST-000001", + "Session Storage/000004.log", + "Session Storage/CURRENT", + "Session Storage/LOCK", + "Session Storage/MANIFEST-000001", +} + +var archiveLayoutExtraFiles = []string{ + "Local State", + "Default/Login Data For Account", + "Default/Network/Cookies-wal", + "Default/Network/Cookies-shm", + "Default/Favicons", + "System Profile/Preferences", + "System Profile/History", +} + +func archiveLayoutUserData(t *testing.T) string { + t.Helper() + root := t.TempDir() + files := append([]string{}, archiveLayoutExtraFiles...) + for _, profile := range []string{"Default", "Profile 1"} { + for _, rel := range archiveLayoutProfileFiles { + files = append(files, profile+"/"+rel) + } + } + for _, rel := range files { + abs := filepath.Join(root, filepath.FromSlash(rel)) + require.NoError(t, os.MkdirAll(filepath.Dir(abs), 0o755)) + require.NoError(t, os.WriteFile(abs, []byte(rel), 0o600)) + } + return root +} + +func archiveLayoutEntryNames(t *testing.T, zipPath string) []string { + t.Helper() + r, err := zip.OpenReader(zipPath) + require.NoError(t, err) + defer r.Close() + names := make([]string, 0, len(r.File)) + for _, f := range r.File { + names = append(names, f.Name) + } + return names +} + +func TestArchiveGolden(t *testing.T) { + b, err := chromium.NewBrowser(types.BrowserConfig{ + Key: archiveLayoutKey, + Name: "Chrome", + Kind: types.Chromium, + UserDataDir: archiveLayoutUserData(t), + }) + require.NoError(t, err) + require.NotNil(t, b) + + tests := []struct { + name string + golden string + categories []types.Category + }{ + {name: "all", golden: "archive-all.golden", categories: types.AllCategories}, + {name: "cookie", golden: "archive-cookie.golden", categories: []types.Category{types.Cookie}}, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + out := filepath.Join(t.TempDir(), "browser-data.zip") + n, err := browser.WriteArchive([]browser.Browser{b}, tt.categories, out) + require.NoError(t, err) + assertGolden(t, tt.golden, fmt.Sprintf("entries=%d\n", n)+zipListing(t, out)) + + prefix := archiveLayoutKey + "/" + names := archiveLayoutEntryNames(t, out) + for _, name := range names { + assert.Truef(t, strings.HasPrefix(name, prefix), "entry %q lacks the %q prefix", name, prefix) + assert.NotContains(t, name, `\`) + assert.NotEqual(t, "LOCK", path.Base(name)) + assert.Falsef(t, strings.HasPrefix(name, prefix+"System Profile/"), "entry %q comes from a skipped profile", name) + } + assert.Contains(t, names, prefix+"Default/Network/Cookies") + assert.Contains(t, names, prefix+"Default/Network/Cookies-wal") + assert.NotContains(t, names, prefix+"Default/Favicons") + }) + } +} diff --git a/cmd/hack-browser-data/chromium_fixture_test.go b/cmd/hack-browser-data/chromium_fixture_test.go new file mode 100644 index 0000000..fcb65eb --- /dev/null +++ b/cmd/hack-browser-data/chromium_fixture_test.go @@ -0,0 +1,483 @@ +package main + +import ( + "crypto/sha256" + "database/sql" + "encoding/binary" + "encoding/hex" + "fmt" + "os" + "path/filepath" + "sort" + "strings" + "testing" + "time" + "unicode/utf16" + + "github.com/stretchr/testify/require" + "github.com/syndtr/goleveldb/leveldb" + _ "modernc.org/sqlite" + + "github.com/moond4rk/hackbrowserdata/browser" + "github.com/moond4rk/hackbrowserdata/browser/chromium" + "github.com/moond4rk/hackbrowserdata/crypto" + "github.com/moond4rk/hackbrowserdata/masterkey" + "github.com/moond4rk/hackbrowserdata/types" +) + +// Only GCM-sealed values (v10 under a 32-byte key, v20) decrypt identically on every OS. +var chromiumFixtureKeys = masterkey.MasterKeys{ + V10: []byte("0123456789abcdef0123456789abcdef"), + V20: []byte("0123456789abcdef"), +} + +var chromiumFixtureInstalls = []struct { + key string + name string +}{ + {key: "chrome", name: "Chrome"}, + {key: "edge", name: "Microsoft Edge"}, +} + +var chromiumFixtureProfiles = []struct { + dir string + label string + start time.Time + accountLogins bool +}{ + {dir: "Default", label: "home", start: time.Date(2024, 3, 1, 9, 0, 0, 0, time.UTC), accountLogins: true}, + {dir: "Profile 1", label: "work", start: time.Date(2024, 6, 1, 9, 0, 0, 0, time.UTC)}, +} + +func chromiumFixtureInstallations(t *testing.T, root string) { + t.Helper() + for _, inst := range chromiumFixtureInstalls { + chromiumFixtureUserData(t, filepath.Join(root, inst.key), inst.key) + } +} + +func chromiumFixtureBrowsers(t *testing.T, root string) []browser.Browser { + t.Helper() + browsers := make([]browser.Browser, 0, len(chromiumFixtureInstalls)) + for _, inst := range chromiumFixtureInstalls { + b, err := chromium.NewBrowser(types.BrowserConfig{ + Key: inst.key, + Name: inst.name, + Kind: types.Chromium, + UserDataDir: filepath.Join(root, inst.key), + }) + require.NoError(t, err) + require.NotNil(t, b) + b.SetRetrievers(chromiumFixtureRetrievers(chromiumFixtureKeys)) + browsers = append(browsers, b) + } + return browsers +} + +func chromiumFixtureRetrievers(keys masterkey.MasterKeys) masterkey.Retrievers { + return masterkey.Retrievers{ + V10: chromiumFixtureStaticRetriever(keys.V10), + V11: chromiumFixtureStaticRetriever(keys.V11), + V20: chromiumFixtureStaticRetriever(keys.V20), + } +} + +func chromiumFixtureStaticRetriever(key []byte) masterkey.Retriever { + if len(key) == 0 { + return nil + } + return masterkey.NewStaticRetriever(key) +} + +func chromiumFixtureUserData(t *testing.T, userDataDir, browserKey string) { + t.Helper() + chromiumFixtureWrite(t, filepath.Join(userDataDir, "Local State"), "{}") + for _, p := range chromiumFixtureProfiles { + site := p.label + "." + browserKey + ".test" + chromiumFixtureProfile(t, filepath.Join(userDataDir, p.dir), site, p.start, p.accountLogins) + } +} + +func chromiumFixtureProfile(t *testing.T, dir, site string, start time.Time, accountLogins bool) { + t.Helper() + at := func(offset time.Duration) int64 { return chromiumFixtureMicros(start.Add(offset)) } + link := func(host, path string) string { return "https://" + host + "." + site + path } + v10 := func(plaintext string) string { + return chromiumFixtureSeal(t, "v10", chromiumFixtureKeys.V10, plaintext) + } + v20 := func(plaintext string) string { + return chromiumFixtureSeal(t, "v20", chromiumFixtureKeys.V20, plaintext) + } + // Chrome 130+ seals SHA256(host_key) ahead of the cookie value, which extraction must strip again. + hostBound := func(host, value string) string { + sum := sha256.Sum256([]byte(host)) + return string(sum[:]) + value + } + day := 24 * time.Hour + + chromiumFixtureWrite(t, filepath.Join(dir, "Preferences"), "{}") + + chromiumFixtureSQLite(t, filepath.Join(dir, "Login Data"), chromiumFixtureLoginsSchema, + chromiumFixtureInsertLogin(link("accounts", "/"), link("accounts", "/login"), "alice", + v10("correct-horse-battery-staple"), at(time.Hour)), + chromiumFixtureInsertLogin(link("shop", "/"), link("shop", "/signin"), "alice@"+site, v10(`pa,ss"word`), at(2*time.Hour)), + ) + if accountLogins { + chromiumFixtureSQLite(t, filepath.Join(dir, "Login Data For Account"), chromiumFixtureLoginsSchema, + chromiumFixtureInsertLogin(link("sync", "/"), link("sync", "/auth"), "alice", v10("synced-secret"), at(90*time.Minute)), + ) + } + + domain, www, app := "."+site, "www."+site, "app."+site + chromiumFixtureSQLite(t, filepath.Join(dir, "Network", "Cookies"), chromiumFixtureCookiesSchema, + chromiumFixtureInsertCookie("SID", domain, "/", v20(hostBound(domain, "sid-"+site)), + at(10*time.Minute+123456*time.Microsecond), at(365*day), 1, 1, 1), + chromiumFixtureInsertCookie("prefs", www, "/settings", v10("theme=dark"), at(20*time.Minute), at(30*day), 0, 0, 2), + chromiumFixtureInsertCookie("tracker", domain, "/", v20(hostBound(domain, "opt-out")), at(30*time.Minute), at(730*day), 1, 0, 0), + chromiumFixtureInsertCookie("session", app, "/", v20("ephemeral"), at(40*time.Minute), 0, 1, 1, -1), + ) + + chromiumFixtureSQLite(t, filepath.Join(dir, "History"), chromiumFixtureURLsSchema, chromiumFixtureDownloadsSchema, + chromiumFixtureInsertURL(link("www", "/"), "Home", 42, at(3*time.Hour)), + chromiumFixtureInsertURL(link("docs", "/guide?q=go&lang=en"), `Guide, "quoted" & bold`, 7, at(4*time.Hour)), + chromiumFixtureInsertURL(link("news", "/ja"), "ニュース", 3, at(5*time.Hour)), + chromiumFixtureInsertDownload(`C:\Users\alice\Downloads\report.pdf`, link("files", "/report.pdf"), "application/pdf", + 52344, at(6*time.Hour), at(6*time.Hour+3*time.Second)), + chromiumFixtureInsertDownload("/home/alice/Downloads/archive.tar.gz", link("files", "/archive.tar.gz"), "application/gzip", + 1048576, at(7*time.Hour), 0), + ) + + chromiumFixtureWrite(t, filepath.Join(dir, "Bookmarks"), + fmt.Sprintf(chromiumFixtureBookmarks, site, at(0), at(8*time.Hour), at(9*time.Hour), at(10*time.Hour))) + + chromiumFixtureSQLite(t, filepath.Join(dir, "Web Data"), chromiumFixtureCreditCardsSchema, + chromiumFixtureInsertCreditCard("Alice Example", 4, 2031, v10("4111111111111111"), "Travel", "billing-home"), + chromiumFixtureInsertCreditCard("Bob Example", 11, 2029, v10("5500005555555559"), "", ""), + ) + + chromiumFixtureWrite(t, filepath.Join(dir, "Secure Preferences"), chromiumFixtureSecurePreferences) + + origin := link("app", "") + dataKey := "_" + origin + "\x00" + chromiumFixtureLevelDB(t, filepath.Join(dir, "Local Storage", "leveldb"), map[string]string{ + "VERSION": "1", + "META:" + origin: "\x08\x96\x01", + "METAACCESS:" + origin: "\x10\x20", + dataKey + chromiumFixtureLatin1("greeting"): chromiumFixtureLatin1("caf\xe9"), + dataKey + chromiumFixtureUTF16("言語"): chromiumFixtureUTF16("日本語"), + dataKey + chromiumFixtureLatin1("blob"): chromiumFixtureLatin1(strings.Repeat("x", 2100)), + }) + + namespace := "namespace-0a1b2c3d_4e5f_6a7b_8c9d_0e1f2a3b4c5d-" + chromiumFixtureLevelDB(t, filepath.Join(dir, "Session Storage"), map[string]string{ + namespace + link("app", "/"): "1", + namespace + link("shop", "/"): "2", + "map-1-draft": chromiumFixtureUTF16Raw("Hello, world"), + "map-1-scrollY": chromiumFixtureUTF16Raw("640"), + "map-2-cart": chromiumFixtureUTF16Raw(`{"items":2}`), + "next-map-id": "3", + "version": "1", + }) +} + +func chromiumFixtureSeal(t *testing.T, version string, key []byte, plaintext string) string { + t.Helper() + nonce := []byte(version + "_nonce_12") + sealed, err := crypto.AESGCMEncrypt(key, nonce, []byte(plaintext)) + require.NoError(t, err) + return hex.EncodeToString(append(append([]byte(version), nonce...), sealed...)) +} + +func chromiumFixtureMicros(ts time.Time) int64 { + const unixToChromiumEpochMicros = 11_644_473_600_000_000 + return ts.UnixMicro() + unixToChromiumEpochMicros +} + +func chromiumFixtureLatin1(s string) string { return "\x01" + s } + +func chromiumFixtureUTF16(s string) string { return "\x00" + chromiumFixtureUTF16Raw(s) } + +func chromiumFixtureUTF16Raw(s string) string { + units := utf16.Encode([]rune(s)) + b := make([]byte, 2*len(units)) + for i, u := range units { + binary.LittleEndian.PutUint16(b[2*i:], u) + } + return string(b) +} + +func chromiumFixtureWrite(t *testing.T, path, content string) { + t.Helper() + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + require.NoError(t, os.WriteFile(path, []byte(content), 0o644)) +} + +func chromiumFixtureSQLite(t *testing.T, path string, stmts ...string) { + t.Helper() + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + db, err := sql.Open("sqlite", path) + require.NoError(t, err) + defer db.Close() + for _, stmt := range stmts { + _, err = db.Exec(stmt) + require.NoError(t, err) + } +} + +func chromiumFixtureLevelDB(t *testing.T, dir string, entries map[string]string) { + t.Helper() + keys := make([]string, 0, len(entries)) + for k := range entries { + keys = append(keys, k) + } + sort.Strings(keys) + db, err := leveldb.OpenFile(dir, nil) + require.NoError(t, err) + for _, k := range keys { + require.NoError(t, db.Put([]byte(k), []byte(entries[k]), nil)) + } + require.NoError(t, db.Close()) +} + +func chromiumFixtureInsertLogin(originURL, actionURL, username, pwdHex string, dateCreated int64) string { + return fmt.Sprintf( + `INSERT INTO logins (origin_url, action_url, username_element, username_value, + password_element, password_value, submit_element, signon_realm, date_created, + blacklisted_by_user, scheme) + VALUES ('%s', '%s', '', '%s', '', x'%s', '', '%s', %d, 0, 0)`, + originURL, actionURL, username, pwdHex, originURL, dateCreated, + ) +} + +func chromiumFixtureInsertCookie( + name, host, path, encValueHex string, creationUTC, expiresUTC int64, secure, httpOnly, sameSite int, +) string { + persistent := 0 + if expiresUTC != 0 { + persistent = 1 + } + return fmt.Sprintf( + `INSERT INTO cookies (creation_utc, host_key, top_frame_site_key, name, value, + encrypted_value, path, expires_utc, is_secure, is_httponly, last_access_utc, + has_expires, is_persistent, priority, samesite, source_scheme, source_port, + last_update_utc, source_type, has_cross_site_ancestor) + VALUES (%d, '%s', '', '%s', '', x'%s', '%s', %d, %d, %d, %d, %d, %d, 1, %d, 2, 443, %d, 0, 0)`, + creationUTC, host, name, encValueHex, path, expiresUTC, secure, httpOnly, creationUTC, + persistent, persistent, sameSite, creationUTC, + ) +} + +func chromiumFixtureInsertURL(url, title string, visitCount int, lastVisitTime int64) string { + return fmt.Sprintf( + `INSERT INTO urls (url, title, visit_count, typed_count, last_visit_time, hidden) + VALUES ('%s', '%s', %d, 0, %d, 0)`, + url, title, visitCount, lastVisitTime, + ) +} + +func chromiumFixtureInsertDownload(targetPath, tabURL, mimeType string, totalBytes, startTime, endTime int64) string { + return fmt.Sprintf( + `INSERT INTO downloads (id, guid, current_path, target_path, start_time, received_bytes, + total_bytes, state, danger_type, interrupt_reason, hash, end_time, opened, last_access_time, + transient, referrer, site_url, embedder_download_data, tab_url, tab_referrer_url, + http_method, by_ext_id, by_ext_name, by_web_app_id, etag, last_modified, mime_type, original_mime_type) + VALUES (NULL, '', '', '%s', %d, %d, %d, 1, 0, 0, x'', %d, 0, 0, 0, '', '', '', '%s', '', 'GET', '', '', '', '', '', '%s', '')`, + targetPath, startTime, totalBytes, totalBytes, endTime, tabURL, mimeType, + ) +} + +func chromiumFixtureInsertCreditCard(name string, month, year int, encNumberHex, nickName, address string) string { + return fmt.Sprintf( + `INSERT INTO credit_cards (guid, name_on_card, expiration_month, expiration_year, card_number_encrypted, + nickname, billing_address_id) + VALUES ('%s-%d-%d', '%s', %d, %d, x'%s', '%s', '%s')`, + name, month, year, name, month, year, encNumberHex, nickName, address, + ) +} + +const chromiumFixtureLoginsSchema = `CREATE TABLE logins ( + origin_url VARCHAR NOT NULL, + action_url VARCHAR, + username_element VARCHAR, + username_value VARCHAR, + password_element VARCHAR, + password_value BLOB, + submit_element VARCHAR, + signon_realm VARCHAR NOT NULL, + date_created INTEGER NOT NULL, + blacklisted_by_user INTEGER NOT NULL, + scheme INTEGER NOT NULL, + password_type INTEGER, + times_used INTEGER, + form_data BLOB, + display_name VARCHAR, + icon_url VARCHAR, + federation_url VARCHAR, + skip_zero_click INTEGER, + generation_upload_status INTEGER, + possible_username_pairs BLOB, + id INTEGER PRIMARY KEY AUTOINCREMENT, + date_last_used INTEGER NOT NULL DEFAULT 0, + moving_blocked_for BLOB, + date_password_modified INTEGER NOT NULL DEFAULT 0, + sender_email VARCHAR, + sender_name VARCHAR, + date_received INTEGER, + sharing_notification_displayed INTEGER NOT NULL DEFAULT 0, + keychain_identifier BLOB, + sender_profile_image_url VARCHAR, + date_last_filled INTEGER NOT NULL DEFAULT 0, + actor_login_approved INTEGER NOT NULL DEFAULT 0, + UNIQUE (origin_url, username_element, username_value, password_element, signon_realm) +)` + +const chromiumFixtureCookiesSchema = `CREATE TABLE cookies ( + creation_utc INTEGER NOT NULL, + host_key TEXT NOT NULL, + top_frame_site_key TEXT NOT NULL, + name TEXT NOT NULL, + value TEXT NOT NULL, + encrypted_value BLOB NOT NULL, + path TEXT NOT NULL, + expires_utc INTEGER NOT NULL, + is_secure INTEGER NOT NULL, + is_httponly INTEGER NOT NULL, + last_access_utc INTEGER NOT NULL, + has_expires INTEGER NOT NULL, + is_persistent INTEGER NOT NULL, + priority INTEGER NOT NULL, + samesite INTEGER NOT NULL, + source_scheme INTEGER NOT NULL, + source_port INTEGER NOT NULL, + last_update_utc INTEGER NOT NULL, + source_type INTEGER NOT NULL, + has_cross_site_ancestor INTEGER NOT NULL +)` + +const chromiumFixtureURLsSchema = `CREATE TABLE urls ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + url LONGVARCHAR, + title LONGVARCHAR, + visit_count INTEGER DEFAULT 0 NOT NULL, + typed_count INTEGER DEFAULT 0 NOT NULL, + last_visit_time INTEGER NOT NULL, + hidden INTEGER DEFAULT 0 NOT NULL +)` + +const chromiumFixtureDownloadsSchema = `CREATE TABLE downloads ( + id INTEGER PRIMARY KEY, + guid VARCHAR NOT NULL, + current_path LONGVARCHAR NOT NULL, + target_path LONGVARCHAR NOT NULL, + start_time INTEGER NOT NULL, + received_bytes INTEGER NOT NULL, + total_bytes INTEGER NOT NULL, + state INTEGER NOT NULL, + danger_type INTEGER NOT NULL, + interrupt_reason INTEGER NOT NULL, + hash BLOB NOT NULL, + end_time INTEGER NOT NULL, + opened INTEGER NOT NULL, + last_access_time INTEGER NOT NULL, + transient INTEGER NOT NULL, + referrer VARCHAR NOT NULL, + site_url VARCHAR NOT NULL, + embedder_download_data VARCHAR NOT NULL, + tab_url VARCHAR NOT NULL, + tab_referrer_url VARCHAR NOT NULL, + http_method VARCHAR NOT NULL, + by_ext_id VARCHAR NOT NULL, + by_ext_name VARCHAR NOT NULL, + by_web_app_id VARCHAR NOT NULL, + etag VARCHAR NOT NULL, + last_modified VARCHAR NOT NULL, + mime_type VARCHAR(255) NOT NULL, + original_mime_type VARCHAR(255) NOT NULL +)` + +const chromiumFixtureCreditCardsSchema = `CREATE TABLE credit_cards ( + guid VARCHAR PRIMARY KEY, + name_on_card VARCHAR, + expiration_month INTEGER, + expiration_year INTEGER, + card_number_encrypted BLOB, + date_modified INTEGER NOT NULL DEFAULT 0, + origin VARCHAR DEFAULT '', + use_count INTEGER NOT NULL DEFAULT 0, + use_date INTEGER NOT NULL DEFAULT 0, + billing_address_id VARCHAR, + nickname VARCHAR +)` + +const chromiumFixtureBookmarks = `{ + "checksum": "00000000000000000000000000000000", + "roots": { + "bookmark_bar": { + "children": [ + {"date_added": "%[3]d", "id": "4", "name": "Docs", "type": "url", "url": "https://docs.%[1]s/"}, + { + "children": [ + {"date_added": "%[4]d", "id": "6", "name": "Long read & tags", "type": "url", "url": "https://news.%[1]s/long-read"} + ], + "date_added": "%[2]d", + "id": "5", + "name": "Reading", + "type": "folder" + } + ], + "date_added": "%[2]d", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ + {"date_added": "%[5]d", "id": "7", "name": "Café menu", "type": "url", "url": "https://shop.%[1]s/menu"} + ], + "date_added": "%[2]d", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": {"children": [], "date_added": "%[2]d", "id": "3", "name": "Mobile bookmarks", "type": "folder"} + }, + "version": 1 +}` + +const chromiumFixtureSecurePreferences = `{ + "extensions": { + "settings": { + "aaaabbbbccccddddeeeeffffgggghhhh": { + "disable_reasons": [], + "location": 1, + "manifest": { + "description": "Groups tabs by site, \"neatly\" & ", + "homepage_url": "https://tabs.example/", + "name": "Tab Organizer", + "version": "2.4.1" + } + }, + "iiiijjjjkkkkllllmmmmnnnnoooopppp": { + "disable_reasons": [1], + "location": 1, + "manifest": {"description": "Distraction-free reading", "name": "Reader Mode", "version": "0.9.0"} + }, + "ppppoooonnnnmmmmllllkkkkjjjjiiii": { + "location": 5, + "manifest": {"name": "Built-in Component", "version": "1.0"} + }, + "hhhhggggffffeeeeddddccccbbbbaaaa": { + "location": 10, + "manifest": {"name": "External Component", "version": "1.0"} + }, + "abcdabcdabcdabcdabcdabcdabcdabcd": { + "location": 4, + "manifest": {"name": "Legacy Unpacked", "version": "0.1"}, + "state": 1 + }, + "dcbadcbadcbadcbadcbadcbadcbadcba": { + "location": 1 + } + } + } +}` diff --git a/cmd/hack-browser-data/export_golden_test.go b/cmd/hack-browser-data/export_golden_test.go new file mode 100644 index 0000000..7ff0da8 --- /dev/null +++ b/cmd/hack-browser-data/export_golden_test.go @@ -0,0 +1,378 @@ +package main + +import ( + "archive/zip" + "io" + "os" + "path/filepath" + "runtime" + "sort" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/moond4rk/hackbrowserdata/output" + "github.com/moond4rk/hackbrowserdata/types" + "github.com/moond4rk/hackbrowserdata/utils/fileutil" +) + +const ( + exportUTF8BOM = "\xEF\xBB\xBF" + exportURLWithHTMLChars = "https://shop.example.com/cart?item=42&qty=<3>" + exportURLWithHTMLCharsEscaped = `https://shop.example.com/cart?item=42\u0026qty=\u003c3\u003e` +) + +type exportStamp struct { + browser string + profile string + data *types.BrowserData +} + +type exportURLForm struct { + file string + escaped bool +} + +func TestExportGolden(t *testing.T) { + formats := []struct { + format string + ext string + urlForms []exportURLForm + jsonFallback bool + }{ + { + format: "csv", + ext: "csv", + urlForms: []exportURLForm{{file: "cookie.csv"}, {file: "history.csv"}}, + }, + { + format: "json", + ext: "json", + urlForms: []exportURLForm{{file: "cookie.json", escaped: true}, {file: "history.json", escaped: true}}, + }, + { + format: "cookie-editor", + ext: "json", + urlForms: []exportURLForm{{file: "cookie.json"}, {file: "history.json", escaped: true}}, + jsonFallback: true, + }, + } + for _, tc := range formats { + tc := tc + t.Run(tc.format, func(t *testing.T) { + dir := filepath.Join(t.TempDir(), "results") + exportWrite(t, dir, tc.format, exportStamps()) + got := bundleDir(t, dir) + if tc.jsonFallback { + jsonDir := filepath.Join(t.TempDir(), "results") + exportWrite(t, jsonDir, "json", exportStamps()) + assertJSONFallback(t, dir, jsonDir) + got = bundleFiles(t, dir, "cookie.json") + } + assertGolden(t, "export-"+tc.format+".golden", got) + assert.Equal(t, exportCategoryFiles(tc.ext, types.AllCategories...), exportDirFiles(t, dir)) + exportAssertFileContract(t, dir) + for _, form := range tc.urlForms { + exportAssertURLForm(t, dir, form) + } + + sparse := filepath.Join(t.TempDir(), "sparse") + exportWrite(t, sparse, tc.format, exportSparseStamps()) + assert.Equal(t, exportCategoryFiles(tc.ext, types.Password, types.LocalStorage), exportDirFiles(t, sparse)) + }) + } + + t.Run("zip", func(t *testing.T) { + dir := filepath.Join(t.TempDir(), "results") + exportWrite(t, dir, "csv", exportStamps()) + loose := readDirFiles(t, dir) + require.NoError(t, fileutil.CompressDir(dir)) + + assert.Equal(t, []string{"results.zip"}, exportDirFiles(t, dir)) + archive := filepath.Join(dir, "results.zip") + assertGolden(t, "export-zip.golden", zipListing(t, archive)) + assert.Equal(t, loose, exportReadZip(t, archive)) + }) +} + +func exportWrite(t *testing.T, dir, format string, stamps []exportStamp) { + t.Helper() + w, err := output.NewWriter(dir, format) + require.NoError(t, err) + for _, s := range stamps { + w.Add(s.browser, s.profile, s.data) + } + require.NoError(t, w.Write()) +} + +func exportCategoryFiles(ext string, categories ...types.Category) []string { + names := make([]string, 0, len(categories)) + for _, c := range categories { + names = append(names, c.String()+"."+ext) + } + sort.Strings(names) + return names +} + +func exportDirFiles(t *testing.T, dir string) []string { + t.Helper() + entries, err := os.ReadDir(dir) + require.NoError(t, err) + names := make([]string, 0, len(entries)) + for _, e := range entries { + names = append(names, e.Name()) + } + return names +} + +func exportReadFile(t *testing.T, dir, name string) string { + t.Helper() + data, err := os.ReadFile(filepath.Join(dir, name)) + require.NoError(t, err) + return string(data) +} + +func exportReadZip(t *testing.T, path string) map[string]string { + t.Helper() + r, err := zip.OpenReader(path) + require.NoError(t, err) + defer r.Close() + entries := make(map[string]string, len(r.File)) + for _, f := range r.File { + entries[f.Name] = exportReadZipEntry(t, f) + } + return entries +} + +func exportReadZipEntry(t *testing.T, f *zip.File) string { + t.Helper() + rc, err := f.Open() + require.NoError(t, err) + defer rc.Close() + data, err := io.ReadAll(rc) + require.NoError(t, err) + return string(data) +} + +func exportAssertFileContract(t *testing.T, dir string) { + t.Helper() + for _, name := range exportDirFiles(t, dir) { + content := exportReadFile(t, dir, name) + switch filepath.Ext(name) { + case ".csv": + assert.Truef(t, strings.HasPrefix(content, exportUTF8BOM), "%s must start with the UTF-8 BOM", name) + case ".json": + assert.Falsef(t, strings.HasPrefix(content, exportUTF8BOM), "%s must not start with a BOM", name) + default: + t.Errorf("unexpected output file %s", name) + } + if runtime.GOOS != "windows" { + info, err := os.Stat(filepath.Join(dir, name)) + require.NoError(t, err) + assert.Equalf(t, os.FileMode(0o600), info.Mode().Perm(), "%s permissions", name) + } + } +} + +func exportAssertURLForm(t *testing.T, dir string, form exportURLForm) { + t.Helper() + present, absent := exportURLWithHTMLChars, exportURLWithHTMLCharsEscaped + if form.escaped { + present, absent = absent, present + } + content := exportReadFile(t, dir, form.file) + assert.Containsf(t, content, present, "%s", form.file) + assert.NotContainsf(t, content, absent, "%s", form.file) +} + +// Entries are listed in extractor sort order with unique sort keys, so re-sorting a profile cannot change a golden. +func exportStamps() []exportStamp { + return []exportStamp{ + {browser: "Chrome", profile: "Default", data: &types.BrowserData{ + Passwords: []types.LoginEntry{ + { + URL: "https://accounts.example.com/signin?continue=/mail&hl=ja", Username: "alice@example.com", + Password: "pa$$ \"quoted\", comma\\backslash\nnewline", + CreatedAt: time.Date(2026, 3, 14, 15, 9, 26, 535897932, time.UTC), Store: types.PasswordStoreAccount, + }, + { + URL: "https://例え.jp/ログイン", Username: "日本語ユーザー", Password: "🔑 emoji", + CreatedAt: time.Date(2025, 11, 5, 6, 7, 8, 0, time.UTC), Store: types.PasswordStoreLocal, + }, + }, + Cookies: []types.CookieEntry{ + { + Host: ".example.com", Path: "/", Name: "return_to", Value: exportURLWithHTMLChars, + IsSecure: true, IsHTTPOnly: true, HasExpire: true, IsPersistent: true, + ExpireAt: time.Date(2027, 6, 30, 12, 34, 56, 789000000, time.UTC), + CreatedAt: time.Date(2026, 3, 14, 15, 9, 27, 100000000, time.UTC), SameSite: "lax", + }, + { + Host: "www.example.com", Path: "/account", Name: "session_id", Value: `{"user":"日本語 🍪","dir":"C:\Temp"}`, + IsHTTPOnly: true, CreatedAt: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), SameSite: "strict", + }, + }, + Histories: []types.HistoryEntry{ + { + URL: exportURLWithHTMLChars, Title: `Cart "deals" &, 日本語 🛒`, VisitCount: 42, + LastVisit: time.Date(2026, 3, 14, 15, 10, 0, 1000, time.UTC), + }, + {URL: "file:///C:/Users/Alice/notes.html", Title: "multi\nline title", VisitCount: 3}, + }, + Downloads: []types.DownloadEntry{ + { + URL: "https://dl.example.com/files/big.iso?token=a&sig=", + TargetPath: `C:\Users\Alice\Downloads\Ubuntu "final", v2.iso`, + MimeType: "application/x-iso9660-image", TotalBytes: 5368709121, + StartTime: time.Date(2026, 3, 14, 15, 0, 0, 250000000, time.UTC), + EndTime: time.Date(2026, 3, 14, 15, 30, 0, 750000000, time.UTC), + }, + }, + Bookmarks: []types.BookmarkEntry{ + { + ID: 7, Name: "Docs & ", Type: "url", URL: "https://docs.example.com/search?a=1&b=<2>", Folder: "Bookmarks bar", + CreatedAt: time.Date(2026, 2, 2, 2, 2, 2, 20202020, time.UTC), + }, + {ID: 4294967298, Name: "日本語 📚", Type: "url", URL: "https://例え.jp/", Folder: "Other bookmarks"}, + }, + CreditCards: []types.CreditCardEntry{ + { + GUID: "00000000-0000-4000-8000-000000000001", Name: "山田 太郎", Number: "4111111111111111", + ExpMonth: "12", ExpYear: "2030", NickName: `Work "primary", 💳`, Address: "1-2-3 Chiyoda,\nTokyo 100-0001", + }, + }, + Extensions: []types.ExtensionEntry{ + { + Name: "Ad Blocker", ID: "abcdefghijklmnopabcdefghijklmnop", Description: `Blocks ads & trackers, "fast" `, + Version: "1.58.0", HomepageURL: "https://adblock.example/?a=1&b=<2>", Enabled: true, + }, + }, + LocalStorage: []types.StorageEntry{ + {URL: "https://app.example.com", Key: "prefs", Value: `{"theme":"dark","greeting":"こんにちは 👋","dir":"C:\Temp"}`}, + {IsMeta: true, URL: "https://app.example.com", Value: "meta data, value bytes is [8 128 1]"}, + }, + SessionStorage: []types.StorageEntry{ + {URL: "https://app.example.com", Key: "tab-id", Value: "42"}, + }, + }}, + {browser: "Chrome", profile: "Profile 1", data: &types.BrowserData{ + Passwords: []types.LoginEntry{ + { + URL: "http://192.168.0.1:8080/admin", Username: "admin", Password: " leading space", + CreatedAt: time.Date(2025, 6, 1, 0, 0, 0, 1, time.UTC), Store: types.PasswordStoreLocal, + }, + {URL: "android://hash@com.example.app/", Store: types.PasswordStoreLocal}, + }, + Cookies: []types.CookieEntry{ + { + Host: ".tracker.example", Path: "/", Name: "_ga", Value: "GA1.2.1234567890.1700000000", + IsSecure: true, HasExpire: true, IsPersistent: true, + ExpireAt: time.Date(2028, 2, 29, 23, 59, 59, 0, time.UTC), + CreatedAt: time.Date(2025, 5, 5, 5, 5, 5, 123456789, time.UTC), SameSite: "none", + }, + {Host: ".dev.example", Path: "/dev", Name: "multi_line", Value: "line one\nline two, with comma", SameSite: "unspecified"}, + }, + Histories: []types.HistoryEntry{ + { + URL: "https://search.example.com/?q=a%26b&lang=日本語", VisitCount: 1000000, + LastVisit: time.Date(2025, 7, 7, 7, 7, 7, 700000000, time.UTC), + }, + {URL: "about:blank", Title: " leading space", LastVisit: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)}, + }, + Downloads: []types.DownloadEntry{ + { + URL: "https://例え.jp/資料.pdf", TargetPath: "/home/alice/Downloads/資料 📄.pdf", MimeType: "application/pdf", + StartTime: time.Date(2025, 8, 1, 8, 0, 0, 0, time.UTC), + }, + }, + Bookmarks: []types.BookmarkEntry{ + { + ID: 1, Name: `Quote "this", please`, Type: "url", URL: "https://example.org/a,b", Folder: "multi\nline folder", + CreatedAt: time.Date(2025, 3, 3, 3, 3, 3, 0, time.UTC), + }, + }, + CreditCards: []types.CreditCardEntry{ + { + GUID: "00000000-0000-4000-8000-000000000002", Name: "Alice O'Brien", Number: "5555555555554444", + ExpMonth: "1", ExpYear: "2027", CVC: "123", Comment: `note & \ end`, + }, + }, + Extensions: []types.ExtensionEntry{ + {Name: "日本語拡張 🧩", ID: "ponmlkjihgfedcbaponmlkjihgfedcba", Description: "line one\nline two", Version: "0.0.1"}, + }, + LocalStorage: []types.StorageEntry{ + {URL: "https://example.org", Key: "a&b", Value: "multi\nline"}, + }, + SessionStorage: []types.StorageEntry{ + {URL: "https://example.org/?x=1&y=<2>", Key: "draft", Value: `He said "hi", then left \`}, + }, + }}, + {browser: "Microsoft Edge", profile: "Default", data: &types.BrowserData{ + Passwords: []types.LoginEntry{ + { + URL: "https://login.example.org//authorize?client=a&scope=b", Username: `CORP\jdoe`, Password: "日本語パスワード", + CreatedAt: time.Date(2024, 2, 29, 12, 0, 0, 500000000, time.UTC), Store: types.PasswordStoreAccount, + }, + }, + Cookies: []types.CookieEntry{ + { + Host: ".edge.example", Path: "/", Name: "epoch_expiry", Value: `back\slash "quoted" &`, + IsSecure: true, IsHTTPOnly: true, HasExpire: true, IsPersistent: true, + ExpireAt: time.Unix(0, 0).UTC(), CreatedAt: time.Date(2024, 12, 24, 18, 0, 0, 0, time.UTC), + }, + { + Host: "edge.example", Path: "/", Name: "host_only", Value: "v", HasExpire: true, IsPersistent: true, + ExpireAt: time.Date(2026, 12, 31, 23, 59, 59, 999999999, time.UTC), + CreatedAt: time.Date(2024, 6, 15, 9, 30, 0, 0, time.UTC), SameSite: "strict", + }, + }, + Histories: []types.HistoryEntry{ + { + URL: "edge://settings/?a=1&b=2", Title: `C:\Windows\System32`, VisitCount: 7, + LastVisit: time.Date(2024, 7, 4, 0, 0, 0, 500000000, time.UTC), + }, + }, + Downloads: []types.DownloadEntry{ + {URL: "blob:https://app.example/1234", TargetPath: `\\fileserver\share\Q3 summary.csv`, TotalBytes: 4294967296}, + }, + Bookmarks: []types.BookmarkEntry{ + { + ID: 12, Name: `C:\Shares\docs`, Type: "url", URL: "https://edge.example/", Folder: "Favorites bar", + CreatedAt: time.Date(2024, 4, 4, 4, 4, 4, 400000000, time.UTC), + }, + }, + CreditCards: []types.CreditCardEntry{ + {GUID: "00000000-0000-4000-8000-000000000003"}, + }, + Extensions: []types.ExtensionEntry{ + { + Name: "Edge Helper", ID: "aaaabbbbccccddddeeeeffffgggghhhh", Description: `Installed under C:\Program Files\Helper`, + Version: "2.0", HomepageURL: "https://helper.example/", Enabled: true, + }, + }, + LocalStorage: []types.StorageEntry{ + {URL: "https://edge.example", Key: "日本語"}, + }, + SessionStorage: []types.StorageEntry{ + {IsMeta: true, URL: "https://edge.example", Value: "meta data, value bytes is [16 2]"}, + }, + }}, + } +} + +func exportSparseStamps() []exportStamp { + return []exportStamp{ + {browser: "Chrome", profile: "Default", data: &types.BrowserData{ + Passwords: []types.LoginEntry{{URL: "https://example.com/", Username: "alice", Store: types.PasswordStoreLocal}}, + Cookies: []types.CookieEntry{}, + }}, + {browser: "Chrome", profile: "Profile 1"}, + {browser: "Microsoft Edge", profile: "Default", data: &types.BrowserData{ + Histories: []types.HistoryEntry{}, + LocalStorage: []types.StorageEntry{{URL: "https://example.com", Key: "k", Value: "v"}}, + }}, + } +} diff --git a/cmd/hack-browser-data/extract_golden_test.go b/cmd/hack-browser-data/extract_golden_test.go new file mode 100644 index 0000000..ec9a483 --- /dev/null +++ b/cmd/hack-browser-data/extract_golden_test.go @@ -0,0 +1,43 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/moond4rk/hackbrowserdata/types" +) + +func TestExtractGolden(t *testing.T) { + root := t.TempDir() + chromiumFixtureInstallations(t, root) + + tests := []struct { + format string + golden string + jsonFallback bool + }{ + {format: "csv", golden: "extract-csv.golden"}, + {format: "json", golden: "extract-json.golden"}, + {format: "cookie-editor", golden: "extract-cookie-editor.golden", jsonFallback: true}, + } + for _, tt := range tests { + tt := tt + t.Run(tt.format, func(t *testing.T) { + out := extractGoldenRun(t, root, tt.format) + got := bundleDir(t, out) + if tt.jsonFallback { + assertJSONFallback(t, out, extractGoldenRun(t, root, "json")) + got = bundleFiles(t, out, "cookie.json") + } + assertGolden(t, tt.golden, got) + }) + } +} + +func extractGoldenRun(t *testing.T, root, format string) string { + t.Helper() + out := t.TempDir() + require.NoError(t, extractAndWrite(chromiumFixtureBrowsers(t, root), types.AllCategories, out, format, false)) + return out +} diff --git a/cmd/hack-browser-data/flags_test.go b/cmd/hack-browser-data/flags_test.go index 97826c0..043f341 100644 --- a/cmd/hack-browser-data/flags_test.go +++ b/cmd/hack-browser-data/flags_test.go @@ -1,9 +1,6 @@ package main import ( - "flag" - "os" - "path/filepath" "sort" "strconv" "strings" @@ -11,22 +8,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) -var update = flag.Bool("update", false, "rewrite testdata/flags.golden from the current command tree") - func TestFlagSurface(t *testing.T) { - golden := filepath.Join("testdata", "flags.golden") - got := flagSurface(rootCmd()) - if *update { - require.NoError(t, os.MkdirAll(filepath.Dir(golden), 0o755)) - require.NoError(t, os.WriteFile(golden, []byte(got), 0o644)) - } - want, err := os.ReadFile(golden) - require.NoError(t, err) - assert.Equal(t, string(want), got, "regenerate with: go test ./cmd/hack-browser-data -run TestFlagSurface -update") + assertGolden(t, "flags.golden", flagSurface(rootCmd())) } func flagSurface(root *cobra.Command) string { diff --git a/cmd/hack-browser-data/golden_test.go b/cmd/hack-browser-data/golden_test.go new file mode 100644 index 0000000..2555baa --- /dev/null +++ b/cmd/hack-browser-data/golden_test.go @@ -0,0 +1,94 @@ +package main + +import ( + "archive/zip" + "flag" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var update = flag.Bool("update", false, "rewrite the golden files from the current code") + +const goldenDir = "../../testdata" + +func assertGolden(t *testing.T, name, got string) { + t.Helper() + path := filepath.Join(goldenDir, name) + if *update { + require.NoError(t, os.MkdirAll(goldenDir, 0o755)) + require.NoError(t, os.WriteFile(path, []byte(got), 0o644)) + } + want, err := os.ReadFile(path) + require.NoError(t, err) + assert.Equal(t, string(want), got, "regenerate with: go test ./cmd/hack-browser-data -run '%s' -update", t.Name()) +} + +func bundleDir(t *testing.T, dir string) string { + t.Helper() + entries, err := os.ReadDir(dir) + require.NoError(t, err) + names := make([]string, 0, len(entries)) + for _, e := range entries { + require.Truef(t, e.Type().IsRegular(), "unexpected non-regular entry %s in %s", e.Name(), dir) + names = append(names, e.Name()) + } + return bundleFiles(t, dir, names...) +} + +func bundleFiles(t *testing.T, dir string, names ...string) string { + t.Helper() + var b strings.Builder + for _, name := range names { + data, err := os.ReadFile(filepath.Join(dir, name)) + require.NoError(t, err) + fmt.Fprintf(&b, "-- %s (%d bytes) --\n", name, len(data)) + b.Write(data) + if len(data) > 0 && data[len(data)-1] != '\n' { + b.WriteByte('\n') + } + } + return b.String() +} + +func readDirFiles(t *testing.T, dir string) map[string]string { + t.Helper() + entries, err := os.ReadDir(dir) + require.NoError(t, err) + files := make(map[string]string, len(entries)) + for _, e := range entries { + data, err := os.ReadFile(filepath.Join(dir, e.Name())) + require.NoError(t, err) + files[e.Name()] = string(data) + } + return files +} + +// Cookie-Editor's own format covers cookies only; every other category is written exactly as the json format writes it. +func assertJSONFallback(t *testing.T, cookieEditorDir, jsonDir string) { + t.Helper() + got, want := readDirFiles(t, cookieEditorDir), readDirFiles(t, jsonDir) + require.Contains(t, got, "cookie.json") + delete(got, "cookie.json") + delete(want, "cookie.json") + assert.Equal(t, want, got) +} + +func zipListing(t *testing.T, path string) string { + t.Helper() + r, err := zip.OpenReader(path) + require.NoError(t, err) + defer r.Close() + var b strings.Builder + for _, f := range r.File { + fmt.Fprintf(&b, "%s method=%d modified=%s size=%d crc32=%08x\n", + f.Name, f.Method, f.Modified.UTC().Format(time.RFC3339), f.UncompressedSize64, f.CRC32) + } + return b.String() +} diff --git a/cmd/hack-browser-data/keys_golden_test.go b/cmd/hack-browser-data/keys_golden_test.go new file mode 100644 index 0000000..97146db --- /dev/null +++ b/cmd/hack-browser-data/keys_golden_test.go @@ -0,0 +1,256 @@ +package main + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "errors" + "os" + "path/filepath" + "runtime" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/moond4rk/hackbrowserdata/browser" + "github.com/moond4rk/hackbrowserdata/masterkey" + "github.com/moond4rk/hackbrowserdata/types" +) + +var keysGoldenCreatedAt = time.Date(2026, time.May, 16, 8, 30, 15, 123456789, time.UTC) + +var ( + _ browser.Browser = (*keysFakeBrowser)(nil) + _ browser.KeyManager = (*keysFakeChromium)(nil) +) + +type keysFakeBrowser struct { + name, userDataDir string + profiles []string +} + +func (b *keysFakeBrowser) BrowserName() string { return b.name } +func (b *keysFakeBrowser) UserDataDir() string { return b.userDataDir } + +func (b *keysFakeBrowser) Profiles() []types.Profile { + out := make([]types.Profile, 0, len(b.profiles)) + for _, name := range b.profiles { + out = append(out, types.Profile{Name: name, Dir: filepath.Join(b.userDataDir, name)}) + } + return out +} + +func (b *keysFakeBrowser) Extract(_ []types.Category) ([]types.ExtractResult, error) { + return nil, nil +} + +func (b *keysFakeBrowser) CountEntries(_ []types.Category) ([]types.CountResult, error) { + return nil, nil +} + +type keysFakeChromium struct { + keysFakeBrowser + key string + kind types.BrowserKind + keys masterkey.MasterKeys + exportErr error +} + +func (c *keysFakeChromium) SetRetrievers(_ masterkey.Retrievers) {} + +func (c *keysFakeChromium) ExportKeys() (masterkey.MasterKeys, error) { return c.keys, c.exportErr } + +func (c *keysFakeChromium) BrowserKey() string { return c.key } + +func (c *keysFakeChromium) Kind() types.BrowserKind { return c.kind } + +// Strict rejects non-canonical literals, so every key reads in keys.golden exactly as written here. +func keysFakeKey(t *testing.T, b64 string) []byte { + t.Helper() + key, err := base64.StdEncoding.Strict().DecodeString(b64) + require.NoError(t, err) + return key +} + +func keysFakeBrowsers(t *testing.T) []browser.Browser { + t.Helper() + return []browser.Browser{ + &keysFakeChromium{ + keysFakeBrowser: keysFakeBrowser{ + name: "Chrome", + userDataDir: `C:\Users\Jürgen\AppData\Local\Google\Chrome\User Data`, + profiles: []string{"Default", "Profile 1"}, + }, + key: "chrome", + kind: types.Chromium, + keys: masterkey.MasterKeys{ + V10: keysFakeKey(t, "chrome+v10/os+crypt+key/AAAAAAAAAAAAAAAAAAA="), + V20: keysFakeKey(t, "chrome+v20/app+bound+key/AAAAAAAAAAAAAAAAAA="), + }, + }, + &keysFakeBrowser{ + name: "Firefox", + userDataDir: "/home/r&d/.mozilla/firefox", + profiles: []string{"x7k2p9qd.default-release"}, + }, + &keysFakeChromium{ + keysFakeBrowser: keysFakeBrowser{ + name: "Microsoft Edge", + userDataDir: `C:\Users\Jürgen\AppData\Local\Microsoft\Edge\User Data`, + profiles: []string{"Default"}, + }, + key: "edge", + kind: types.Chromium, + keys: masterkey.MasterKeys{ + V10: keysFakeKey(t, "edge+v10/os+crypt+key/AAAAAAAAAAAAAAAAAAAAA="), + V20: keysFakeKey(t, "edge+v20/app+bound+key/AAAAAAAAAAAAAAAAAAAA="), + }, + }, + &keysFakeChromium{ + keysFakeBrowser: keysFakeBrowser{ + name: "Opera", + userDataDir: "/home/r&d/.config/opera", + profiles: []string{"Default"}, + }, + key: "opera", + kind: types.ChromiumOpera, + keys: masterkey.MasterKeys{ + V10: keysFakeKey(t, "opera+v10/peanuts+AAAA=="), + V11: keysFakeKey(t, "opera+v11/keyring+AAAA=="), + }, + }, + &keysFakeChromium{ + keysFakeBrowser: keysFakeBrowser{ + name: "Vivaldi", + userDataDir: `C:\Users\Jürgen\AppData\Local\Vivaldi\User Data`, + profiles: []string{"Default"}, + }, + key: "vivaldi", + kind: types.Chromium, + exportErr: errors.New("v10: DPAPI decrypt failed"), + }, + &keysFakeChromium{ + keysFakeBrowser: keysFakeBrowser{ + name: "Yandex", + userDataDir: "/Users/r&d/Library/Application Support/Yandex/YandexBrowser", + profiles: []string{"Default"}, + }, + key: "yandex", + kind: types.ChromiumYandex, + keys: masterkey.MasterKeys{V10: keysFakeKey(t, "yandex+v10/keychain+AA==")}, + }, + &keysFakeChromium{ + keysFakeBrowser: keysFakeBrowser{ + name: "Brave", + userDataDir: `C:\Users\Jürgen\AppData\Local\BraveSoftware\Brave-Browser\User Data`, + profiles: []string{"Default"}, + }, + key: "brave", + kind: types.Chromium, + keys: masterkey.MasterKeys{V10: keysFakeKey(t, "brave+v10/os+crypt+key/AAAAAAAAAAAAAAAAAAAA=")}, + exportErr: errors.New("v20: elevation service unavailable"), + }, + } +} + +func keysFreeze(t *testing.T, dump masterkey.Dump, host masterkey.Host) masterkey.Dump { + t.Helper() + assert.Equal(t, runtime.GOOS, dump.Host.OS) + assert.Equal(t, runtime.GOARCH, dump.Host.Arch) + assert.Equal(t, time.UTC, dump.CreatedAt.Location()) + assert.WithinDuration(t, time.Now(), dump.CreatedAt, time.Hour) + dump.CreatedAt = keysGoldenCreatedAt + dump.Host = host + return dump +} + +func keysVaultsDump(t *testing.T) masterkey.Dump { + t.Helper() + host := masterkey.Host{OS: "windows", Arch: "amd64", Hostname: "GOLDEN-PC", User: `GOLDEN-PC\Jürgen`} + return keysFreeze(t, browser.BuildDump(keysFakeBrowsers(t)), host) +} + +func keysEmptyDump(t *testing.T) masterkey.Dump { + t.Helper() + return keysFreeze(t, masterkey.NewDump(), masterkey.Host{OS: "linux", Arch: "arm64"}) +} + +func TestKeysGolden(t *testing.T) { + tests := []struct { + name string + golden string + dump func(t *testing.T) masterkey.Dump + }{ + {name: "vaults", golden: "keys.golden", dump: keysVaultsDump}, + {name: "empty", golden: "keys-empty.golden", dump: keysEmptyDump}, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + var buf bytes.Buffer + require.NoError(t, tt.dump(t).WriteJSON(&buf)) + assertGolden(t, tt.golden, buf.String()) + }) + } +} + +func TestKeysRead(t *testing.T) { + tests := []struct { + name string + golden string + edit func(t *testing.T, doc map[string]any) + want func(t *testing.T) masterkey.Dump + wantErr string + }{ + {name: "golden", golden: "keys.golden", want: keysVaultsDump}, + {name: "empty golden", golden: "keys-empty.golden", want: keysEmptyDump}, + {name: "unknown fields", golden: "keys.golden", edit: keysAddUnknownFields, want: keysVaultsDump}, + {name: "older version", golden: "keys.golden", edit: keysSetVersion("1"), wantErr: "unsupported dump version"}, + {name: "newer version", golden: "keys.golden", edit: keysSetVersion("3"), wantErr: "unsupported dump version"}, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + data, err := os.ReadFile(filepath.Join(goldenDir, tt.golden)) + require.NoError(t, err) + if tt.edit != nil { + data = keysEditJSON(t, data, tt.edit) + } + got, err := masterkey.ReadJSON(bytes.NewReader(data)) + if tt.wantErr != "" { + require.ErrorContains(t, err, tt.wantErr) + return + } + require.NoError(t, err) + assert.Equal(t, tt.want(t), got) + }) + } +} + +func keysEditJSON(t *testing.T, data []byte, edit func(t *testing.T, doc map[string]any)) []byte { + t.Helper() + var doc map[string]any + require.NoError(t, json.Unmarshal(data, &doc)) + edit(t, doc) + edited, err := json.Marshal(doc) + require.NoError(t, err) + return edited +} + +func keysAddUnknownFields(t *testing.T, doc map[string]any) { + doc["generator"] = map[string]any{"name": "hack-browser-data", "version": "v9.9.9"} + vaults, ok := doc["vaults"].([]any) + require.True(t, ok) + require.NotEmpty(t, vaults) + for _, v := range vaults { + vault, ok := v.(map[string]any) + require.True(t, ok) + vault["labels"] = []any{"work", "travel"} + } +} + +func keysSetVersion(version string) func(t *testing.T, doc map[string]any) { + return func(_ *testing.T, doc map[string]any) { doc["version"] = version } +} diff --git a/cmd/hack-browser-data/restore_golden_test.go b/cmd/hack-browser-data/restore_golden_test.go new file mode 100644 index 0000000..9462dbb --- /dev/null +++ b/cmd/hack-browser-data/restore_golden_test.go @@ -0,0 +1,113 @@ +package main + +import ( + "bytes" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/moond4rk/hackbrowserdata/browser" + "github.com/moond4rk/hackbrowserdata/masterkey" + "github.com/moond4rk/hackbrowserdata/types" + "github.com/moond4rk/hackbrowserdata/utils/fileutil" +) + +func TestRestoreGolden(t *testing.T) { + data := t.TempDir() + chromiumFixtureInstallations(t, data) + keys := chromiumFixtureKeysFile(t) + want := restoreWantFiles(t, data) + + t.Run("data-dir", func(t *testing.T) { + out := t.TempDir() + chromiumFixtureRestore(t, "--keys", keys, "--data-dir", data, "-d", out) + assert.Equal(t, want, readDirFiles(t, out)) + }) + + t.Run("zip", func(t *testing.T) { + out := filepath.Join(t.TempDir(), "results") + chromiumFixtureRestore(t, "--keys", keys, "--data-dir", data, "-d", out, "--zip") + + entries, err := os.ReadDir(out) + require.NoError(t, err) + require.Len(t, entries, 1) + require.Equal(t, "results.zip", entries[0].Name()) + + archive := filepath.Join(out, "results.zip") + assertGolden(t, "restore-zip.golden", zipListing(t, archive)) + unzipped := t.TempDir() + require.NoError(t, fileutil.Unzip(archive, unzipped)) + assert.Equal(t, want, readDirFiles(t, unzipped)) + }) + + t.Run("data-zip", func(t *testing.T) { + dataZip := filepath.Join(t.TempDir(), "data.zip") + _, err := browser.WriteArchive(chromiumFixtureBrowsers(t, data), types.AllCategories, dataZip) + require.NoError(t, err) + + out := t.TempDir() + chromiumFixtureRestore(t, "--keys", keys, "--data-zip", dataZip, "-d", out) + assert.Equal(t, want, readDirFiles(t, out)) + }) +} + +// Restore has no golden of its own: its output is extract's json output, pinned by extract-json.golden, restamped. +func restoreWantFiles(t *testing.T, data string) map[string]string { + t.Helper() + // Known difference: restore stamps each row with the vault key, extract with the display name. + stamps := make([]string, 0, 2*len(chromiumFixtureInstalls)) + for _, inst := range chromiumFixtureInstalls { + stamps = append(stamps, fmt.Sprintf(`"browser": %q`, inst.name), fmt.Sprintf(`"browser": %q`, inst.key)) + } + toVaultKeys := strings.NewReplacer(stamps...) + + files := readDirFiles(t, extractGoldenRun(t, data, "json")) + for name, content := range files { + restamped := toVaultKeys.Replace(content) + require.NotEqualf(t, content, restamped, "%s carries no display-name stamp to restamp", name) + files[name] = restamped + } + return files +} + +func chromiumFixtureKeysFile(t *testing.T) string { + t.Helper() + profiles := make([]string, 0, len(chromiumFixtureProfiles)) + for _, p := range chromiumFixtureProfiles { + profiles = append(profiles, p.dir) + } + dump := masterkey.Dump{ + // A literal rather than DumpVersion: keys files written by today's dumpkeys must keep restoring. + Version: "2", + CreatedAt: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC), + Host: masterkey.Host{OS: "windows", Arch: "amd64"}, + Vaults: []masterkey.Vault{}, + } + for _, inst := range chromiumFixtureInstalls { + dump.Vaults = append(dump.Vaults, masterkey.Vault{ + Browser: inst.key, + Kind: "chromium", + Profiles: profiles, + Keys: chromiumFixtureKeys, + }) + } + + var buf bytes.Buffer + require.NoError(t, dump.WriteJSON(&buf)) + path := filepath.Join(t.TempDir(), "keys.json") + require.NoError(t, os.WriteFile(path, buf.Bytes(), 0o600)) + return path +} + +func chromiumFixtureRestore(t *testing.T, args ...string) { + t.Helper() + cmd := restoreCmd() + cmd.SetArgs(args) + require.NoError(t, cmd.Execute()) +} diff --git a/rfcs/011-testing-and-quality.md b/rfcs/011-testing-and-quality.md index 19908b4..7066641 100644 --- a/rfcs/011-testing-and-quality.md +++ b/rfcs/011-testing-and-quality.md @@ -31,6 +31,8 @@ These guard the contract; a failure means the rewrite changed something users ca Export and extractor tests compare against checked-in golden outputs. Deterministic ordering is what makes goldens stable — without it, goldens would flap. A `-update` flag regenerates them on intentional changes. Goldens double as documentation of the exact output shape, useful for the README and for talks. +The compatibility goldens — the flag sets, every output format, `keys.json`, and the archive layout — live in the repository-root `testdata/` and are read by the tests in `cmd/hack-browser-data`, the one package that never moves, so every phase compares its output against the same files. A golden holds what no other golden already implies: the Cookie-Editor golden holds only `cookie.json`, because every other category is asserted to match the json output byte for byte, and `restore` is asserted to match the extract output except for its `browser` stamp. + ## Regression tests for the known bugs Each bug designed out by this rewrite gets a test that would have caught it, so it can never silently return: diff --git a/testdata/archive-all.golden b/testdata/archive-all.golden new file mode 100644 index 0000000..d781c3a --- /dev/null +++ b/testdata/archive-all.golden @@ -0,0 +1,31 @@ +entries=20 +chrome/Default/Bookmarks method=8 modified=1979-11-30T00:00:00Z size=17 crc32=b3abdc26 +chrome/Default/History method=8 modified=1979-11-30T00:00:00Z size=15 crc32=3e17b79c +chrome/Default/Local Storage/leveldb/000003.log method=8 modified=1979-11-30T00:00:00Z size=40 crc32=15faa528 +chrome/Default/Local Storage/leveldb/CURRENT method=8 modified=1979-11-30T00:00:00Z size=37 crc32=8f6abec4 +chrome/Default/Local Storage/leveldb/MANIFEST-000001 method=8 modified=1979-11-30T00:00:00Z size=45 crc32=35e1957b +chrome/Default/Login Data method=8 modified=1979-11-30T00:00:00Z size=18 crc32=142b1d76 +chrome/Default/Login Data For Account method=8 modified=1979-11-30T00:00:00Z size=30 crc32=9db5ee07 +chrome/Default/Network/Cookies method=8 modified=1979-11-30T00:00:00Z size=23 crc32=b51bbd79 +chrome/Default/Network/Cookies-shm method=8 modified=1979-11-30T00:00:00Z size=27 crc32=72008c70 +chrome/Default/Network/Cookies-wal method=8 modified=1979-11-30T00:00:00Z size=27 crc32=d3ccaf73 +chrome/Default/Preferences method=8 modified=1979-11-30T00:00:00Z size=19 crc32=b990cd74 +chrome/Default/Secure Preferences method=8 modified=1979-11-30T00:00:00Z size=26 crc32=28329a7f +chrome/Default/Session Storage/000004.log method=8 modified=1979-11-30T00:00:00Z size=34 crc32=cf0c8c20 +chrome/Default/Session Storage/CURRENT method=8 modified=1979-11-30T00:00:00Z size=31 crc32=62eede41 +chrome/Default/Session Storage/MANIFEST-000001 method=8 modified=1979-11-30T00:00:00Z size=39 crc32=f0e90780 +chrome/Default/Web Data method=8 modified=1979-11-30T00:00:00Z size=16 crc32=aaefcc06 +chrome/Local State method=8 modified=1979-11-30T00:00:00Z size=11 crc32=015c5138 +chrome/Profile 1/Bookmarks method=8 modified=1979-11-30T00:00:00Z size=19 crc32=455804cf +chrome/Profile 1/History method=8 modified=1979-11-30T00:00:00Z size=17 crc32=1f0023f8 +chrome/Profile 1/Local Storage/leveldb/000003.log method=8 modified=1979-11-30T00:00:00Z size=42 crc32=56ecc61f +chrome/Profile 1/Local Storage/leveldb/CURRENT method=8 modified=1979-11-30T00:00:00Z size=39 crc32=0a50ecce +chrome/Profile 1/Local Storage/leveldb/MANIFEST-000001 method=8 modified=1979-11-30T00:00:00Z size=47 crc32=cc8c6a04 +chrome/Profile 1/Login Data method=8 modified=1979-11-30T00:00:00Z size=20 crc32=cd0bb472 +chrome/Profile 1/Network/Cookies method=8 modified=1979-11-30T00:00:00Z size=25 crc32=184f7580 +chrome/Profile 1/Preferences method=8 modified=1979-11-30T00:00:00Z size=21 crc32=be2429c4 +chrome/Profile 1/Secure Preferences method=8 modified=1979-11-30T00:00:00Z size=28 crc32=fd021a26 +chrome/Profile 1/Session Storage/000004.log method=8 modified=1979-11-30T00:00:00Z size=36 crc32=481c79bb +chrome/Profile 1/Session Storage/CURRENT method=8 modified=1979-11-30T00:00:00Z size=33 crc32=6290110a +chrome/Profile 1/Session Storage/MANIFEST-000001 method=8 modified=1979-11-30T00:00:00Z size=41 crc32=8f635ae8 +chrome/Profile 1/Web Data method=8 modified=1979-11-30T00:00:00Z size=18 crc32=e0117ed3 diff --git a/testdata/archive-cookie.golden b/testdata/archive-cookie.golden new file mode 100644 index 0000000..fdc4324 --- /dev/null +++ b/testdata/archive-cookie.golden @@ -0,0 +1,8 @@ +entries=5 +chrome/Default/Network/Cookies method=8 modified=1979-11-30T00:00:00Z size=23 crc32=b51bbd79 +chrome/Default/Network/Cookies-shm method=8 modified=1979-11-30T00:00:00Z size=27 crc32=72008c70 +chrome/Default/Network/Cookies-wal method=8 modified=1979-11-30T00:00:00Z size=27 crc32=d3ccaf73 +chrome/Default/Preferences method=8 modified=1979-11-30T00:00:00Z size=19 crc32=b990cd74 +chrome/Local State method=8 modified=1979-11-30T00:00:00Z size=11 crc32=015c5138 +chrome/Profile 1/Network/Cookies method=8 modified=1979-11-30T00:00:00Z size=25 crc32=184f7580 +chrome/Profile 1/Preferences method=8 modified=1979-11-30T00:00:00Z size=21 crc32=be2429c4 diff --git a/testdata/export-cookie-editor.golden b/testdata/export-cookie-editor.golden new file mode 100644 index 0000000..1b686e6 --- /dev/null +++ b/testdata/export-cookie-editor.golden @@ -0,0 +1,72 @@ +-- cookie.json (1568 bytes) -- +[ + { + "domain": ".example.com", + "expirationDate": 1814358896, + "httpOnly": true, + "name": "return_to", + "path": "/", + "secure": true, + "value": "https://shop.example.com/cart?item=42&qty=<3>", + "sameSite": "lax", + "session": false, + "hostOnly": false + }, + { + "domain": "www.example.com", + "httpOnly": true, + "name": "session_id", + "path": "/account", + "secure": false, + "value": "{\"user\":\"日本語 🍪\",\"dir\":\"C:\\Temp\"}", + "sameSite": "strict", + "session": true, + "hostOnly": true + }, + { + "domain": ".tracker.example", + "expirationDate": 1835481599, + "httpOnly": false, + "name": "_ga", + "path": "/", + "secure": true, + "value": "GA1.2.1234567890.1700000000", + "sameSite": "no_restriction", + "session": false, + "hostOnly": false + }, + { + "domain": ".dev.example", + "httpOnly": false, + "name": "multi_line", + "path": "/dev", + "secure": false, + "value": "line one\nline two, with comma", + "sameSite": null, + "session": true, + "hostOnly": false + }, + { + "domain": ".edge.example", + "httpOnly": true, + "name": "epoch_expiry", + "path": "/", + "secure": true, + "value": "back\\slash \"quoted\" &", + "sameSite": null, + "session": true, + "hostOnly": false + }, + { + "domain": "edge.example", + "expirationDate": 1798761599, + "httpOnly": false, + "name": "host_only", + "path": "/", + "secure": false, + "value": "v", + "sameSite": "strict", + "session": false, + "hostOnly": true + } +] diff --git a/testdata/export-csv.golden b/testdata/export-csv.golden new file mode 100644 index 0000000..c339548 --- /dev/null +++ b/testdata/export-csv.golden @@ -0,0 +1,61 @@ +-- bookmark.csv (465 bytes) -- +browser,profile,id,name,type,url,folder,created_at +Chrome,Default,7,Docs & ,url,https://docs.example.com/search?a=1&b=<2>,Bookmarks bar,2026-02-02T02:02:02Z +Chrome,Default,4294967298,日本語 📚,url,https://例え.jp/,Other bookmarks, +Chrome,Profile 1,1,"Quote ""this"", please",url,"https://example.org/a,b","multi +line folder",2025-03-03T03:03:03Z +Microsoft Edge,Default,12,C:\Shares\docs,url,https://edge.example/,Favorites bar,2024-04-04T04:04:04Z +-- cookie.csv (951 bytes) -- +browser,profile,host,path,name,value,is_secure,is_http_only,has_expire,is_persistent,expire_at,created_at,same_site +Chrome,Default,.example.com,/,return_to,https://shop.example.com/cart?item=42&qty=<3>,true,true,true,true,2027-06-30T12:34:56Z,2026-03-14T15:09:27Z,lax +Chrome,Default,www.example.com,/account,session_id,"{""user"":""日本語 🍪"",""dir"":""C:\Temp""}",false,true,false,false,,2026-01-01T00:00:00Z,strict +Chrome,Profile 1,.tracker.example,/,_ga,GA1.2.1234567890.1700000000,true,false,true,true,2028-02-29T23:59:59Z,2025-05-05T05:05:05Z,none +Chrome,Profile 1,.dev.example,/dev,multi_line,"line one +line two, with comma",false,false,false,false,,,unspecified +Microsoft Edge,Default,.edge.example,/,epoch_expiry,"back\slash ""quoted"" &",true,true,true,true,1970-01-01T00:00:00Z,2024-12-24T18:00:00Z, +Microsoft Edge,Default,edge.example,/,host_only,v,false,false,true,true,2026-12-31T23:59:59Z,2024-06-15T09:30:00Z,strict +-- creditcard.csv (421 bytes) -- +browser,profile,guid,name,number,exp_month,exp_year,nick_name,address,cvc,comment +Chrome,Default,00000000-0000-4000-8000-000000000001,山田 太郎,4111111111111111,12,2030,"Work ""primary"", 💳","1-2-3 Chiyoda, +Tokyo 100-0001",, +Chrome,Profile 1,00000000-0000-4000-8000-000000000002,Alice O'Brien,5555555555554444,1,2027,,,123,note & \ end +Microsoft Edge,Default,00000000-0000-4000-8000-000000000003,,,,,,,, +-- download.csv (503 bytes) -- +browser,profile,url,target_path,mime_type,total_bytes,start_time,end_time +Chrome,Default,https://dl.example.com/files/big.iso?token=a&sig=,"C:\Users\Alice\Downloads\Ubuntu ""final"", v2.iso",application/x-iso9660-image,5368709121,2026-03-14T15:00:00Z,2026-03-14T15:30:00Z +Chrome,Profile 1,https://例え.jp/資料.pdf,/home/alice/Downloads/資料 📄.pdf,application/pdf,0,2025-08-01T08:00:00Z, +Microsoft Edge,Default,blob:https://app.example/1234,\\fileserver\share\Q3 summary.csv,,4294967296,, +-- extension.csv (457 bytes) -- +browser,profile,name,id,description,version,homepage_url,enabled +Chrome,Default,Ad Blocker,abcdefghijklmnopabcdefghijklmnop,"Blocks ads & trackers, ""fast"" ",1.58.0,https://adblock.example/?a=1&b=<2>,true +Chrome,Profile 1,日本語拡張 🧩,ponmlkjihgfedcbaponmlkjihgfedcba,"line one +line two",0.0.1,,false +Microsoft Edge,Default,Edge Helper,aaaabbbbccccddddeeeeffffgggghhhh,Installed under C:\Program Files\Helper,2.0,https://helper.example/,true +-- history.csv (508 bytes) -- +browser,profile,url,title,visit_count,last_visit +Chrome,Default,https://shop.example.com/cart?item=42&qty=<3>,"Cart ""deals"" &, 日本語 🛒",42,2026-03-14T15:10:00Z +Chrome,Default,file:///C:/Users/Alice/notes.html,"multi +line title",3, +Chrome,Profile 1,https://search.example.com/?q=a%26b&lang=日本語,,1000000,2025-07-07T07:07:07Z +Chrome,Profile 1,about:blank," leading space",0,2025-01-01T00:00:00Z +Microsoft Edge,Default,edge://settings/?a=1&b=2,C:\Windows\System32,7,2024-07-04T00:00:00Z +-- localstorage.csv (380 bytes) -- +browser,profile,is_meta,url,key,value +Chrome,Default,false,https://app.example.com,prefs,"{""theme"":""dark"",""greeting"":""こんにちは 👋"",""dir"":""C:\Temp""}" +Chrome,Default,true,https://app.example.com,,"meta data, value bytes is [8 128 1]" +Chrome,Profile 1,false,https://example.org,a&b,"multi +line" +Microsoft Edge,Default,false,https://edge.example,日本語, +-- password.csv (630 bytes) -- +browser,profile,url,username,password,created_at,store +Chrome,Default,https://accounts.example.com/signin?continue=/mail&hl=ja,alice@example.com,"pa$$ ""quoted"", comma\backslash +newline",2026-03-14T15:09:26Z,account +Chrome,Default,https://例え.jp/ログイン,日本語ユーザー,🔑 emoji,2025-11-05T06:07:08Z,local +Chrome,Profile 1,http://192.168.0.1:8080/admin,admin," leading space",2025-06-01T00:00:00Z,local +Chrome,Profile 1,android://hash@com.example.app/,,,,local +Microsoft Edge,Default,https://login.example.org//authorize?client=a&scope=b,CORP\jdoe,日本語パスワード,2024-02-29T12:00:00Z,account +-- sessionstorage.csv (271 bytes) -- +browser,profile,is_meta,url,key,value +Chrome,Default,false,https://app.example.com,tab-id,42 +Chrome,Profile 1,false,https://example.org/?x=1&y=<2>,draft,"He said ""hi"", then left \" +Microsoft Edge,Default,true,https://edge.example,,"meta data, value bytes is [16 2]" diff --git a/testdata/export-json.golden b/testdata/export-json.golden new file mode 100644 index 0000000..9f6b951 --- /dev/null +++ b/testdata/export-json.golden @@ -0,0 +1,397 @@ +-- bookmark.json (1020 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "id": 7, + "name": "Docs \u0026 \u003cSpecs\u003e", + "type": "url", + "url": "https://docs.example.com/search?a=1\u0026b=\u003c2\u003e", + "folder": "Bookmarks bar", + "created_at": "2026-02-02T02:02:02.02020202Z" + }, + { + "browser": "Chrome", + "profile": "Default", + "id": 4294967298, + "name": "日本語 📚", + "type": "url", + "url": "https://例え.jp/", + "folder": "Other bookmarks", + "created_at": "0001-01-01T00:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "id": 1, + "name": "Quote \"this\", please", + "type": "url", + "url": "https://example.org/a,b", + "folder": "multi\nline folder", + "created_at": "2025-03-03T03:03:03Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "id": 12, + "name": "C:\\Shares\\docs", + "type": "url", + "url": "https://edge.example/", + "folder": "Favorites bar", + "created_at": "2024-04-04T04:04:04.4Z" + } +] +-- cookie.json (2434 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "host": ".example.com", + "path": "/", + "name": "return_to", + "value": "https://shop.example.com/cart?item=42\u0026qty=\u003c3\u003e", + "is_secure": true, + "is_http_only": true, + "has_expire": true, + "is_persistent": true, + "expire_at": "2027-06-30T12:34:56.789Z", + "created_at": "2026-03-14T15:09:27.1Z", + "same_site": "lax" + }, + { + "browser": "Chrome", + "profile": "Default", + "host": "www.example.com", + "path": "/account", + "name": "session_id", + "value": "{\"user\":\"日本語 🍪\",\"dir\":\"C:\\Temp\"}", + "is_secure": false, + "is_http_only": true, + "has_expire": false, + "is_persistent": false, + "expire_at": "0001-01-01T00:00:00Z", + "created_at": "2026-01-01T00:00:00Z", + "same_site": "strict" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "host": ".tracker.example", + "path": "/", + "name": "_ga", + "value": "GA1.2.1234567890.1700000000", + "is_secure": true, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2028-02-29T23:59:59Z", + "created_at": "2025-05-05T05:05:05.123456789Z", + "same_site": "none" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "host": ".dev.example", + "path": "/dev", + "name": "multi_line", + "value": "line one\nline two, with comma", + "is_secure": false, + "is_http_only": false, + "has_expire": false, + "is_persistent": false, + "expire_at": "0001-01-01T00:00:00Z", + "created_at": "0001-01-01T00:00:00Z", + "same_site": "unspecified" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "host": ".edge.example", + "path": "/", + "name": "epoch_expiry", + "value": "back\\slash \"quoted\" \u003cb\u003e\u0026amp;\u003c/b\u003e", + "is_secure": true, + "is_http_only": true, + "has_expire": true, + "is_persistent": true, + "expire_at": "1970-01-01T00:00:00Z", + "created_at": "2024-12-24T18:00:00Z", + "same_site": "" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "host": "edge.example", + "path": "/", + "name": "host_only", + "value": "v", + "is_secure": false, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2026-12-31T23:59:59.999999999Z", + "created_at": "2024-06-15T09:30:00Z", + "same_site": "strict" + } +] +-- creditcard.json (962 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "guid": "00000000-0000-4000-8000-000000000001", + "name": "山田 太郎", + "number": "4111111111111111", + "exp_month": "12", + "exp_year": "2030", + "nick_name": "Work \"primary\", 💳", + "address": "1-2-3 Chiyoda,\nTokyo 100-0001", + "cvc": "", + "comment": "" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "guid": "00000000-0000-4000-8000-000000000002", + "name": "Alice O'Brien", + "number": "5555555555554444", + "exp_month": "1", + "exp_year": "2027", + "nick_name": "", + "address": "", + "cvc": "123", + "comment": "note \u003cb\u003e\u0026\u003c/b\u003e \\ end" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "guid": "00000000-0000-4000-8000-000000000003", + "name": "", + "number": "", + "exp_month": "", + "exp_year": "", + "nick_name": "", + "address": "", + "cvc": "", + "comment": "" + } +] +-- download.json (996 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "url": "https://dl.example.com/files/big.iso?token=a\u0026sig=\u003cx\u003e", + "target_path": "C:\\Users\\Alice\\Downloads\\Ubuntu \"final\", v2.iso", + "mime_type": "application/x-iso9660-image", + "total_bytes": 5368709121, + "start_time": "2026-03-14T15:00:00.25Z", + "end_time": "2026-03-14T15:30:00.75Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://例え.jp/資料.pdf", + "target_path": "/home/alice/Downloads/資料 📄.pdf", + "mime_type": "application/pdf", + "total_bytes": 0, + "start_time": "2025-08-01T08:00:00Z", + "end_time": "0001-01-01T00:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "blob:https://app.example/1234", + "target_path": "\\\\fileserver\\share\\Q3 summary.csv", + "mime_type": "", + "total_bytes": 4294967296, + "start_time": "0001-01-01T00:00:00Z", + "end_time": "0001-01-01T00:00:00Z" + } +] +-- extension.json (874 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "name": "Ad Blocker", + "id": "abcdefghijklmnopabcdefghijklmnop", + "description": "Blocks ads \u0026 trackers, \"fast\" \u003cb\u003e", + "version": "1.58.0", + "homepage_url": "https://adblock.example/?a=1\u0026b=\u003c2\u003e", + "enabled": true + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "name": "日本語拡張 🧩", + "id": "ponmlkjihgfedcbaponmlkjihgfedcba", + "description": "line one\nline two", + "version": "0.0.1", + "homepage_url": "", + "enabled": false + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "name": "Edge Helper", + "id": "aaaabbbbccccddddeeeeffffgggghhhh", + "description": "Installed under C:\\Program Files\\Helper", + "version": "2.0", + "homepage_url": "https://helper.example/", + "enabled": true + } +] +-- history.json (1112 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "url": "https://shop.example.com/cart?item=42\u0026qty=\u003c3\u003e", + "title": "Cart \"deals\" \u003cb\u003e\u0026\u003c/b\u003e, 日本語 🛒", + "visit_count": 42, + "last_visit": "2026-03-14T15:10:00.000001Z" + }, + { + "browser": "Chrome", + "profile": "Default", + "url": "file:///C:/Users/Alice/notes.html", + "title": "multi\nline title", + "visit_count": 3, + "last_visit": "0001-01-01T00:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://search.example.com/?q=a%26b\u0026lang=日本語", + "title": "", + "visit_count": 1000000, + "last_visit": "2025-07-07T07:07:07.7Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "about:blank", + "title": " leading space", + "visit_count": 0, + "last_visit": "2025-01-01T00:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "edge://settings/?a=1\u0026b=2", + "title": "C:\\Windows\\System32", + "visit_count": 7, + "last_visit": "2024-07-04T00:00:00.5Z" + } +] +-- localstorage.json (769 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://app.example.com", + "key": "prefs", + "value": "{\"theme\":\"dark\",\"greeting\":\"こんにちは 👋\",\"dir\":\"C:\\Temp\"}" + }, + { + "browser": "Chrome", + "profile": "Default", + "is_meta": true, + "url": "https://app.example.com", + "key": "", + "value": "meta data, value bytes is [8 128 1]" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://example.org", + "key": "a\u0026b\u003cc\u003e", + "value": "multi\nline" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": false, + "url": "https://edge.example", + "key": "日本語", + "value": "" + } +] +-- password.json (1301 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "url": "https://accounts.example.com/signin?continue=/mail\u0026hl=ja", + "username": "alice@example.com", + "password": "pa$$ \"quoted\", comma\\backslash\nnewline", + "created_at": "2026-03-14T15:09:26.535897932Z", + "store": "account" + }, + { + "browser": "Chrome", + "profile": "Default", + "url": "https://例え.jp/ログイン", + "username": "日本語ユーザー", + "password": "🔑 emoji", + "created_at": "2025-11-05T06:07:08Z", + "store": "local" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "http://192.168.0.1:8080/admin", + "username": "admin", + "password": " leading space", + "created_at": "2025-06-01T00:00:00.000000001Z", + "store": "local" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "android://hash@com.example.app/", + "username": "", + "password": "", + "created_at": "0001-01-01T00:00:00Z", + "store": "local" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://login.example.org/\u003ctenant\u003e/authorize?client=a\u0026scope=b", + "username": "CORP\\jdoe", + "password": "日本語パスワード", + "created_at": "2024-02-29T12:00:00.5Z", + "store": "account" + } +] +-- sessionstorage.json (557 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://app.example.com", + "key": "tab-id", + "value": "42" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://example.org/?x=1\u0026y=\u003c2\u003e", + "key": "draft", + "value": "He said \"hi\", then left \\" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": true, + "url": "https://edge.example", + "key": "", + "value": "meta data, value bytes is [16 2]" + } +] diff --git a/testdata/export-zip.golden b/testdata/export-zip.golden new file mode 100644 index 0000000..1573b2f --- /dev/null +++ b/testdata/export-zip.golden @@ -0,0 +1,9 @@ +bookmark.csv method=8 modified=1979-11-30T00:00:00Z size=465 crc32=8a226a78 +cookie.csv method=8 modified=1979-11-30T00:00:00Z size=951 crc32=d8142c2c +creditcard.csv method=8 modified=1979-11-30T00:00:00Z size=421 crc32=b70d4fbd +download.csv method=8 modified=1979-11-30T00:00:00Z size=503 crc32=93bf2f68 +extension.csv method=8 modified=1979-11-30T00:00:00Z size=457 crc32=9db54ddb +history.csv method=8 modified=1979-11-30T00:00:00Z size=508 crc32=ca7cbdf4 +localstorage.csv method=8 modified=1979-11-30T00:00:00Z size=380 crc32=e5224819 +password.csv method=8 modified=1979-11-30T00:00:00Z size=630 crc32=057af35e +sessionstorage.csv method=8 modified=1979-11-30T00:00:00Z size=271 crc32=5a8632b3 diff --git a/testdata/extract-cookie-editor.golden b/testdata/extract-cookie-editor.golden new file mode 100644 index 0000000..cd3f0dd --- /dev/null +++ b/testdata/extract-cookie-editor.golden @@ -0,0 +1,191 @@ +-- cookie.json (4019 bytes) -- +[ + { + "domain": "app.home.chrome.test", + "httpOnly": true, + "name": "session", + "path": "/", + "secure": true, + "value": "ephemeral", + "sameSite": null, + "session": true, + "hostOnly": true + }, + { + "domain": ".home.chrome.test", + "expirationDate": 1772355600, + "httpOnly": false, + "name": "tracker", + "path": "/", + "secure": true, + "value": "opt-out", + "sameSite": "no_restriction", + "session": false, + "hostOnly": false + }, + { + "domain": "www.home.chrome.test", + "expirationDate": 1711875600, + "httpOnly": false, + "name": "prefs", + "path": "/settings", + "secure": false, + "value": "theme=dark", + "sameSite": "strict", + "session": false, + "hostOnly": true + }, + { + "domain": ".home.chrome.test", + "expirationDate": 1740819600, + "httpOnly": true, + "name": "SID", + "path": "/", + "secure": true, + "value": "sid-home.chrome.test", + "sameSite": "lax", + "session": false, + "hostOnly": false + }, + { + "domain": "app.work.chrome.test", + "httpOnly": true, + "name": "session", + "path": "/", + "secure": true, + "value": "ephemeral", + "sameSite": null, + "session": true, + "hostOnly": true + }, + { + "domain": ".work.chrome.test", + "expirationDate": 1780304400, + "httpOnly": false, + "name": "tracker", + "path": "/", + "secure": true, + "value": "opt-out", + "sameSite": "no_restriction", + "session": false, + "hostOnly": false + }, + { + "domain": "www.work.chrome.test", + "expirationDate": 1719824400, + "httpOnly": false, + "name": "prefs", + "path": "/settings", + "secure": false, + "value": "theme=dark", + "sameSite": "strict", + "session": false, + "hostOnly": true + }, + { + "domain": ".work.chrome.test", + "expirationDate": 1748768400, + "httpOnly": true, + "name": "SID", + "path": "/", + "secure": true, + "value": "sid-work.chrome.test", + "sameSite": "lax", + "session": false, + "hostOnly": false + }, + { + "domain": "app.home.edge.test", + "httpOnly": true, + "name": "session", + "path": "/", + "secure": true, + "value": "ephemeral", + "sameSite": null, + "session": true, + "hostOnly": true + }, + { + "domain": ".home.edge.test", + "expirationDate": 1772355600, + "httpOnly": false, + "name": "tracker", + "path": "/", + "secure": true, + "value": "opt-out", + "sameSite": "no_restriction", + "session": false, + "hostOnly": false + }, + { + "domain": "www.home.edge.test", + "expirationDate": 1711875600, + "httpOnly": false, + "name": "prefs", + "path": "/settings", + "secure": false, + "value": "theme=dark", + "sameSite": "strict", + "session": false, + "hostOnly": true + }, + { + "domain": ".home.edge.test", + "expirationDate": 1740819600, + "httpOnly": true, + "name": "SID", + "path": "/", + "secure": true, + "value": "sid-home.edge.test", + "sameSite": "lax", + "session": false, + "hostOnly": false + }, + { + "domain": "app.work.edge.test", + "httpOnly": true, + "name": "session", + "path": "/", + "secure": true, + "value": "ephemeral", + "sameSite": null, + "session": true, + "hostOnly": true + }, + { + "domain": ".work.edge.test", + "expirationDate": 1780304400, + "httpOnly": false, + "name": "tracker", + "path": "/", + "secure": true, + "value": "opt-out", + "sameSite": "no_restriction", + "session": false, + "hostOnly": false + }, + { + "domain": "www.work.edge.test", + "expirationDate": 1719824400, + "httpOnly": false, + "name": "prefs", + "path": "/settings", + "secure": false, + "value": "theme=dark", + "sameSite": "strict", + "session": false, + "hostOnly": true + }, + { + "domain": ".work.edge.test", + "expirationDate": 1748768400, + "httpOnly": true, + "name": "SID", + "path": "/", + "secure": true, + "value": "sid-work.edge.test", + "sameSite": "lax", + "session": false, + "hostOnly": false + } +] diff --git a/testdata/extract-csv.golden b/testdata/extract-csv.golden new file mode 100644 index 0000000..1bf1d0b --- /dev/null +++ b/testdata/extract-csv.golden @@ -0,0 +1,128 @@ +-- bookmark.csv (1342 bytes) -- +browser,profile,id,name,type,url,folder,created_at +Chrome,Default,7,Café menu,url,https://shop.home.chrome.test/menu,Other bookmarks,2024-03-01T19:00:00Z +Chrome,Default,6,Long read & tags,url,https://news.home.chrome.test/long-read,Reading,2024-03-01T18:00:00Z +Chrome,Default,4,Docs,url,https://docs.home.chrome.test/,Bookmarks bar,2024-03-01T17:00:00Z +Chrome,Profile 1,7,Café menu,url,https://shop.work.chrome.test/menu,Other bookmarks,2024-06-01T19:00:00Z +Chrome,Profile 1,6,Long read & tags,url,https://news.work.chrome.test/long-read,Reading,2024-06-01T18:00:00Z +Chrome,Profile 1,4,Docs,url,https://docs.work.chrome.test/,Bookmarks bar,2024-06-01T17:00:00Z +Microsoft Edge,Default,7,Café menu,url,https://shop.home.edge.test/menu,Other bookmarks,2024-03-01T19:00:00Z +Microsoft Edge,Default,6,Long read & tags,url,https://news.home.edge.test/long-read,Reading,2024-03-01T18:00:00Z +Microsoft Edge,Default,4,Docs,url,https://docs.home.edge.test/,Bookmarks bar,2024-03-01T17:00:00Z +Microsoft Edge,Profile 1,7,Café menu,url,https://shop.work.edge.test/menu,Other bookmarks,2024-06-01T19:00:00Z +Microsoft Edge,Profile 1,6,Long read & tags,url,https://news.work.edge.test/long-read,Reading,2024-06-01T18:00:00Z +Microsoft Edge,Profile 1,4,Docs,url,https://docs.work.edge.test/,Bookmarks bar,2024-06-01T17:00:00Z +-- cookie.csv (2143 bytes) -- +browser,profile,host,path,name,value,is_secure,is_http_only,has_expire,is_persistent,expire_at,created_at,same_site +Chrome,Default,app.home.chrome.test,/,session,ephemeral,true,true,false,false,,2024-03-01T09:40:00Z,unspecified +Chrome,Default,.home.chrome.test,/,tracker,opt-out,true,false,true,true,2026-03-01T09:00:00Z,2024-03-01T09:30:00Z,none +Chrome,Default,www.home.chrome.test,/settings,prefs,theme=dark,false,false,true,true,2024-03-31T09:00:00Z,2024-03-01T09:20:00Z,strict +Chrome,Default,.home.chrome.test,/,SID,sid-home.chrome.test,true,true,true,true,2025-03-01T09:00:00Z,2024-03-01T09:10:00Z,lax +Chrome,Profile 1,app.work.chrome.test,/,session,ephemeral,true,true,false,false,,2024-06-01T09:40:00Z,unspecified +Chrome,Profile 1,.work.chrome.test,/,tracker,opt-out,true,false,true,true,2026-06-01T09:00:00Z,2024-06-01T09:30:00Z,none +Chrome,Profile 1,www.work.chrome.test,/settings,prefs,theme=dark,false,false,true,true,2024-07-01T09:00:00Z,2024-06-01T09:20:00Z,strict +Chrome,Profile 1,.work.chrome.test,/,SID,sid-work.chrome.test,true,true,true,true,2025-06-01T09:00:00Z,2024-06-01T09:10:00Z,lax +Microsoft Edge,Default,app.home.edge.test,/,session,ephemeral,true,true,false,false,,2024-03-01T09:40:00Z,unspecified +Microsoft Edge,Default,.home.edge.test,/,tracker,opt-out,true,false,true,true,2026-03-01T09:00:00Z,2024-03-01T09:30:00Z,none +Microsoft Edge,Default,www.home.edge.test,/settings,prefs,theme=dark,false,false,true,true,2024-03-31T09:00:00Z,2024-03-01T09:20:00Z,strict +Microsoft Edge,Default,.home.edge.test,/,SID,sid-home.edge.test,true,true,true,true,2025-03-01T09:00:00Z,2024-03-01T09:10:00Z,lax +Microsoft Edge,Profile 1,app.work.edge.test,/,session,ephemeral,true,true,false,false,,2024-06-01T09:40:00Z,unspecified +Microsoft Edge,Profile 1,.work.edge.test,/,tracker,opt-out,true,false,true,true,2026-06-01T09:00:00Z,2024-06-01T09:30:00Z,none +Microsoft Edge,Profile 1,www.work.edge.test,/settings,prefs,theme=dark,false,false,true,true,2024-07-01T09:00:00Z,2024-06-01T09:20:00Z,strict +Microsoft Edge,Profile 1,.work.edge.test,/,SID,sid-work.edge.test,true,true,true,true,2025-06-01T09:00:00Z,2024-06-01T09:10:00Z,lax +-- creditcard.csv (813 bytes) -- +browser,profile,guid,name,number,exp_month,exp_year,nick_name,address,cvc,comment +Chrome,Default,Alice Example-4-2031,Alice Example,4111111111111111,4,2031,Travel,billing-home,, +Chrome,Default,Bob Example-11-2029,Bob Example,5500005555555559,11,2029,,,, +Chrome,Profile 1,Alice Example-4-2031,Alice Example,4111111111111111,4,2031,Travel,billing-home,, +Chrome,Profile 1,Bob Example-11-2029,Bob Example,5500005555555559,11,2029,,,, +Microsoft Edge,Default,Alice Example-4-2031,Alice Example,4111111111111111,4,2031,Travel,billing-home,, +Microsoft Edge,Default,Bob Example-11-2029,Bob Example,5500005555555559,11,2029,,,, +Microsoft Edge,Profile 1,Alice Example-4-2031,Alice Example,4111111111111111,4,2031,Travel,billing-home,, +Microsoft Edge,Profile 1,Bob Example-11-2029,Bob Example,5500005555555559,11,2029,,,, +-- download.csv (1317 bytes) -- +browser,profile,url,target_path,mime_type,total_bytes,start_time,end_time +Chrome,Default,https://files.home.chrome.test/archive.tar.gz,/home/alice/Downloads/archive.tar.gz,application/gzip,1048576,2024-03-01T16:00:00Z, +Chrome,Default,https://files.home.chrome.test/report.pdf,C:\Users\alice\Downloads\report.pdf,application/pdf,52344,2024-03-01T15:00:00Z,2024-03-01T15:00:03Z +Chrome,Profile 1,https://files.work.chrome.test/archive.tar.gz,/home/alice/Downloads/archive.tar.gz,application/gzip,1048576,2024-06-01T16:00:00Z, +Chrome,Profile 1,https://files.work.chrome.test/report.pdf,C:\Users\alice\Downloads\report.pdf,application/pdf,52344,2024-06-01T15:00:00Z,2024-06-01T15:00:03Z +Microsoft Edge,Default,https://files.home.edge.test/archive.tar.gz,/home/alice/Downloads/archive.tar.gz,application/gzip,1048576,2024-03-01T16:00:00Z, +Microsoft Edge,Default,https://files.home.edge.test/report.pdf,C:\Users\alice\Downloads\report.pdf,application/pdf,52344,2024-03-01T15:00:00Z,2024-03-01T15:00:03Z +Microsoft Edge,Profile 1,https://files.work.edge.test/archive.tar.gz,/home/alice/Downloads/archive.tar.gz,application/gzip,1048576,2024-06-01T16:00:00Z, +Microsoft Edge,Profile 1,https://files.work.edge.test/report.pdf,C:\Users\alice\Downloads\report.pdf,application/pdf,52344,2024-06-01T15:00:00Z,2024-06-01T15:00:03Z +-- extension.csv (1372 bytes) -- +browser,profile,name,id,description,version,homepage_url,enabled +Chrome,Default,Tab Organizer,aaaabbbbccccddddeeeeffffgggghhhh,"Groups tabs by site, ""neatly"" & ",2.4.1,https://tabs.example/,true +Chrome,Default,Reader Mode,iiiijjjjkkkkllllmmmmnnnnoooopppp,Distraction-free reading,0.9.0,,false +Chrome,Default,Legacy Unpacked,abcdabcdabcdabcdabcdabcdabcdabcd,,0.1,,true +Chrome,Profile 1,Tab Organizer,aaaabbbbccccddddeeeeffffgggghhhh,"Groups tabs by site, ""neatly"" & ",2.4.1,https://tabs.example/,true +Chrome,Profile 1,Reader Mode,iiiijjjjkkkkllllmmmmnnnnoooopppp,Distraction-free reading,0.9.0,,false +Chrome,Profile 1,Legacy Unpacked,abcdabcdabcdabcdabcdabcdabcdabcd,,0.1,,true +Microsoft Edge,Default,Tab Organizer,aaaabbbbccccddddeeeeffffgggghhhh,"Groups tabs by site, ""neatly"" & ",2.4.1,https://tabs.example/,true +Microsoft Edge,Default,Reader Mode,iiiijjjjkkkkllllmmmmnnnnoooopppp,Distraction-free reading,0.9.0,,false +Microsoft Edge,Default,Legacy Unpacked,abcdabcdabcdabcdabcdabcdabcdabcd,,0.1,,true +Microsoft Edge,Profile 1,Tab Organizer,aaaabbbbccccddddeeeeffffgggghhhh,"Groups tabs by site, ""neatly"" & ",2.4.1,https://tabs.example/,true +Microsoft Edge,Profile 1,Reader Mode,iiiijjjjkkkkllllmmmmnnnnoooopppp,Distraction-free reading,0.9.0,,false +Microsoft Edge,Profile 1,Legacy Unpacked,abcdabcdabcdabcdabcdabcdabcdabcd,,0.1,,true +-- history.csv (1216 bytes) -- +browser,profile,url,title,visit_count,last_visit +Chrome,Default,https://www.home.chrome.test/,Home,42,2024-03-01T12:00:00Z +Chrome,Default,https://docs.home.chrome.test/guide?q=go&lang=en,"Guide, ""quoted"" & bold",7,2024-03-01T13:00:00Z +Chrome,Default,https://news.home.chrome.test/ja,ニュース,3,2024-03-01T14:00:00Z +Chrome,Profile 1,https://www.work.chrome.test/,Home,42,2024-06-01T12:00:00Z +Chrome,Profile 1,https://docs.work.chrome.test/guide?q=go&lang=en,"Guide, ""quoted"" & bold",7,2024-06-01T13:00:00Z +Chrome,Profile 1,https://news.work.chrome.test/ja,ニュース,3,2024-06-01T14:00:00Z +Microsoft Edge,Default,https://www.home.edge.test/,Home,42,2024-03-01T12:00:00Z +Microsoft Edge,Default,https://docs.home.edge.test/guide?q=go&lang=en,"Guide, ""quoted"" & bold",7,2024-03-01T13:00:00Z +Microsoft Edge,Default,https://news.home.edge.test/ja,ニュース,3,2024-03-01T14:00:00Z +Microsoft Edge,Profile 1,https://www.work.edge.test/,Home,42,2024-06-01T12:00:00Z +Microsoft Edge,Profile 1,https://docs.work.edge.test/guide?q=go&lang=en,"Guide, ""quoted"" & bold",7,2024-06-01T13:00:00Z +Microsoft Edge,Profile 1,https://news.work.edge.test/ja,ニュース,3,2024-06-01T14:00:00Z +-- localstorage.csv (1829 bytes) -- +browser,profile,is_meta,url,key,value +Chrome,Default,true,https://app.home.chrome.test,,"meta data, value bytes is [8 150 1]" +Chrome,Default,true,https://app.home.chrome.test,,"meta data, value bytes is [16 32]" +Chrome,Default,false,https://app.home.chrome.test,言語,日本語 +Chrome,Default,false,https://app.home.chrome.test,blob,"value is too long, length is 2101, supported max length is 2048" +Chrome,Default,false,https://app.home.chrome.test,greeting,café +Chrome,Profile 1,true,https://app.work.chrome.test,,"meta data, value bytes is [8 150 1]" +Chrome,Profile 1,true,https://app.work.chrome.test,,"meta data, value bytes is [16 32]" +Chrome,Profile 1,false,https://app.work.chrome.test,言語,日本語 +Chrome,Profile 1,false,https://app.work.chrome.test,blob,"value is too long, length is 2101, supported max length is 2048" +Chrome,Profile 1,false,https://app.work.chrome.test,greeting,café +Microsoft Edge,Default,true,https://app.home.edge.test,,"meta data, value bytes is [8 150 1]" +Microsoft Edge,Default,true,https://app.home.edge.test,,"meta data, value bytes is [16 32]" +Microsoft Edge,Default,false,https://app.home.edge.test,言語,日本語 +Microsoft Edge,Default,false,https://app.home.edge.test,blob,"value is too long, length is 2101, supported max length is 2048" +Microsoft Edge,Default,false,https://app.home.edge.test,greeting,café +Microsoft Edge,Profile 1,true,https://app.work.edge.test,,"meta data, value bytes is [8 150 1]" +Microsoft Edge,Profile 1,true,https://app.work.edge.test,,"meta data, value bytes is [16 32]" +Microsoft Edge,Profile 1,false,https://app.work.edge.test,言語,日本語 +Microsoft Edge,Profile 1,false,https://app.work.edge.test,blob,"value is too long, length is 2101, supported max length is 2048" +Microsoft Edge,Profile 1,false,https://app.work.edge.test,greeting,café +-- password.csv (1170 bytes) -- +browser,profile,url,username,password,created_at,store +Chrome,Default,https://shop.home.chrome.test/,alice@home.chrome.test,"pa,ss""word",2024-03-01T11:00:00Z,local +Chrome,Default,https://sync.home.chrome.test/,alice,synced-secret,2024-03-01T10:30:00Z,account +Chrome,Default,https://accounts.home.chrome.test/,alice,correct-horse-battery-staple,2024-03-01T10:00:00Z,local +Chrome,Profile 1,https://shop.work.chrome.test/,alice@work.chrome.test,"pa,ss""word",2024-06-01T11:00:00Z,local +Chrome,Profile 1,https://accounts.work.chrome.test/,alice,correct-horse-battery-staple,2024-06-01T10:00:00Z,local +Microsoft Edge,Default,https://shop.home.edge.test/,alice@home.edge.test,"pa,ss""word",2024-03-01T11:00:00Z,local +Microsoft Edge,Default,https://sync.home.edge.test/,alice,synced-secret,2024-03-01T10:30:00Z,account +Microsoft Edge,Default,https://accounts.home.edge.test/,alice,correct-horse-battery-staple,2024-03-01T10:00:00Z,local +Microsoft Edge,Profile 1,https://shop.work.edge.test/,alice@work.edge.test,"pa,ss""word",2024-06-01T11:00:00Z,local +Microsoft Edge,Profile 1,https://accounts.work.edge.test/,alice,correct-horse-battery-staple,2024-06-01T10:00:00Z,local +-- sessionstorage.csv (921 bytes) -- +browser,profile,is_meta,url,key,value +Chrome,Default,false,https://app.home.chrome.test/,draft,"Hello, world" +Chrome,Default,false,https://app.home.chrome.test/,scrollY,640 +Chrome,Default,false,https://shop.home.chrome.test/,cart,"{""items"":2}" +Chrome,Profile 1,false,https://app.work.chrome.test/,draft,"Hello, world" +Chrome,Profile 1,false,https://app.work.chrome.test/,scrollY,640 +Chrome,Profile 1,false,https://shop.work.chrome.test/,cart,"{""items"":2}" +Microsoft Edge,Default,false,https://app.home.edge.test/,draft,"Hello, world" +Microsoft Edge,Default,false,https://app.home.edge.test/,scrollY,640 +Microsoft Edge,Default,false,https://shop.home.edge.test/,cart,"{""items"":2}" +Microsoft Edge,Profile 1,false,https://app.work.edge.test/,draft,"Hello, world" +Microsoft Edge,Profile 1,false,https://app.work.edge.test/,scrollY,640 +Microsoft Edge,Profile 1,false,https://shop.work.edge.test/,cart,"{""items"":2}" diff --git a/testdata/extract-json.golden b/testdata/extract-json.golden new file mode 100644 index 0000000..82ec72b --- /dev/null +++ b/testdata/extract-json.golden @@ -0,0 +1,1133 @@ +-- bookmark.json (2995 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "id": 7, + "name": "Café menu", + "type": "url", + "url": "https://shop.home.chrome.test/menu", + "folder": "Other bookmarks", + "created_at": "2024-03-01T19:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Default", + "id": 6, + "name": "Long read \u003cwith\u003e \u0026 tags", + "type": "url", + "url": "https://news.home.chrome.test/long-read", + "folder": "Reading", + "created_at": "2024-03-01T18:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Default", + "id": 4, + "name": "Docs", + "type": "url", + "url": "https://docs.home.chrome.test/", + "folder": "Bookmarks bar", + "created_at": "2024-03-01T17:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "id": 7, + "name": "Café menu", + "type": "url", + "url": "https://shop.work.chrome.test/menu", + "folder": "Other bookmarks", + "created_at": "2024-06-01T19:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "id": 6, + "name": "Long read \u003cwith\u003e \u0026 tags", + "type": "url", + "url": "https://news.work.chrome.test/long-read", + "folder": "Reading", + "created_at": "2024-06-01T18:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "id": 4, + "name": "Docs", + "type": "url", + "url": "https://docs.work.chrome.test/", + "folder": "Bookmarks bar", + "created_at": "2024-06-01T17:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "id": 7, + "name": "Café menu", + "type": "url", + "url": "https://shop.home.edge.test/menu", + "folder": "Other bookmarks", + "created_at": "2024-03-01T19:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "id": 6, + "name": "Long read \u003cwith\u003e \u0026 tags", + "type": "url", + "url": "https://news.home.edge.test/long-read", + "folder": "Reading", + "created_at": "2024-03-01T18:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "id": 4, + "name": "Docs", + "type": "url", + "url": "https://docs.home.edge.test/", + "folder": "Bookmarks bar", + "created_at": "2024-03-01T17:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "id": 7, + "name": "Café menu", + "type": "url", + "url": "https://shop.work.edge.test/menu", + "folder": "Other bookmarks", + "created_at": "2024-06-01T19:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "id": 6, + "name": "Long read \u003cwith\u003e \u0026 tags", + "type": "url", + "url": "https://news.work.edge.test/long-read", + "folder": "Reading", + "created_at": "2024-06-01T18:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "id": 4, + "name": "Docs", + "type": "url", + "url": "https://docs.work.edge.test/", + "folder": "Bookmarks bar", + "created_at": "2024-06-01T17:00:00Z" + } +] +-- cookie.json (6071 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "host": "app.home.chrome.test", + "path": "/", + "name": "session", + "value": "ephemeral", + "is_secure": true, + "is_http_only": true, + "has_expire": false, + "is_persistent": false, + "expire_at": "0001-01-01T00:00:00Z", + "created_at": "2024-03-01T09:40:00Z", + "same_site": "unspecified" + }, + { + "browser": "Chrome", + "profile": "Default", + "host": ".home.chrome.test", + "path": "/", + "name": "tracker", + "value": "opt-out", + "is_secure": true, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2026-03-01T09:00:00Z", + "created_at": "2024-03-01T09:30:00Z", + "same_site": "none" + }, + { + "browser": "Chrome", + "profile": "Default", + "host": "www.home.chrome.test", + "path": "/settings", + "name": "prefs", + "value": "theme=dark", + "is_secure": false, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2024-03-31T09:00:00Z", + "created_at": "2024-03-01T09:20:00Z", + "same_site": "strict" + }, + { + "browser": "Chrome", + "profile": "Default", + "host": ".home.chrome.test", + "path": "/", + "name": "SID", + "value": "sid-home.chrome.test", + "is_secure": true, + "is_http_only": true, + "has_expire": true, + "is_persistent": true, + "expire_at": "2025-03-01T09:00:00Z", + "created_at": "2024-03-01T09:10:00.123456Z", + "same_site": "lax" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "host": "app.work.chrome.test", + "path": "/", + "name": "session", + "value": "ephemeral", + "is_secure": true, + "is_http_only": true, + "has_expire": false, + "is_persistent": false, + "expire_at": "0001-01-01T00:00:00Z", + "created_at": "2024-06-01T09:40:00Z", + "same_site": "unspecified" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "host": ".work.chrome.test", + "path": "/", + "name": "tracker", + "value": "opt-out", + "is_secure": true, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2026-06-01T09:00:00Z", + "created_at": "2024-06-01T09:30:00Z", + "same_site": "none" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "host": "www.work.chrome.test", + "path": "/settings", + "name": "prefs", + "value": "theme=dark", + "is_secure": false, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2024-07-01T09:00:00Z", + "created_at": "2024-06-01T09:20:00Z", + "same_site": "strict" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "host": ".work.chrome.test", + "path": "/", + "name": "SID", + "value": "sid-work.chrome.test", + "is_secure": true, + "is_http_only": true, + "has_expire": true, + "is_persistent": true, + "expire_at": "2025-06-01T09:00:00Z", + "created_at": "2024-06-01T09:10:00.123456Z", + "same_site": "lax" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "host": "app.home.edge.test", + "path": "/", + "name": "session", + "value": "ephemeral", + "is_secure": true, + "is_http_only": true, + "has_expire": false, + "is_persistent": false, + "expire_at": "0001-01-01T00:00:00Z", + "created_at": "2024-03-01T09:40:00Z", + "same_site": "unspecified" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "host": ".home.edge.test", + "path": "/", + "name": "tracker", + "value": "opt-out", + "is_secure": true, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2026-03-01T09:00:00Z", + "created_at": "2024-03-01T09:30:00Z", + "same_site": "none" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "host": "www.home.edge.test", + "path": "/settings", + "name": "prefs", + "value": "theme=dark", + "is_secure": false, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2024-03-31T09:00:00Z", + "created_at": "2024-03-01T09:20:00Z", + "same_site": "strict" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "host": ".home.edge.test", + "path": "/", + "name": "SID", + "value": "sid-home.edge.test", + "is_secure": true, + "is_http_only": true, + "has_expire": true, + "is_persistent": true, + "expire_at": "2025-03-01T09:00:00Z", + "created_at": "2024-03-01T09:10:00.123456Z", + "same_site": "lax" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "host": "app.work.edge.test", + "path": "/", + "name": "session", + "value": "ephemeral", + "is_secure": true, + "is_http_only": true, + "has_expire": false, + "is_persistent": false, + "expire_at": "0001-01-01T00:00:00Z", + "created_at": "2024-06-01T09:40:00Z", + "same_site": "unspecified" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "host": ".work.edge.test", + "path": "/", + "name": "tracker", + "value": "opt-out", + "is_secure": true, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2026-06-01T09:00:00Z", + "created_at": "2024-06-01T09:30:00Z", + "same_site": "none" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "host": "www.work.edge.test", + "path": "/settings", + "name": "prefs", + "value": "theme=dark", + "is_secure": false, + "is_http_only": false, + "has_expire": true, + "is_persistent": true, + "expire_at": "2024-07-01T09:00:00Z", + "created_at": "2024-06-01T09:20:00Z", + "same_site": "strict" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "host": ".work.edge.test", + "path": "/", + "name": "SID", + "value": "sid-work.edge.test", + "is_secure": true, + "is_http_only": true, + "has_expire": true, + "is_persistent": true, + "expire_at": "2025-06-01T09:00:00Z", + "created_at": "2024-06-01T09:10:00.123456Z", + "same_site": "lax" + } +] +-- creditcard.json (2331 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "guid": "Alice Example-4-2031", + "name": "Alice Example", + "number": "4111111111111111", + "exp_month": "4", + "exp_year": "2031", + "nick_name": "Travel", + "address": "billing-home", + "cvc": "", + "comment": "" + }, + { + "browser": "Chrome", + "profile": "Default", + "guid": "Bob Example-11-2029", + "name": "Bob Example", + "number": "5500005555555559", + "exp_month": "11", + "exp_year": "2029", + "nick_name": "", + "address": "", + "cvc": "", + "comment": "" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "guid": "Alice Example-4-2031", + "name": "Alice Example", + "number": "4111111111111111", + "exp_month": "4", + "exp_year": "2031", + "nick_name": "Travel", + "address": "billing-home", + "cvc": "", + "comment": "" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "guid": "Bob Example-11-2029", + "name": "Bob Example", + "number": "5500005555555559", + "exp_month": "11", + "exp_year": "2029", + "nick_name": "", + "address": "", + "cvc": "", + "comment": "" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "guid": "Alice Example-4-2031", + "name": "Alice Example", + "number": "4111111111111111", + "exp_month": "4", + "exp_year": "2031", + "nick_name": "Travel", + "address": "billing-home", + "cvc": "", + "comment": "" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "guid": "Bob Example-11-2029", + "name": "Bob Example", + "number": "5500005555555559", + "exp_month": "11", + "exp_year": "2029", + "nick_name": "", + "address": "", + "cvc": "", + "comment": "" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "guid": "Alice Example-4-2031", + "name": "Alice Example", + "number": "4111111111111111", + "exp_month": "4", + "exp_year": "2031", + "nick_name": "Travel", + "address": "billing-home", + "cvc": "", + "comment": "" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "guid": "Bob Example-11-2029", + "name": "Bob Example", + "number": "5500005555555559", + "exp_month": "11", + "exp_year": "2029", + "nick_name": "", + "address": "", + "cvc": "", + "comment": "" + } +] +-- download.json (2619 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "url": "https://files.home.chrome.test/archive.tar.gz", + "target_path": "/home/alice/Downloads/archive.tar.gz", + "mime_type": "application/gzip", + "total_bytes": 1048576, + "start_time": "2024-03-01T16:00:00Z", + "end_time": "0001-01-01T00:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Default", + "url": "https://files.home.chrome.test/report.pdf", + "target_path": "C:\\Users\\alice\\Downloads\\report.pdf", + "mime_type": "application/pdf", + "total_bytes": 52344, + "start_time": "2024-03-01T15:00:00Z", + "end_time": "2024-03-01T15:00:03Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://files.work.chrome.test/archive.tar.gz", + "target_path": "/home/alice/Downloads/archive.tar.gz", + "mime_type": "application/gzip", + "total_bytes": 1048576, + "start_time": "2024-06-01T16:00:00Z", + "end_time": "0001-01-01T00:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://files.work.chrome.test/report.pdf", + "target_path": "C:\\Users\\alice\\Downloads\\report.pdf", + "mime_type": "application/pdf", + "total_bytes": 52344, + "start_time": "2024-06-01T15:00:00Z", + "end_time": "2024-06-01T15:00:03Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://files.home.edge.test/archive.tar.gz", + "target_path": "/home/alice/Downloads/archive.tar.gz", + "mime_type": "application/gzip", + "total_bytes": 1048576, + "start_time": "2024-03-01T16:00:00Z", + "end_time": "0001-01-01T00:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://files.home.edge.test/report.pdf", + "target_path": "C:\\Users\\alice\\Downloads\\report.pdf", + "mime_type": "application/pdf", + "total_bytes": 52344, + "start_time": "2024-03-01T15:00:00Z", + "end_time": "2024-03-01T15:00:03Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "url": "https://files.work.edge.test/archive.tar.gz", + "target_path": "/home/alice/Downloads/archive.tar.gz", + "mime_type": "application/gzip", + "total_bytes": 1048576, + "start_time": "2024-06-01T16:00:00Z", + "end_time": "0001-01-01T00:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "url": "https://files.work.edge.test/report.pdf", + "target_path": "C:\\Users\\alice\\Downloads\\report.pdf", + "mime_type": "application/pdf", + "total_bytes": 52344, + "start_time": "2024-06-01T15:00:00Z", + "end_time": "2024-06-01T15:00:03Z" + } +] +-- extension.json (3171 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "name": "Tab Organizer", + "id": "aaaabbbbccccddddeeeeffffgggghhhh", + "description": "Groups tabs by site, \"neatly\" \u0026 \u003cfast\u003e", + "version": "2.4.1", + "homepage_url": "https://tabs.example/", + "enabled": true + }, + { + "browser": "Chrome", + "profile": "Default", + "name": "Reader Mode", + "id": "iiiijjjjkkkkllllmmmmnnnnoooopppp", + "description": "Distraction-free reading", + "version": "0.9.0", + "homepage_url": "", + "enabled": false + }, + { + "browser": "Chrome", + "profile": "Default", + "name": "Legacy Unpacked", + "id": "abcdabcdabcdabcdabcdabcdabcdabcd", + "description": "", + "version": "0.1", + "homepage_url": "", + "enabled": true + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "name": "Tab Organizer", + "id": "aaaabbbbccccddddeeeeffffgggghhhh", + "description": "Groups tabs by site, \"neatly\" \u0026 \u003cfast\u003e", + "version": "2.4.1", + "homepage_url": "https://tabs.example/", + "enabled": true + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "name": "Reader Mode", + "id": "iiiijjjjkkkkllllmmmmnnnnoooopppp", + "description": "Distraction-free reading", + "version": "0.9.0", + "homepage_url": "", + "enabled": false + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "name": "Legacy Unpacked", + "id": "abcdabcdabcdabcdabcdabcdabcdabcd", + "description": "", + "version": "0.1", + "homepage_url": "", + "enabled": true + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "name": "Tab Organizer", + "id": "aaaabbbbccccddddeeeeffffgggghhhh", + "description": "Groups tabs by site, \"neatly\" \u0026 \u003cfast\u003e", + "version": "2.4.1", + "homepage_url": "https://tabs.example/", + "enabled": true + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "name": "Reader Mode", + "id": "iiiijjjjkkkkllllmmmmnnnnoooopppp", + "description": "Distraction-free reading", + "version": "0.9.0", + "homepage_url": "", + "enabled": false + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "name": "Legacy Unpacked", + "id": "abcdabcdabcdabcdabcdabcdabcdabcd", + "description": "", + "version": "0.1", + "homepage_url": "", + "enabled": true + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "name": "Tab Organizer", + "id": "aaaabbbbccccddddeeeeffffgggghhhh", + "description": "Groups tabs by site, \"neatly\" \u0026 \u003cfast\u003e", + "version": "2.4.1", + "homepage_url": "https://tabs.example/", + "enabled": true + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "name": "Reader Mode", + "id": "iiiijjjjkkkkllllmmmmnnnnoooopppp", + "description": "Distraction-free reading", + "version": "0.9.0", + "homepage_url": "", + "enabled": false + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "name": "Legacy Unpacked", + "id": "abcdabcdabcdabcdabcdabcdabcdabcd", + "description": "", + "version": "0.1", + "homepage_url": "", + "enabled": true + } +] +-- history.json (2659 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "url": "https://www.home.chrome.test/", + "title": "Home", + "visit_count": 42, + "last_visit": "2024-03-01T12:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Default", + "url": "https://docs.home.chrome.test/guide?q=go\u0026lang=en", + "title": "Guide, \"quoted\" \u0026 \u003cb\u003ebold\u003c/b\u003e", + "visit_count": 7, + "last_visit": "2024-03-01T13:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Default", + "url": "https://news.home.chrome.test/ja", + "title": "ニュース", + "visit_count": 3, + "last_visit": "2024-03-01T14:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://www.work.chrome.test/", + "title": "Home", + "visit_count": 42, + "last_visit": "2024-06-01T12:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://docs.work.chrome.test/guide?q=go\u0026lang=en", + "title": "Guide, \"quoted\" \u0026 \u003cb\u003ebold\u003c/b\u003e", + "visit_count": 7, + "last_visit": "2024-06-01T13:00:00Z" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://news.work.chrome.test/ja", + "title": "ニュース", + "visit_count": 3, + "last_visit": "2024-06-01T14:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://www.home.edge.test/", + "title": "Home", + "visit_count": 42, + "last_visit": "2024-03-01T12:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://docs.home.edge.test/guide?q=go\u0026lang=en", + "title": "Guide, \"quoted\" \u0026 \u003cb\u003ebold\u003c/b\u003e", + "visit_count": 7, + "last_visit": "2024-03-01T13:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://news.home.edge.test/ja", + "title": "ニュース", + "visit_count": 3, + "last_visit": "2024-03-01T14:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "url": "https://www.work.edge.test/", + "title": "Home", + "visit_count": 42, + "last_visit": "2024-06-01T12:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "url": "https://docs.work.edge.test/guide?q=go\u0026lang=en", + "title": "Guide, \"quoted\" \u0026 \u003cb\u003ebold\u003c/b\u003e", + "visit_count": 7, + "last_visit": "2024-06-01T13:00:00Z" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "url": "https://news.work.edge.test/ja", + "title": "ニュース", + "visit_count": 3, + "last_visit": "2024-06-01T14:00:00Z" + } +] +-- localstorage.json (3847 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "is_meta": true, + "url": "https://app.home.chrome.test", + "key": "", + "value": "meta data, value bytes is [8 150 1]" + }, + { + "browser": "Chrome", + "profile": "Default", + "is_meta": true, + "url": "https://app.home.chrome.test", + "key": "", + "value": "meta data, value bytes is [16 32]" + }, + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.chrome.test", + "key": "言語", + "value": "日本語" + }, + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.chrome.test", + "key": "blob", + "value": "value is too long, length is 2101, supported max length is 2048" + }, + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.chrome.test", + "key": "greeting", + "value": "café" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": true, + "url": "https://app.work.chrome.test", + "key": "", + "value": "meta data, value bytes is [8 150 1]" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": true, + "url": "https://app.work.chrome.test", + "key": "", + "value": "meta data, value bytes is [16 32]" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.chrome.test", + "key": "言語", + "value": "日本語" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.chrome.test", + "key": "blob", + "value": "value is too long, length is 2101, supported max length is 2048" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.chrome.test", + "key": "greeting", + "value": "café" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": true, + "url": "https://app.home.edge.test", + "key": "", + "value": "meta data, value bytes is [8 150 1]" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": true, + "url": "https://app.home.edge.test", + "key": "", + "value": "meta data, value bytes is [16 32]" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.edge.test", + "key": "言語", + "value": "日本語" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.edge.test", + "key": "blob", + "value": "value is too long, length is 2101, supported max length is 2048" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.edge.test", + "key": "greeting", + "value": "café" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": true, + "url": "https://app.work.edge.test", + "key": "", + "value": "meta data, value bytes is [8 150 1]" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": true, + "url": "https://app.work.edge.test", + "key": "", + "value": "meta data, value bytes is [16 32]" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.edge.test", + "key": "言語", + "value": "日本語" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.edge.test", + "key": "blob", + "value": "value is too long, length is 2101, supported max length is 2048" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.edge.test", + "key": "greeting", + "value": "café" + } +] +-- password.json (2437 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "url": "https://shop.home.chrome.test/", + "username": "alice@home.chrome.test", + "password": "pa,ss\"word", + "created_at": "2024-03-01T11:00:00Z", + "store": "local" + }, + { + "browser": "Chrome", + "profile": "Default", + "url": "https://sync.home.chrome.test/", + "username": "alice", + "password": "synced-secret", + "created_at": "2024-03-01T10:30:00Z", + "store": "account" + }, + { + "browser": "Chrome", + "profile": "Default", + "url": "https://accounts.home.chrome.test/", + "username": "alice", + "password": "correct-horse-battery-staple", + "created_at": "2024-03-01T10:00:00Z", + "store": "local" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://shop.work.chrome.test/", + "username": "alice@work.chrome.test", + "password": "pa,ss\"word", + "created_at": "2024-06-01T11:00:00Z", + "store": "local" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "url": "https://accounts.work.chrome.test/", + "username": "alice", + "password": "correct-horse-battery-staple", + "created_at": "2024-06-01T10:00:00Z", + "store": "local" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://shop.home.edge.test/", + "username": "alice@home.edge.test", + "password": "pa,ss\"word", + "created_at": "2024-03-01T11:00:00Z", + "store": "local" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://sync.home.edge.test/", + "username": "alice", + "password": "synced-secret", + "created_at": "2024-03-01T10:30:00Z", + "store": "account" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "url": "https://accounts.home.edge.test/", + "username": "alice", + "password": "correct-horse-battery-staple", + "created_at": "2024-03-01T10:00:00Z", + "store": "local" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "url": "https://shop.work.edge.test/", + "username": "alice@work.edge.test", + "password": "pa,ss\"word", + "created_at": "2024-06-01T11:00:00Z", + "store": "local" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "url": "https://accounts.work.edge.test/", + "username": "alice", + "password": "correct-horse-battery-staple", + "created_at": "2024-06-01T10:00:00Z", + "store": "local" + } +] +-- sessionstorage.json (2115 bytes) -- +[ + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.chrome.test/", + "key": "draft", + "value": "Hello, world" + }, + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.chrome.test/", + "key": "scrollY", + "value": "640" + }, + { + "browser": "Chrome", + "profile": "Default", + "is_meta": false, + "url": "https://shop.home.chrome.test/", + "key": "cart", + "value": "{\"items\":2}" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.chrome.test/", + "key": "draft", + "value": "Hello, world" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.chrome.test/", + "key": "scrollY", + "value": "640" + }, + { + "browser": "Chrome", + "profile": "Profile 1", + "is_meta": false, + "url": "https://shop.work.chrome.test/", + "key": "cart", + "value": "{\"items\":2}" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.edge.test/", + "key": "draft", + "value": "Hello, world" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": false, + "url": "https://app.home.edge.test/", + "key": "scrollY", + "value": "640" + }, + { + "browser": "Microsoft Edge", + "profile": "Default", + "is_meta": false, + "url": "https://shop.home.edge.test/", + "key": "cart", + "value": "{\"items\":2}" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.edge.test/", + "key": "draft", + "value": "Hello, world" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": false, + "url": "https://app.work.edge.test/", + "key": "scrollY", + "value": "640" + }, + { + "browser": "Microsoft Edge", + "profile": "Profile 1", + "is_meta": false, + "url": "https://shop.work.edge.test/", + "key": "cart", + "value": "{\"items\":2}" + } +] diff --git a/cmd/hack-browser-data/testdata/flags.golden b/testdata/flags.golden similarity index 100% rename from cmd/hack-browser-data/testdata/flags.golden rename to testdata/flags.golden diff --git a/testdata/keys-empty.golden b/testdata/keys-empty.golden new file mode 100644 index 0000000..6847a36 --- /dev/null +++ b/testdata/keys-empty.golden @@ -0,0 +1,9 @@ +{ + "version": "2", + "created_at": "2026-05-16T08:30:15.123456789Z", + "host": { + "os": "linux", + "arch": "arm64" + }, + "vaults": [] +} diff --git a/testdata/keys.golden b/testdata/keys.golden new file mode 100644 index 0000000..2ed96c9 --- /dev/null +++ b/testdata/keys.golden @@ -0,0 +1,71 @@ +{ + "version": "2", + "created_at": "2026-05-16T08:30:15.123456789Z", + "host": { + "os": "windows", + "arch": "amd64", + "hostname": "GOLDEN-PC", + "user": "GOLDEN-PC\\Jürgen" + }, + "vaults": [ + { + "browser": "chrome", + "kind": "chromium", + "user_data_dir": "C:\\Users\\Jürgen\\AppData\\Local\\Google\\Chrome\\User Data", + "profiles": [ + "Default", + "Profile 1" + ], + "keys": { + "v10": "chrome+v10/os+crypt+key/AAAAAAAAAAAAAAAAAAA=", + "v20": "chrome+v20/app+bound+key/AAAAAAAAAAAAAAAAAA=" + } + }, + { + "browser": "edge", + "kind": "chromium", + "user_data_dir": "C:\\Users\\Jürgen\\AppData\\Local\\Microsoft\\Edge\\User Data", + "profiles": [ + "Default" + ], + "keys": { + "v10": "edge+v10/os+crypt+key/AAAAAAAAAAAAAAAAAAAAA=", + "v20": "edge+v20/app+bound+key/AAAAAAAAAAAAAAAAAAAA=" + } + }, + { + "browser": "opera", + "kind": "chromium-opera", + "user_data_dir": "/home/r\u0026d/.config/opera", + "profiles": [ + "Default" + ], + "keys": { + "v10": "opera+v10/peanuts+AAAA==", + "v11": "opera+v11/keyring+AAAA==" + } + }, + { + "browser": "yandex", + "kind": "chromium-yandex", + "user_data_dir": "/Users/r\u0026d/Library/Application Support/Yandex/YandexBrowser", + "profiles": [ + "Default" + ], + "keys": { + "v10": "yandex+v10/keychain+AA==" + } + }, + { + "browser": "brave", + "kind": "chromium", + "user_data_dir": "C:\\Users\\Jürgen\\AppData\\Local\\BraveSoftware\\Brave-Browser\\User Data", + "profiles": [ + "Default" + ], + "keys": { + "v10": "brave+v10/os+crypt+key/AAAAAAAAAAAAAAAAAAAA=" + } + } + ] +} diff --git a/testdata/restore-zip.golden b/testdata/restore-zip.golden new file mode 100644 index 0000000..bc8ed45 --- /dev/null +++ b/testdata/restore-zip.golden @@ -0,0 +1,9 @@ +bookmark.json method=8 modified=1979-11-30T00:00:00Z size=2935 crc32=70093b8f +cookie.json method=8 modified=1979-11-30T00:00:00Z size=5991 crc32=f581d667 +creditcard.json method=8 modified=1979-11-30T00:00:00Z size=2291 crc32=0634e639 +download.json method=8 modified=1979-11-30T00:00:00Z size=2579 crc32=0e521921 +extension.json method=8 modified=1979-11-30T00:00:00Z size=3111 crc32=d265da9a +history.json method=8 modified=1979-11-30T00:00:00Z size=2599 crc32=464a4210 +localstorage.json method=8 modified=1979-11-30T00:00:00Z size=3747 crc32=ce3d609a +password.json method=8 modified=1979-11-30T00:00:00Z size=2387 crc32=fb1c57e1 +sessionstorage.json method=8 modified=1979-11-30T00:00:00Z size=2055 crc32=5e06c08c