From 3216ab0a7ebcec65d61e38be0a11a743b41ee23c Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Tue, 19 Sep 2023 16:44:24 -0600 Subject: [PATCH] Remove returning the response body: In testing this was causing issues with consumers of the provider using the error string. Also, for security reasons we might not want to return an arbitrary response body, especially when it doesn't conform to the response contract. Signed-off-by: Jacob Weinstock --- providers/rpc/http.go | 3 +-- providers/rpc/rpc_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/providers/rpc/http.go b/providers/rpc/http.go index bde373ab..f9c7b3e4 100644 --- a/providers/rpc/http.go +++ b/providers/rpc/http.go @@ -58,8 +58,7 @@ func (p *Provider) handleResponse(statusCode int, headers http.Header, body *byt if statusCode != http.StatusOK { return ResponsePayload{}, fmt.Errorf("unexpected status code: %d, response error(optional): %v", statusCode, res.Error) } - example, _ := json.Marshal(ResponsePayload{ID: 123, Host: p.Host, Error: &ResponseError{Code: 1, Message: "error message"}}) - return ResponsePayload{}, fmt.Errorf("failed to parse response: got: %q, error: %w, expected response json spec: %v", body.String(), err, string(example)) + return ResponsePayload{}, fmt.Errorf("failed to parse response: %w", err) } if statusCode != http.StatusOK { return ResponsePayload{}, fmt.Errorf("unexpected status code: %d, response error(optional): %v", statusCode, res.Error) diff --git a/providers/rpc/rpc_test.go b/providers/rpc/rpc_test.go index 61401324..e15c5ee7 100644 --- a/providers/rpc/rpc_test.go +++ b/providers/rpc/rpc_test.go @@ -124,7 +124,7 @@ func TestPowerStateGet(t *testing.T) { shouldErr bool url string }{ - "success": {}, + "success": {powerState: "on"}, "unknown state": {shouldErr: true}, }