package vaultik_test import ( "context" "io" "testing" "github.com/stretchr/testify/require" "sneak.berlin/go/vaultik/internal/config" "sneak.berlin/go/vaultik/internal/ui" "sneak.berlin/go/vaultik/internal/vaultik" ) // TestRestoreRejectsMalformedKeyBeforeDownload verifies that a malformed // age secret key stops restore at the parse step: nothing is fetched from // the store, and the error does not echo the key value (which is secret). func TestRestoreRejectsMalformedKeyBeforeDownload(t *testing.T) { t.Parallel() const malformed = "this-is-not-a-valid-age-key" mock := NewMockStorer() v := &vaultik.Vaultik{ Config: &config.Config{AgeSecretKey: malformed}, Storage: mock, Stdout: io.Discard, Stderr: io.Discard, UI: ui.NewWithColor(io.Discard, false), } v.SetContext(context.Background()) err := v.Restore(&vaultik.RestoreOptions{ SnapshotID: "any-snapshot", TargetDir: t.TempDir(), }) require.Error(t, err) require.NotContains(t, err.Error(), malformed, "error must not echo the key value") require.Contains(t, err.Error(), "age_secret_key", "error should name the configuration source") require.Empty(t, mock.GetCalls(), "a malformed key must fail before anything is fetched") }