mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
b3dd4ed6e4
* feat: add Chromium extract methods, source mapping, and tests Implement per-category data extraction for Chromium browsers as typed standalone functions, preparing for Phase 8 wiring into the new Chromium struct. New files: - source.go: dataSource struct, chromiumSources/yandexSources maps, yandexQueryOverrides for Yandex action_url variant - decrypt.go: decryptValue() wrapping platform-specific decryption - extract_password.go: SQLite + decrypt → []LoginEntry - extract_cookie.go: SQLite + decrypt → []CookieEntry - extract_creditcard.go: SQLite + decrypt → []CreditCardEntry - extract_history.go: SQLite → []HistoryEntry - extract_download.go: SQLite → []DownloadEntry - extract_bookmark.go: JSON recursive → []BookmarkEntry - extract_extension.go: JSON → []ExtensionEntry - extract_storage.go: LevelDB → []StorageEntry (local + session) - firefox/source.go: firefoxSources map Tests use real Chrome table schemas for SQLite fixtures, with INSERT helpers to keep test data readable and self-documenting. Ref #520 * fix: remove LevelDB invalid path test (Windows compatibility) leveldb.OpenFile creates the directory on Windows instead of returning an error, causing TestExtractLocalStorage_InvalidPath to fail in CI. This test was verifying LevelDB behavior, not our extraction logic. * refactor: remove unused query parameter from extract functions Only extractPasswords needs the query override (Yandex action_url). The other 7 SQLite extract functions always use their default query, so remove the unnecessary query parameter from their signatures. * refactor: use DetectVersion in decryptValue instead of blind fallback Replace try-then-fallback pattern with explicit version detection using crypto.DetectVersion. Routes v10 to DecryptWithChromium, DPAPI to DecryptWithDPAPI, and adds a TODO placeholder for v20 App-Bound Encryption. * chore: relax gocognit and gocritic linters for test files * revert: restore strict gocognit and gocritic linters for test files * fix: address review feedback on extract methods - Store DetectVersion result in local variable to avoid duplicate call - Scan credit card expiration_month/year as int then convert to string (matches INTEGER column type in real Chrome schema) - Add os.Stat check before leveldb.OpenFile to prevent creating empty directories for non-existent paths - Rename TestExtractExtensions_InvalidJSON to TestExtractExtensions_MissingSettingsPath (JSON is valid, path is missing) * fix: revert creditcard scan to string type for NULL safety modernc.org/sqlite handles INTEGER→string conversion automatically. Scanning into string is safer for nullable columns — NULL becomes "" instead of "0" which would be an invalid month/year.
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package chromium
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExtractExtensions(t *testing.T) {
|
|
path := createTestJSON(t, "Secure Preferences", `{
|
|
"extensions": {
|
|
"settings": {
|
|
"abc123": {
|
|
"location": 1,
|
|
"manifest": {
|
|
"name": "React DevTools",
|
|
"description": "React debugging",
|
|
"version": "4.28.0"
|
|
}
|
|
},
|
|
"system-ext": {
|
|
"location": 5,
|
|
"manifest": {"name": "System", "version": "1.0"}
|
|
},
|
|
"component-ext": {
|
|
"location": 10,
|
|
"manifest": {"name": "Component", "version": "1.0"}
|
|
},
|
|
"def456": {
|
|
"location": 1,
|
|
"manifest": {
|
|
"name": "uBlock Origin",
|
|
"description": "Ad blocker",
|
|
"version": "1.52.0"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`)
|
|
|
|
got, err := extractExtensions(path)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 2) // system (location=5) and component (location=10) skipped
|
|
|
|
// Verify field mapping (order may vary since gjson.ForEach iterates map)
|
|
ids := map[string]bool{}
|
|
for _, ext := range got {
|
|
ids[ext.ID] = true
|
|
assert.NotEmpty(t, ext.Name)
|
|
assert.NotEmpty(t, ext.Version)
|
|
assert.NotEmpty(t, ext.Description)
|
|
}
|
|
assert.True(t, ids["abc123"])
|
|
assert.True(t, ids["def456"])
|
|
assert.False(t, ids["system-ext"])
|
|
}
|
|
|
|
func TestExtractExtensions_NoManifestSkipped(t *testing.T) {
|
|
path := createTestJSON(t, "Secure Preferences", `{
|
|
"extensions": {
|
|
"settings": {
|
|
"no-manifest": {"location": 1}
|
|
}
|
|
}
|
|
}`)
|
|
|
|
got, err := extractExtensions(path)
|
|
require.NoError(t, err)
|
|
assert.Empty(t, got)
|
|
}
|
|
|
|
func TestExtractExtensions_MissingSettingsPath(t *testing.T) {
|
|
path := createTestJSON(t, "Secure Preferences", `{"something": "else"}`)
|
|
_, err := extractExtensions(path)
|
|
require.Error(t, err)
|
|
}
|