Files
xinmi/cli/internal/secrets/keyring_test.go
T
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

68 lines
1.8 KiB
Go

package secrets
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zalando/go-keyring"
)
// Use the in-memory keyring backend for deterministic tests.
//
// go-keyring exposes MockInit so tests don't need a real OS keychain.
func TestKeyringStore_RoundTrip(t *testing.T) {
keyring.MockInit()
t.Cleanup(func() {
// Reset the mock so other test packages don't see leaked state.
keyring.MockInit()
})
k := NewKeyringStore()
// Get on missing returns ErrNotFound.
_, err := k.Get("prod", "access")
require.ErrorIs(t, err, ErrNotFound)
// Set + Get.
require.NoError(t, k.Set("prod", "access", "jwt-x"))
got, err := k.Get("prod", "access")
require.NoError(t, err)
assert.Equal(t, "jwt-x", got)
// Delete + Get.
require.NoError(t, k.Delete("prod", "access"))
_, err = k.Get("prod", "access")
require.ErrorIs(t, err, ErrNotFound)
// Delete on missing is a no-op.
require.NoError(t, k.Delete("prod", "access"))
}
func TestKeyringStore_NamespaceIsolation(t *testing.T) {
keyring.MockInit()
t.Cleanup(func() { keyring.MockInit() })
k := NewKeyringStore()
require.NoError(t, k.Set("prod", "access", "P"))
require.NoError(t, k.Set("staging", "access", "S"))
got, _ := k.Get("prod", "access")
assert.Equal(t, "P", got)
got, _ = k.Get("staging", "access")
assert.Equal(t, "S", got)
}
func TestNewBestEffortStore(t *testing.T) {
keyring.MockInit() // mock backend "supports" keyring → returns KeyringStore
t.Cleanup(func() { keyring.MockInit() })
s, err := NewBestEffortStore()
require.NoError(t, err)
_, ok := s.(*KeyringStore)
assert.True(t, ok, "with mock keyring backend, BestEffort must return KeyringStore")
}
func TestKeyringStore_Ref(t *testing.T) {
k := NewKeyringStore()
got := k.Ref("prod", "access")
assert.Equal(t, "keychain://weknora/prod/access", got)
}