fix(216): fix presence of sign = in header values

pull/224/head
Jean-Thierry BONHOMME 2019-07-21 10:33:46 +02:00
parent 85b4129b08
commit c68e149328
4 changed files with 2007 additions and 658 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -298,7 +298,7 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
req.Header.Set("Content-Type", content.(string))
}
for _, h := range headers {
keyVal := strings.Split(h, "=")
keyVal := strings.SplitN(h, "=", 2)
if len(keyVal) == 2 {
if keyVal[0] != "" && keyVal[1] != "" {
req.Header.Set(keyVal[0], keyVal[1])

View File

@ -20,6 +20,7 @@ import (
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
"time"
)
@ -172,3 +173,23 @@ func TestRandomString(t *testing.T) {
func TestDeleteDirectory(t *testing.T) {
assert.Nil(t, DeleteDirectory(Directory+"/logs"))
}
func TestHttpRequest(t *testing.T) {
// Start a local HTTP server
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
// Test request parameters
assert.Equal(t, req.URL.String(), "/")
assert.Equal(t, req.Header["Aaa"], []string{"bbbb="})
assert.Equal(t, req.Header["Ccc"], []string{"ddd"})
// Send response to be tested
rw.Write([]byte(`OK`))
}))
// Close the server when test finishes
defer server.Close()
body, resp, err := HttpRequest(server.URL, "GET", "application/json", []string{"aaa=bbbb=", "ccc=ddd"}, nil, 2*time.Second)
assert.Nil(t, err)
assert.Equal(t, []byte("OK"), body)
assert.Equal(t, resp.StatusCode, 200)
}