mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: run Chromium through the internal/app pipeline (#656)
Validate, Discover, NewPlan, Execute, and Report run beside today's path: one snapshot per user data dir, each dir's keys retrieved once on first use, every record stamped by the collector. On the Chromium fixtures it writes the extract goldens byte for byte; the CLI switches over later.
This commit is contained in:
1 parent
322c41d187
commit
2b70e4ad65
15 files changed
+1122
-1
No files matched your search
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"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
|
||||
}
|
||||
|
||||
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 := pipelineGoldenRun(t, home, keys, tt.format)
|
||||
got := bundleDir(t, out)
|
||||
if tt.jsonFallback {
|
||||
assertJSONFallback(t, out, pipelineGoldenRun(t, home, keys, "json"))
|
||||
got = bundleFiles(t, out, "cookie.json")
|
||||
}
|
||||
assertGolden(t, tt.golden, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user