From 1d535dc20d008845e79eb928ebd20d8190ae9129 Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Fri, 25 Aug 2017 13:14:03 -0400 Subject: [PATCH] Crash for nested params during GET 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. --- endpoint/endpoint.go | 11 +++++++++-- request/request_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index c58d570..1bd2b55 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -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 } diff --git a/request/request_test.go b/request/request_test.go index feb3c4e..d2c9fa3 100644 --- a/request/request_test.go +++ b/request/request_test.go @@ -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) + } +}