Files
HackBrowserData/cmd/hack-browser-data/pipeline_golden_test.go
T
Roger 4add07e825 refactor: add the Safari base under internal/browser (#660)
Parsers move with git mv and hand records to a Collector; discovery reads a copy
of SafariTabs.db, and app hands the run's login keychain to the default profile's
password extractor. The old browser/safari runs the new extractors.
2026-10-28 15:51:15 +08:00

69 lines
2.2 KiB
Go

package main
import (
"context"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/internal/app"
ibrowser "github.com/moond4rk/hackbrowserdata/internal/browser"
"github.com/moond4rk/hackbrowserdata/internal/masterkey"
)
// Until the switch-over the pipeline runs beside today's extract path: on the same fixtures it must write the same
// goldens byte for byte.
func TestPipelineGolden(t *testing.T) {
home := t.TempDir()
keys := make(map[ibrowser.DirID]masterkey.Set)
for _, inst := range chromiumFixtureInstalls {
def, ok := ibrowser.Lookup(inst.key)
require.True(t, ok, inst.key)
require.Equal(t, inst.name, def.Name, "records are stamped with the table's display name")
chromiumFixtureUserData(t, filepath.Join(home, filepath.FromSlash(def.Platform().UserDataDirs[0])), inst.key)
keys[ibrowser.DirID(inst.key)] = chromiumFixtureKeys
}
assertExtractGoldens(t, "extract", func(t *testing.T, format string) string {
return pipelineGoldenRun(t, home, keys, format)
})
}
func TestPipelineGoldenFirefox(t *testing.T) {
home := t.TempDir()
def, ok := ibrowser.Lookup("firefox")
require.True(t, ok)
firefoxFixtureUserData(t, filepath.Join(home, filepath.FromSlash(def.Platform().UserDataDirs[0])))
assertExtractGoldens(t, "extract-firefox", func(t *testing.T, format string) string {
return pipelineGoldenRun(t, home, nil, format)
})
}
func TestPipelineGoldenSafari(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("Safari is in the browser table on macOS only")
}
home := t.TempDir()
safariFixtureLibrary(t, filepath.Join(home, "Library"))
assertExtractGoldens(t, "extract-safari", func(t *testing.T, format string) string {
return pipelineGoldenRun(t, home, nil, format)
})
}
func pipelineGoldenRun(t *testing.T, home string, keys map[ibrowser.DirID]masterkey.Set, format string) string {
t.Helper()
out := t.TempDir()
req, err := app.Validate(app.Flags{Browser: "all", Categories: "all", Format: format, Dir: out})
require.NoError(t, err)
req.Home, req.Keys = home, keys
plan := app.NewPlan(app.Discover(req), req)
_, err = app.Execute(context.Background(), plan, req)
require.NoError(t, err)
return out
}