mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Def, Request, DirID, and Source said too little, and short variables and doc comments that skip their name hid intent. varnamelen and staticcheck ST1020-22 now keep both from coming back.
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package firefox
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
)
|
|
|
|
func setupWebappsDB(t *testing.T) string {
|
|
t.Helper()
|
|
return createTestDB(t, "webappsstore.sqlite", []string{webappsstore2Schema},
|
|
insertWebappsstore("moc.buhtig.:https:443", "theme", "dark"),
|
|
insertWebappsstore("moc.buhtig.:https:443", "lang", "en"),
|
|
insertWebappsstore("moc.elpmaxe.:http:8080", "token", "abc123"),
|
|
)
|
|
}
|
|
|
|
func TestExtractLocalStorage(t *testing.T) {
|
|
path := setupWebappsDB(t)
|
|
|
|
var out testCollector
|
|
err := extractLocalStorage(path, &out)
|
|
got := collected[record.LocalStorage](t, &out)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 3)
|
|
|
|
byKey := map[string]string{}
|
|
for _, entry := range got {
|
|
byKey[entry.URL+"/"+entry.Key] = entry.Value
|
|
}
|
|
assert.Equal(t, "dark", byKey["https://github.com:443/theme"])
|
|
assert.Equal(t, "en", byKey["https://github.com:443/lang"])
|
|
assert.Equal(t, "abc123", byKey["http://example.com:8080/token"])
|
|
}
|
|
|
|
func TestParseOriginKey(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
originKey string
|
|
want string
|
|
}{
|
|
{
|
|
name: "https with port",
|
|
originKey: "moc.buhtig.:https:443",
|
|
want: "https://github.com:443",
|
|
},
|
|
{
|
|
name: "http with non-standard port",
|
|
originKey: "moc.elpmaxe.:http:8080",
|
|
want: "http://example.com:8080",
|
|
},
|
|
{
|
|
name: "no port",
|
|
originKey: "moc.elpmaxe.:https",
|
|
want: "https://example.com",
|
|
},
|
|
{
|
|
name: "invalid format",
|
|
originKey: "something",
|
|
want: "something",
|
|
},
|
|
}
|
|
|
|
for _, testCase := range tests {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
got := parseOriginKey(testCase.originKey)
|
|
assert.Equal(t, testCase.want, got)
|
|
})
|
|
}
|
|
}
|