Files
HackBrowserData/browser/firefox/extract_history_test.go
T
Roger 1ec2781131 feat: add Firefox extract methods and complete data model fields (#527)
* feat: add Firefox extract methods and complete data model fields

Firefox extract methods:
- extractPasswords: JSON + ASN1PBE decryption via decryptPBE helper
- extractCookies: SQLite, plaintext (no encryption), journalOff
- extractHistories: SQLite, visit count ASC sort (matches old behavior)
- extractDownloads: SQLite, moz_annos JOIN with JSON content parsing
- extractBookmarks: SQLite, moz_bookmarks JOIN moz_places
- extractExtensions: JSON, filter by location=app-profile
- extractLocalStorage: SQLite webappsstore2, reversed originKey parsing

Complete data model fields (union of Chromium and Firefox):
- CookieEntry: add HasExpire, IsPersistent
- DownloadEntry: add MimeType
- CreditCardEntry: add NickName, Address
- ExtensionEntry: add HomepageURL, Enabled

Update Chromium extractors to populate new fields:
- extract_cookie.go: fill HasExpire, IsPersistent
- extract_download.go: SELECT and fill mime_type
- extract_creditcard.go: SELECT nickname, billing_address_id
- extract_extension.go: fill HomepageURL, Enabled (state==1)

Tests:
- Full test coverage for all 7 Firefox extract functions
- Password test uses known ASN1PBE test vectors from crypto package
- Table-driven tests for parseOriginKey
- Updated Chromium tests for new fields

* fix: add COALESCE for nullable bookmark title in Firefox query

Firefox moz_bookmarks.title can be NULL (PR #500 fixed this in old code).
Add COALESCE to handle NULL gracefully in SQL instead of relying on
driver-specific NULL→string conversion behavior.

* fix: enable journalOff for all Firefox SQLite extractors and populate cookie flags

- Set journalOff=true for extract_history, extract_download, extract_bookmark
  (Firefox databases require PRAGMA journal_mode=off to avoid lock errors)
- Populate HasExpire and IsPersistent for Firefox cookies (derived from expiry>0)
- Add test assertions for HasExpire/IsPersistent in both Chromium and Firefox
2026-04-04 01:41:02 +08:00

45 lines
1.4 KiB
Go

package firefox
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestExtractHistories(t *testing.T) {
path := createTestDB(t, "places.sqlite", []string{mozPlacesSchema},
insertMozPlace(1, "https://github.com", "GitHub", 100, 1700000000000000),
insertMozPlace(2, "https://go.dev", "Go", 50, 1710000000000000),
insertMozPlace(3, "https://example.com", "Example", 200, 1690000000000000),
)
got, err := extractHistories(path)
require.NoError(t, err)
require.Len(t, got, 3)
// Verify sort order: visit count ascending (Firefox convention)
assert.Equal(t, 50, got[0].VisitCount)
assert.Equal(t, 100, got[1].VisitCount)
assert.Equal(t, 200, got[2].VisitCount)
// Verify field mapping (first = least visited)
assert.Equal(t, "https://go.dev", got[0].URL)
assert.Equal(t, "Go", got[0].Title)
assert.False(t, got[0].LastVisit.IsZero())
}
func TestExtractHistories_NullFields(t *testing.T) {
path := createTestDB(t, "places.sqlite", []string{mozPlacesSchema},
// last_visit_date=NULL, title=NULL — COALESCE should handle
`INSERT INTO moz_places (id, url, visit_count, rev_host, guid, url_hash)
VALUES (1, 'https://null.test', 1, '', 'g1', 0)`,
)
got, err := extractHistories(path)
require.NoError(t, err)
require.Len(t, got, 1)
assert.Equal(t, "https://null.test", got[0].URL)
assert.Equal(t, "", got[0].Title)
}