diff --git a/pkg/internal/cyberark/dataupload/dataupload.go b/pkg/internal/cyberark/dataupload/dataupload.go index a334be2a..d8835e3b 100644 --- a/pkg/internal/cyberark/dataupload/dataupload.go +++ b/pkg/internal/cyberark/dataupload/dataupload.go @@ -3,7 +3,7 @@ package dataupload import ( "bytes" "context" - "crypto/sha256" + "crypto/sha3" "crypto/x509" "encoding/hex" "encoding/json" @@ -64,7 +64,7 @@ func (c *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, payloa } encodedBody := &bytes.Buffer{} - checksum := sha256.New() + checksum := sha3.New256() if err := json.NewEncoder(io.MultiWriter(encodedBody, checksum)).Encode(payload); err != nil { return err } @@ -107,7 +107,7 @@ func (c *CyberArkClient) retrievePresignedUploadURL(ctx context.Context, checksu request := struct { ClusterID string `json:"cluster_id"` - Checksum string `json:"checksum_sha256"` + Checksum string `json:"checksum_sha3"` AgentVersion string `json:"agent_version"` }{ ClusterID: opts.ClusterName, diff --git a/pkg/internal/cyberark/dataupload/mock.go b/pkg/internal/cyberark/dataupload/mock.go index f54f0fd3..f8a2530b 100644 --- a/pkg/internal/cyberark/dataupload/mock.go +++ b/pkg/internal/cyberark/dataupload/mock.go @@ -1,7 +1,7 @@ package dataupload import ( - "crypto/sha256" + "crypto/sha3" "encoding/hex" "encoding/json" "fmt" @@ -73,19 +73,15 @@ func (mds *mockDataUploadServer) handlePresignedUpload(w http.ResponseWriter, r return } - body, err := io.ReadAll(r.Body) - if err != nil { - http.Error(w, "failed to read post body", http.StatusInternalServerError) - return - } - + decoder := json.NewDecoder(r.Body) var req struct { ClusterID string `json:"cluster_id"` - Checksum string `json:"checksum_sha256"` + Checksum string `json:"checksum_sha3"` AgentVersion string `json:"agent_version"` } - if err := json.Unmarshal(body, &req); err != nil { - http.Error(w, "failed to unmarshal post body", http.StatusInternalServerError) + decoder.DisallowUnknownFields() + if err := decoder.Decode(&req); err != nil { + http.Error(w, `{"error": "Invalid request format"}`, http.StatusBadRequest) return } @@ -141,7 +137,7 @@ func (mds *mockDataUploadServer) handleUpload(w http.ResponseWriter, r *http.Req return } - checksum := sha256.New() + checksum := sha3.New256() _, _ = io.Copy(checksum, r.Body) if r.URL.Query().Get("checksum") != hex.EncodeToString(checksum.Sum(nil)) {