Skip to content

Commit

Permalink
Fixed panic in route logic (fixes #251)
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Nov 15, 2018
1 parent bc60cac commit c4198e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ loop:
protocolError()
return
}
sess, ok = value.(map[string]interface{})["sessionId"].(string)
valueMap, ok := value.(map[string]interface{})
if !ok {
protocolError()
return
}
sess, ok = valueMap["sessionId"].(string)
if !ok {
protocolError()
return
Expand Down
30 changes: 30 additions & 0 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,36 @@ func TestStartSessionJSONWireProtocol(t *testing.T) {
AssertThat(t, value["value"].(map[string]interface{})["sessionId"], EqualTo{fmt.Sprintf("%s123", node.Sum())})
}

func TestPanicRouteProtocolError(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/wd/hub/session", postOnly(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"value":[]}`))
}))
selenium := httptest.NewServer(mux)
defer selenium.Close()

host, port := hostportnum(selenium.URL)
node := Host{Name: host, Port: port, Count: 1}

test.Lock()
defer test.Unlock()

browsers := Browsers{Browsers: []Browser{
{Name: "browser", DefaultVersion: "1.0", Versions: []Version{
{Number: "1.0", Regions: []Region{
{Hosts: Hosts{
node,
}},
}},
}}}}
updateQuota(user, browsers)

rsp, err := createSession(`{"desiredCapabilities":{"browserName":"browser", "version":"1.0"}}`)

AssertThat(t, err, Is{nil})
AssertThat(t, rsp.StatusCode, Is{http.StatusBadGateway})
}

func TestDeleteSession(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/wd/hub/session/", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit c4198e1

Please sign in to comment.