Fix extra string actions
This commit is contained in:
@@ -45,6 +45,22 @@ func (s Service) Copy(model vault.Model, entryID string, target Target) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Service) CopyCustomField(model vault.Model, entryID, key string) error {
|
||||
entry, err := findEntry(model, entryID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
content, ok := entry.Fields[key]
|
||||
if !ok {
|
||||
return ErrUnsupportedTarget
|
||||
}
|
||||
if err := s.writer().WriteText(content); err != nil {
|
||||
return writeError{err: err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Service) writer() Writer {
|
||||
if s.Writer != nil {
|
||||
return s.Writer
|
||||
|
||||
@@ -48,6 +48,30 @@ func TestServiceCopiesUsernamePasswordAndURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceCopiesCustomField(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var writer memoryWriter
|
||||
service := Service{Writer: &writer}
|
||||
model := vault.Model{
|
||||
Entries: []vault.Entry{
|
||||
{
|
||||
ID: "vault-console",
|
||||
Fields: map[string]string{
|
||||
"OTPSeed": "green-light",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := service.CopyCustomField(model, "vault-console", "OTPSeed"); err != nil {
|
||||
t.Fatalf("CopyCustomField(vault-console, OTPSeed) error = %v", err)
|
||||
}
|
||||
if writer.content != "green-light" {
|
||||
t.Fatalf("clipboard content = %q, want green-light", writer.content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceRejectsUnknownEntryAndUnsupportedTarget(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user