Skip to content

Commit

Permalink
Crash for nested params during GET
Browse files Browse the repository at this point in the history
If the params config was nested and the request method was a GET request
we would get a crash during parsing the parameters.

If the param map is not [string,string] it will be ignored now.
  • Loading branch information
ViaoV committed Aug 25, 2017
1 parent d65b599 commit 1d535dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
11 changes: 9 additions & 2 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,16 @@ func (ep *EndpointConfig) GetRequestParams() map[string]string {
return make(map[string]string)
}
paramsMap := make(map[string]string)
children, _ := ep.json.S("data").ChildrenMap()
children, err := ep.json.S("data").ChildrenMap()
if err != nil {
return paramsMap
}
for key, child := range children {
paramsMap[key] = expandFakes(config.ExpandString(child.Data().(string)))
childData, ok := child.Data().(string)
if ok {
paramsMap[key] = expandFakes(config.ExpandString(childData))
}

}
return paramsMap
}
Expand Down
26 changes: 26 additions & 0 deletions request/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ func TestMain(m *testing.M) {
testhelper.Teardown()
os.Exit(retCode)
}

func TestBadGetdata(t *testing.T) {
ts := testhelper.RunTestServer(`
{
"inner": {
"value": "1234567890"
}
}
`)
defer ts.Close()
epConfig := testhelper.EndpointConfig(`
{
"url": "%s",
"method": "GET",
"data": {
"outer": [
{ "inner": "test" }
]
}
}
`, ts.URL)
_, err := Do(epConfig)
if err != nil {
t.Fatalf("Error making request: %s", err)
}
}

0 comments on commit 1d535dc

Please sign in to comment.