Files
HackBrowserData/crypto/keyretriever/keyretriever_linux_test.go
T
Roger ccc8643d86 feat: add interactive terminal password prompt for keychain unlock (#558)
* feat(darwin): add interactive terminal password prompt for keychain unlock (#556)
* test: add unit tests for keyretriever and address review feedback

- Add errStorageNotFound sentinel error for precise error matching
- Non-TTY TerminalPasswordRetriever returns nil silently (review #558)
- Add darwin tests: findStorageKey, empty password, non-TTY skip
- Add linux tests: FallbackRetriever peanuts key, DefaultRetriever chain

* fix: add nolint:unused for errStorageNotFound on Windows, clean up error message

errStorageNotFound is only used on darwin/linux; Windows lint flagged it
as unused. Also simplify error format to avoid "storage" duplication.

* fix: add nolint:unused for errStorageNotFound, simplify error message

errStorageNotFound is only referenced on darwin and linux; Windows lint
flags it as unused. Also remove redundant "storage" prefix from the
error format string.
2026-04-06 01:27:13 +08:00

46 lines
1.3 KiB
Go

//go:build linux
package keyretriever
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFallbackRetriever(t *testing.T) {
r := &FallbackRetriever{}
key, err := r.RetrieveKey("Chrome", "")
require.NoError(t, err)
assert.Equal(t, linuxParams.deriveKey([]byte("peanuts")), key)
assert.Len(t, key, linuxParams.keySize)
// The key should not be all zeros.
allZero := true
for _, b := range key {
if b != 0 {
allZero = false
break
}
}
assert.False(t, allZero, "derived key should not be all zeros")
// "peanuts" is a fixed fallback password, so the result should be
// the same regardless of storage name or number of calls.
key2, err := r.RetrieveKey("Brave", "")
require.NoError(t, err)
assert.Equal(t, key, key2, "fallback key should be the same for any storage")
}
func TestDefaultRetriever_Linux(t *testing.T) {
r := DefaultRetriever("")
chain, ok := r.(*ChainRetriever)
require.True(t, ok, "DefaultRetriever should return a *ChainRetriever")
assert.Len(t, chain.retrievers, 2, "chain should have 2 retrievers")
assert.IsType(t, &DBusRetriever{}, chain.retrievers[0], "first retriever should be DBusRetriever")
assert.IsType(t, &FallbackRetriever{}, chain.retrievers[1], "second retriever should be FallbackRetriever")
}