Skip to content

Commit

Permalink
fix(decode): fixing decode function for base64 secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zoveralli committed Jun 10, 2021
1 parent aa5d8e4 commit 421d601
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/synchronizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func getEnv(key, fallback string) string {
func decode(s string) ([]byte, error) {
switch {
case strings.HasPrefix(s, "base64:"):
return base64.StdEncoding.DecodeString(strings.TrimLeft(s, "base64:"))
return base64.StdEncoding.DecodeString(strings.TrimPrefix(s, "base64:"))
default:
return []byte(s), nil
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/synchronizer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

const (
quote = "The fool don‘t think he is wise, but the wise man knows himself to be a fool."
trivialString = "h"
)

func TestDecode(t *testing.T) {
Expand All @@ -27,6 +28,13 @@ func TestDecode(t *testing.T) {
assert.Equal(t, quote, string(res))
})

t.Run("base64 encoded", func(t *testing.T) {
str := "base64:" + base64.StdEncoding.EncodeToString([]byte(trivialString))
res, err := decode(str)
assert.NoError(t, err)
assert.Equal(t, trivialString, string(res))
})

t.Run("base64 decode fails", func(t *testing.T) {
str := "base64:" + quote
_, err := decode(str)
Expand Down

0 comments on commit 421d601

Please sign in to comment.