Skip to content

Commit

Permalink
[ENHANCEMENT] Allow for whitespace-trailing passwords pt2
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Hardt <[email protected]>
  • Loading branch information
lhardt committed Oct 6, 2024
1 parent 49eafdd commit bdd740c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/gopass/secrets/akv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -266,7 +266,7 @@ func ParseAKV(in []byte) *AKV {
}

key = strings.TrimSpace(key)
// val = strings.TrimSpace(val)
// 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)
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/gopass/secrets/akv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,57 @@ withoutSpace:cd`
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()

Expand Down

0 comments on commit bdd740c

Please sign in to comment.