Skip to content

Commit

Permalink
Output full secret when not properly encoded for cat (gopasspw#2105)
Browse files Browse the repository at this point in the history
RELEASE_NOTES=[BUGFIX] Handle unencoded secret on cat

Fixes gopasspw#2104

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Jan 13, 2022
1 parent 2083301 commit fba72b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/action/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ func (s *Action) binaryGet(ctx context.Context, name string) ([]byte, error) {
}

if cte, _ := sec.Get("content-transfer-encoding"); cte != "Base64" {
return []byte(sec.Body()), nil
// need to use sec.Bytes() otherwise the first line is missing.
return sec.Bytes(), nil
}

buf, err := base64.StdEncoding.DecodeString(sec.Body())
Expand Down
20 changes: 20 additions & 0 deletions internal/action/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ func TestBinarySum(t *testing.T) {
})
}

func TestBinaryGet(t *testing.T) {
u := gptest.NewUnitTester(t)
defer u.Remove()

ctx := context.Background()
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)

act, err := newMock(ctx, u)
require.NoError(t, err)
require.NotNil(t, act)

data := []byte("1\n2\n3\n")
assert.NoError(t, act.insertStdin(ctx, "x", data, false))

out, err := act.binaryGet(ctx, "x")
assert.NoError(t, err)
assert.Equal(t, data, out)
}

func writeBinfile(t *testing.T, fn string) {
// tests should be predicable
rand.Seed(42)
Expand Down

0 comments on commit fba72b6

Please sign in to comment.