Skip to content

Commit

Permalink
fix: core-command fuzzing test http error 500
Browse files Browse the repository at this point in the history
fixed fuzzing core-command http error 500 when invalid input in body http://localhost:59882/api/v3/device/name/Random-Boolean-Device/Bool

Closes: #4639
Signed-off-by: Valina Li <valina.li@intel.com>
  • Loading branch information
vli11 committed Aug 16, 2023
1 parent 74b98e4 commit 7fce62d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/core/command/controller/http/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func TestIssueSetCommand(t *testing.T) {
{"Invalid - execute set command with invalid commandName", testDeviceName, nonExistName, testQueryStrings, testSettingsJsonStr, true, http.StatusBadRequest},
{"Invalid - empty device name", "", testCommandName, testQueryStrings, testSettingsJsonStr, true, http.StatusBadRequest},
{"Invalid - empty command name", testDeviceName, "", testQueryStrings, testSettingsJsonStr, true, http.StatusBadRequest},
{"Invalid - empty settings", testDeviceName, testCommandName, testQueryStrings, []byte{}, true, http.StatusInternalServerError},
{"Invalid - empty settings", testDeviceName, testCommandName, testQueryStrings, []byte{}, true, http.StatusBadRequest},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func ParseBodyToMap(r *http.Request) (map[string]interface{}, errors.EdgeX) {

var result map[string]interface{}
if err = json.Unmarshal(body, &result); err != nil {
return nil, errors.NewCommonEdgeX(errors.KindServerError, "failed to parse request body", err)
return nil, errors.NewCommonEdgeX(errors.KindContractInvalid, "failed to parse request body", err)
}

return result, nil
Expand Down

0 comments on commit 7fce62d

Please sign in to comment.