Skip to content

Commit

Permalink
Change the string literal for the body of MultiHTTP requests into an …
Browse files Browse the repository at this point in the history
…expression that interpolates referenced variables.
  • Loading branch information
The-9880 committed May 29, 2024
1 parent 67934ee commit f8daec4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 2 additions & 6 deletions internal/prober/multihttp/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package multihttp
import (
"bytes"
"embed"
"encoding/base64"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -96,11 +95,8 @@ func buildBody(body *sm.HttpRequestBody) string {

default:
var buf strings.Builder

buf.WriteString(`encoding.b64decode("`)
buf.WriteString(base64.RawStdEncoding.EncodeToString(body.Payload))
buf.WriteString(`", 'rawstd', "b")`)

bodyString := string(body.Payload)
buf.WriteString(performVariableExpansion(bodyString))
return buf.String()
}
}
Expand Down
10 changes: 9 additions & 1 deletion internal/prober/multihttp/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,17 @@ func TestBuildBody(t *testing.T) {
input input
expected string
}{
"variable in body is interpolated correctly": {
input: input{body: &sm.HttpRequestBody{Payload: []byte("test ${testVar} works")}},
expected: "'test '+vars['testVar']+' works'", // 'test '+vars['testVar']+' works'
},
"body starting with variable is interpolated correctly": {
input: input{body: &sm.HttpRequestBody{Payload: []byte("${testVar} test")}},
expected: "vars['testVar']+' test'", // vars['testVar']+' test'
},
"not empty": {
input: input{body: &sm.HttpRequestBody{Payload: []byte("test")}},
expected: `encoding.b64decode("dGVzdA", 'rawstd', "b")`,
expected: "'test'", // 'test'
},
"nil": {
input: input{body: nil},
Expand Down

0 comments on commit f8daec4

Please sign in to comment.