mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
chore: update golangci-lint config and fix lint issues (#542)
* chore: update golangci-lint config and fix lint issues
This commit is contained in:
+15
-5
@@ -7,17 +7,27 @@ import (
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
type cookieEditorFormatter struct{}
|
||||
// cookieEditorFormatter outputs cookies in the CookieEditor browser extension
|
||||
// format. Non-cookie categories fall back to standard JSON output.
|
||||
type cookieEditorFormatter struct {
|
||||
fallback *jsonFormatter
|
||||
}
|
||||
|
||||
func (f *cookieEditorFormatter) ext() string { return "json" }
|
||||
|
||||
func (f *cookieEditorFormatter) format(w io.Writer, rows []row) error {
|
||||
if len(rows) == 0 {
|
||||
return nil
|
||||
}
|
||||
// aggregate() guarantees all rows in a batch share the same type;
|
||||
// check the first row to decide the format.
|
||||
if _, ok := rows[0].entry.(types.CookieEntry); !ok {
|
||||
return f.fallback.format(w, rows)
|
||||
}
|
||||
|
||||
entries := make([]cookieEditorEntry, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
c, ok := r.entry.(types.CookieEntry)
|
||||
if !ok {
|
||||
return nil // not cookies, skip
|
||||
}
|
||||
c, _ := r.entry.(types.CookieEntry)
|
||||
var expDate float64
|
||||
if !c.ExpireAt.IsZero() {
|
||||
expDate = float64(c.ExpireAt.Unix())
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ func newFormatter(name string) (formatter, error) {
|
||||
case "json":
|
||||
return &jsonFormatter{}, nil
|
||||
case "cookie-editor":
|
||||
return &cookieEditorFormatter{}, nil
|
||||
return &cookieEditorFormatter{fallback: &jsonFormatter{}}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported format: %s", name)
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ func TestNew(t *testing.T) {
|
||||
t.Run(tt.format, func(t *testing.T) {
|
||||
out, err := NewWriter(t.TempDir(), tt.format)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, out)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, out)
|
||||
}
|
||||
})
|
||||
@@ -142,7 +142,7 @@ func TestWrite_CSV_UTF8BOM(t *testing.T) {
|
||||
|
||||
raw, err := os.ReadFile(filepath.Join(dir, "password.csv"))
|
||||
require.NoError(t, err)
|
||||
require.True(t, len(raw) >= 3)
|
||||
require.GreaterOrEqual(t, len(raw), 3)
|
||||
assert.Equal(t, utf8BOM, raw[:3], "CSV should start with UTF-8 BOM")
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ func TestWrite_CookieEditor(t *testing.T) {
|
||||
}, entries[0])
|
||||
}
|
||||
|
||||
func TestWrite_CookieEditor_SkipsNonCookie(t *testing.T) {
|
||||
func TestWrite_CookieEditor_FallbackJSON(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
out, err := NewWriter(dir, "cookie-editor")
|
||||
require.NoError(t, err)
|
||||
@@ -258,9 +258,9 @@ func TestWrite_CookieEditor_SkipsNonCookie(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, out.Write())
|
||||
|
||||
// password file should not be created (cookie-editor only exports cookies)
|
||||
// non-cookie categories fall back to standard JSON format
|
||||
_, err = os.Stat(filepath.Join(dir, "password.json"))
|
||||
assert.True(t, os.IsNotExist(err))
|
||||
assert.False(t, os.IsNotExist(err), "password.json should be created via JSON fallback")
|
||||
}
|
||||
|
||||
// --- File creation ---
|
||||
|
||||
Reference in New Issue
Block a user