Skip to content

Commit

Permalink
Merge pull request #270 from jwiklund/binary-metadata
Browse files Browse the repository at this point in the history
base64 decode binary metadata
  • Loading branch information
bojand committed May 4, 2021
2 parents 8d555a2 + 57df589 commit ff10171
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions runner/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package runner

import (
"bytes"
"encoding/base64"
"encoding/json"
"math/rand"
"strings"
"text/template"
"text/template/parse"
"time"
Expand Down Expand Up @@ -181,6 +183,16 @@ func (td *CallData) executeMetadata(metadata string) (map[string]string, error)
if err != nil {
return nil, err
}

for key, value := range mdMap {
if strings.HasSuffix(key, "-bin") {
decoded, err := base64.StdEncoding.DecodeString(value)
if err != nil {
return nil, err
}
mdMap[key] = string(decoded)
}
}
}

return mdMap, nil
Expand Down
5 changes: 5 additions & 0 deletions runner/calldata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func TestCallData_ExecuteMetadata(t *testing.T) {
map[string]string{"trace_id": "asdf {{.Something}} {{.MethodName}} bob"},
false,
},
{"with binary data",
`{"data-bin":"YmFzZTY0"}`,
map[string]string{"data-bin": "base64"},
false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit ff10171

Please sign in to comment.