-
-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly handle new multiline secrets #2625
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,7 @@ func (s *Action) insertGetSecret(ctx context.Context, name, pw string) (gopass.S | |
|
||
// insertYAML will overwrite existing keys. | ||
func (s *Action) insertYAML(ctx context.Context, name, key string, content []byte, kvps map[string]string) error { | ||
debug.Log("insertYAML: %s - %s -> %s", name, key, content) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this will leak OTP codes in the debug logs, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these should be But if they do we can remove these. |
||
if ctxutil.IsInteractive(ctx) { | ||
pw, err := termio.AskForString(ctx, name+":"+key, "") | ||
if err != nil { | ||
|
@@ -200,12 +201,15 @@ func (s *Action) insertYAML(ctx context.Context, name, key string, content []byt | |
if err != nil { | ||
return exit.Error(exit.Encrypt, err, "failed to set key %q of %q: %s", key, name, err) | ||
} | ||
debug.Log("using existing secret %s", name) | ||
} else { | ||
sec = secrets.New() | ||
debug.Log("creating new secret %s", name) | ||
} | ||
|
||
setMetadata(sec, kvps) | ||
|
||
debug.Log("setting %s to %s", key, string(content)) | ||
if err := sec.Set(key, string(content)); err != nil { | ||
return exit.Error(exit.Usage, err, "failed set key %q of %q: %q", key, name, err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ package gitconfig | |
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,37 @@ zab: 123 | |
|
||
sec := ParseAKV([]byte(in)) | ||
assert.Equal(t, in, string(sec.Bytes())) | ||
assert.Equal(t, "passw0rd", sec.Password()) | ||
} | ||
|
||
func TestMultilineInsertAKV(t *testing.T) { | ||
t.Parallel() | ||
|
||
in := `passw0rd | ||
foo: baz | ||
foo: bar | ||
zab: 123 | ||
` | ||
|
||
sec := NewAKV() | ||
_, err := sec.Write([]byte(in)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, in, string(sec.Bytes())) | ||
assert.Equal(t, "passw0rd", sec.Password()) | ||
|
||
_, err = sec.Write([]byte("more text")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "passw0rd", sec.Password()) | ||
} | ||
|
||
func TestSetKeyValuePairToEmptyAKV(t *testing.T) { | ||
t.Parallel() | ||
|
||
sec := NewAKV() | ||
assert.NoError(t, sec.Set("foo", "bar")) | ||
v, found := sec.Get("foo") | ||
assert.True(t, found) | ||
assert.Equal(t, "bar", v) | ||
} | ||
|
||
func TestParseAKV(t *testing.T) { | ||
|
@@ -310,3 +341,34 @@ func FuzzParseAKV(f *testing.F) { | |
ParseAKV(in) | ||
}) | ||
} | ||
|
||
func TestPwWriter(t *testing.T) { | ||
a := NewAKV() | ||
p := pwWriter{w: &a.raw, cb: func(pw string) { a.password = pw }} | ||
|
||
// multi-chunk passwords are supported | ||
_, err := p.Write([]byte("foo")) | ||
assert.NoError(t, err) | ||
|
||
_, err = p.Write([]byte("bar\n")) | ||
assert.NoError(t, err) | ||
|
||
// but anything after the first line is discarded | ||
_, err = p.Write([]byte("baz\n")) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, "foobar", a.Password()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the test also test the content of Body? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's more comprehensive. |
||
assert.Equal(t, "baz\n", a.Body()) | ||
} | ||
|
||
func TestInvalidPwWriter(t *testing.T) { | ||
defer func() { | ||
r := recover() | ||
assert.NotNil(t, r) | ||
}() | ||
p := pwWriter{} | ||
|
||
// will panic because the writer is nil | ||
_, err := p.Write([]byte("foo")) | ||
assert.Error(t, err) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as other comment