Files
HackBrowserData/internal/browser/firefox/extract_extension_test.go
T
Roger 2093045664 refactor: add the Firefox base under internal/browser (#659)
Parsers move with git mv and hand records to a Collector; the old browser/firefox
runs them, and app now discovers Firefox. A profile without a usable key exports
its logins instead of panicking, as RFC-008 now lists.
2026-10-28 15:06:07 +08:00

74 lines
1.7 KiB
Go

package firefox
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/internal/record"
)
func setupMozExtensionJSON(t *testing.T) string {
t.Helper()
return createTestJSON(t, "extensions.json", `{
"addons": [
{
"id": "ublock@gorhill.org",
"location": "app-profile",
"version": "1.52.0",
"active": true,
"defaultLocale": {
"name": "uBlock Origin",
"description": "An efficient blocker"
}
},
{
"id": "system@mozilla.org",
"location": "app-system-defaults",
"version": "1.0",
"defaultLocale": {"name": "System Addon"}
},
{
"id": "bitwarden@bitwarden.com",
"location": "app-profile",
"version": "2024.1.0",
"active": true,
"defaultLocale": {
"name": "Bitwarden",
"description": "Password manager"
}
}
]
}`)
}
func TestExtractExtensions(t *testing.T) {
path := setupMozExtensionJSON(t)
var out testCollector
err := extractExtensions(path, &out)
got := collected[record.Extension](t, &out)
require.NoError(t, err)
require.Len(t, got, 2) // system addon filtered out
ids := map[string]bool{}
for _, ext := range got {
ids[ext.ID] = true
assert.NotEmpty(t, ext.Name)
assert.NotEmpty(t, ext.Version)
}
assert.True(t, ids["ublock@gorhill.org"])
assert.True(t, ids["bitwarden@bitwarden.com"])
assert.False(t, ids["system@mozilla.org"])
}
func TestExtractExtensions_EmptyAddons(t *testing.T) {
path := createTestJSON(t, "extensions.json", `{"addons": []}`)
var out testCollector
err := extractExtensions(path, &out)
got := collected[record.Extension](t, &out)
require.NoError(t, err)
assert.Empty(t, got)
}