Skip to content

Commit

Permalink
return 400 if invalid log_json param is given
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Oct 30, 2019
1 parent 9a162fd commit 9b7f0ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions command/agent/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ func (s *HTTPServer) AgentMonitor(resp http.ResponseWriter, req *http.Request) (
// Determine if we are targeting a server or client
nodeID := req.URL.Query().Get("node_id")

logJSON := false
logJSONStr := req.URL.Query().Get("log_json")
logJSON, err := strconv.ParseBool(logJSONStr)
if err != nil {
logJSON = false
if logJSONStr != "" {
parsed, err := strconv.ParseBool(logJSONStr)
if err != nil {
return nil, CodedError(400, fmt.Sprintf("Unknown option for log json: %v", err))
}
logJSON = parsed
}

// Build the request and parse the ACL token
Expand Down
14 changes: 14 additions & 0 deletions command/agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ func TestHTTP_AgentMonitor(t *testing.T) {
t.Parallel()

httpTest(t, nil, func(s *TestAgent) {
// invalid log_json
{
req, err := http.NewRequest("GET", "/v1/agent/monitor?log_json=no", nil)
require.Nil(t, err)
resp := newClosableRecorder()

// Make the request
_, err = s.Server.AgentMonitor(resp, req)
if err.(HTTPCodedError).Code() != 400 {
t.Fatalf("expected 400 response, got: %v", resp.Code)
}
}

// unknown log_level
{
req, err := http.NewRequest("GET", "/v1/agent/monitor?log_level=unknown", nil)
require.Nil(t, err)
Expand Down

0 comments on commit 9b7f0ab

Please sign in to comment.