mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
* refactor: stream records through sqlitex and the collector A row that failed to scan was logged at debug and dropped, so it never counted toward partial; it now reaches Collector.Fail. Every SQLite open goes through sqlitex with options instead of a bool, and extractors add records as they read them. * refactor: read SQLite rows with plain loops EachRow hid each extractor's loop and its skip rule behind two callbacks; every extractor now opens, queries, and walks its own rows, so the control flow reads top to bottom. * refactor(browser): drop the memoizing key closures Firefox derives its key once before the login loop, and Yandex loads its data key at the first row, so the state sits in plain variables where the loop uses it instead of inside a closure. * fix(safari): report unreadable localStorage origins A broken origin, database or row was only logged at debug level, so it never counted toward a partial result.
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package sqlitex
|
|
|
|
import (
|
|
"database/sql"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func createDB(t *testing.T, statements ...string) string {
|
|
t.Helper()
|
|
path := filepath.Join(t.TempDir(), "test.db")
|
|
database, err := sql.Open("sqlite", path)
|
|
require.NoError(t, err)
|
|
for _, statement := range statements {
|
|
_, err := database.Exec(statement)
|
|
require.NoError(t, err, statement)
|
|
}
|
|
require.NoError(t, database.Close())
|
|
return path
|
|
}
|
|
|
|
func readValue(t *testing.T, path string, options ...Option) string {
|
|
t.Helper()
|
|
database, err := Open(path, options...)
|
|
require.NoError(t, err)
|
|
defer database.Close()
|
|
|
|
var value string
|
|
require.NoError(t, database.QueryRow("SELECT v FROM t").Scan(&value))
|
|
return value
|
|
}
|
|
|
|
func TestOpen(t *testing.T) {
|
|
path := createDB(t, "CREATE TABLE t (v TEXT)", "INSERT INTO t VALUES ('x')")
|
|
assert.Equal(t, "x", readValue(t, path))
|
|
}
|
|
|
|
func TestOpen_JournalOff(t *testing.T) {
|
|
path := createDB(t, "CREATE TABLE t (v TEXT)", "INSERT INTO t VALUES ('x')")
|
|
assert.Equal(t, "x", readValue(t, path, JournalOff))
|
|
}
|
|
|
|
func TestOpen_ReadOnlyImmutable(t *testing.T) {
|
|
path := createDB(t, "CREATE TABLE t (v TEXT)", "INSERT INTO t VALUES ('x')")
|
|
assert.Equal(t, "x", readValue(t, path, ReadOnly, Immutable))
|
|
}
|
|
|
|
func TestOpen_ReadOnlyRejectsWrites(t *testing.T) {
|
|
path := createDB(t, "CREATE TABLE t (v TEXT)")
|
|
database, err := Open(path, ReadOnly)
|
|
require.NoError(t, err)
|
|
defer database.Close()
|
|
|
|
_, err = database.Exec("INSERT INTO t VALUES ('x')")
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestOpen_MissingFileCreatesNothing(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "missing.db")
|
|
_, err := Open(path)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "database file")
|
|
assert.NoFileExists(t, path)
|
|
}
|