-
-
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
[ENHANCEMENT] Allow for whitespace-trailing passwords (#2873) #2954
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 |
---|---|---|
|
@@ -250,7 +250,7 @@ func ParseAKV(in []byte) *AKV { | |
|
||
// handle the password that must be in the very first line | ||
if first { | ||
a.password = strings.TrimSpace(line) | ||
a.password = line | ||
first = false | ||
|
||
continue | ||
|
@@ -260,15 +260,13 @@ func ParseAKV(in []byte) *AKV { | |
continue | ||
} | ||
|
||
line = strings.TrimSpace(line) | ||
|
||
key, val, found := strings.Cut(line, kvSep) | ||
if !found { | ||
continue | ||
} | ||
|
||
key = strings.TrimSpace(key) | ||
val = strings.TrimSpace(val) | ||
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. Should I add a more detailed comment of why val wasn't Do you normally reference GitHub issues on comments? 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. Remove the dead code and add a reference to the GH Issue, please. |
||
// val is not Trimmed. See https://github.com/gopasspw/gopass/issues/2873 | ||
// we only store lower case keys for KV | ||
a.kvp[key] = append(a.kvp[key], val) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,75 @@ func TestSetKeyValuePairToEmptyAKV(t *testing.T) { | |
assert.Equal(t, "bar", v) | ||
} | ||
|
||
func TestAKVTrailingWhitespace(t *testing.T) { | ||
t.Parallel() | ||
// Expected behaviour is KEY: VALUE, with one space. | ||
// Fallback should exist for KEY:VALUE, with no spaces. | ||
mlValue := `foobar | ||
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. I think the issue initially was about passwords surrounded by spaces, no just key-values pairs, no? 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. Correct, I think the issue was about whitespace in passwords. 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. Sorry, I had a misunderstanding between KV pairs and the password itself. But it should also be simple to not |
||
defaultBehaviour: cd | ||
sorroundedBySpace: cd | ||
withoutSpace:cd` | ||
s := ParseAKV([]byte(mlValue)) | ||
assert.NotNil(t, s) | ||
v1, _ := s.Get("defaultBehaviour") | ||
assert.Equal(t, "cd", v1) | ||
v2, _ := s.Get("sorroundedBySpace") | ||
assert.Equal(t, " cd \t ", v2) | ||
v3, _ := s.Get("defaultBehaviour") | ||
assert.Equal(t, "cd", v3) | ||
} | ||
|
||
func TestAKVPasswordWhitespace(t *testing.T) { | ||
t.Parallel() | ||
|
||
helloIsWorldStr := "\nhello: world\n" | ||
helloIsWorldPair := map[string][]string{ | ||
"hello": {"world"}, | ||
} | ||
|
||
for _, tc := range []struct { | ||
name string | ||
in string | ||
pw string | ||
kvp map[string][]string | ||
}{ | ||
{ | ||
name: "justpassword", | ||
in: `this is a password.` + helloIsWorldStr, | ||
pw: "this is a password.", | ||
kvp: helloIsWorldPair, | ||
}, | ||
{ | ||
name: "spaceonly", | ||
in: " " + helloIsWorldStr, | ||
pw: " ", | ||
kvp: helloIsWorldPair, | ||
}, | ||
{ | ||
name: "tab", | ||
in: "\t tab padded password \t" + helloIsWorldStr, | ||
pw: "\t tab padded password \t", | ||
kvp: helloIsWorldPair, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
a := ParseAKV([]byte(tc.in)) | ||
|
||
assert.Equal(t, tc.pw, a.password, tc.name) | ||
for k, vs := range tc.kvp { | ||
sort.Strings(vs) | ||
gvs := a.kvp[k] | ||
sort.Strings(gvs) | ||
assert.Equal(t, vs, gvs, k) | ||
} | ||
|
||
assert.Equal(t, tc.in, string(a.Bytes()), tc.name) | ||
}) | ||
} | ||
} | ||
|
||
func TestParseAKV(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
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.
The components of the line were going to be
trim
med anyway.