refactor: tidy up sharing after the round of tweaks
- Go to's picker settings are one picker struct, set while picking.
- Opening a share link plans the save, then asks or saves; no more
offerWrite doing either by a flag.
- Closing the picker while it encrypts cancels the share, and a
second pick meanwhile is ignored.
- Favourites and Recent leave out plain env values as keys too.
- share.key in the config is checked with share.ParseKey, so
{{secrets/…}} is refused there already.
- A key that can't be read reads the same opening as sharing
("can't use …"); KeyError moved to share.go, maxFiles is
maxUnpacked (bytes), and a stray comment is gone.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
9 files changed
+218
-118
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/provider/fake"
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/provider/repo"
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/share"
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/store"
|
||||
)
|
||||
|
||||
// scryptWait is how long the driver waits for encrypting and decrypting:
|
||||
@@ -50,7 +51,7 @@ func shareFrom(t *testing.T, root string, paste bool) string {
|
||||
// No share.key set: it asks which secret, in Go to, which lists
|
||||
// only secrets.
|
||||
v := d.m.search
|
||||
if v == nil || v.pick == nil {
|
||||
if v == nil || v.picker == nil {
|
||||
t.Fatalf("no secret picker: %s", d.m.flash.text)
|
||||
}
|
||||
for _, o := range v.shown {
|
||||
@@ -210,12 +211,12 @@ func TestShareInDemo(t *testing.T) {
|
||||
}
|
||||
src.Provider = "Repos"
|
||||
d.run(d.m.shareFiles(src, nil))
|
||||
if d.m.search == nil || d.m.search.pick == nil {
|
||||
if d.m.search == nil || d.m.search.picker == nil {
|
||||
t.Fatalf("no picker: %s", d.m.flash.text)
|
||||
}
|
||||
// Too short a key: the picker stays, saying why.
|
||||
d.send(tea.PasteMsg{Content: "https://kv-app-prod.vault.azure.net/secrets/db-password"})
|
||||
if d.m.search == nil || !strings.Contains(d.m.search.pickErr, "Can't use db-password: its value has 28 characters; share.keyRules needs 32 (minLength)") {
|
||||
if d.m.search == nil || !strings.Contains(d.m.search.picker.err, "Can't use db-password: its value has 28 characters; share.keyRules needs 32 (minLength)") {
|
||||
t.Fatalf("not said in the picker: %v\n%s", d.m.search != nil, d.screen())
|
||||
}
|
||||
if !strings.Contains(d.screen(), "28 characters") {
|
||||
@@ -248,3 +249,66 @@ func TestShareInDemo(t *testing.T) {
|
||||
t.Fatalf("nothing saved (%s)", d.m.flash.text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPickerCancelAndBusy(t *testing.T) {
|
||||
clip := &fakeClipboard{}
|
||||
d := newDriverOpts(t, Options{Clipboard: clip},
|
||||
fake.Azure(0), fake.AzureOps(0).As("Azure:admin", "Azure · admin"), fake.Repos())
|
||||
var src provider.Source
|
||||
for _, s := range d.m.sourceResults["Repos"].sources {
|
||||
if s.Here {
|
||||
src = s
|
||||
}
|
||||
}
|
||||
src.Provider = "Repos"
|
||||
d.run(d.m.shareFiles(src, nil))
|
||||
p := d.m.search.picker
|
||||
key, _ := share.ParseKey("https://kv-shared-prod.vault.azure.net/secrets/env-share")
|
||||
|
||||
// Picking starts sealing; another pick meanwhile is ignored.
|
||||
cmd := p.choose(&d.m, key)
|
||||
if cmd == nil || p.busy == "" {
|
||||
t.Fatal("picking didn't start")
|
||||
}
|
||||
if again := p.choose(&d.m, key); again != nil {
|
||||
t.Error("a second pick while busy wasn't ignored")
|
||||
}
|
||||
|
||||
// Closed before the link is made: cancelled, nothing copied.
|
||||
d.m.search = nil
|
||||
d.wait = scryptWait
|
||||
d.run(cmd)
|
||||
if clip.content != "" {
|
||||
t.Errorf("copied after the picker was closed: %q", clip.content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlainEnvNotPickableFromFavourites(t *testing.T) {
|
||||
mem, _ := store.Load("")
|
||||
d := newDriverOpts(t, Options{Store: mem}, fake.Azure(0), fake.Repos())
|
||||
var src provider.Source
|
||||
for _, s := range d.m.sourceResults["Repos"].sources {
|
||||
if s.Here {
|
||||
src = s
|
||||
}
|
||||
}
|
||||
// A key in the demo repo's plain .env, starred.
|
||||
key := "lazysecrets://repo/" + url.PathEscape(src.Detail) + "/.env/DATABASE_URL"
|
||||
mem.Update(key, func(n *store.Node) {
|
||||
n.StarredBy = []string{"Repos"}
|
||||
n.Path = []string{src.Name, ".env"}
|
||||
n.Source = src.ID
|
||||
})
|
||||
src.Provider = "Repos"
|
||||
d.run(d.m.shareFiles(src, nil))
|
||||
favs, _ := d.m.storeEntries()
|
||||
for _, o := range favs {
|
||||
if o.star == key {
|
||||
if _, ok := pickable(o); ok {
|
||||
t.Error("a plain .env value is offered as a key in Favourites")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("the starred key isn't among the favourites: %d", len(favs))
|
||||
}
|
||||
Reference in new issue
Block a user