Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/internal/cyberark/dataupload/dataupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dataupload
import (
"bytes"
"context"
"crypto/sha256"
"crypto/sha3"
"crypto/x509"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 7 additions & 11 deletions pkg/internal/cyberark/dataupload/mock.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dataupload

import (
"crypto/sha256"
"crypto/sha3"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the mock server respond more like the real server.


Expand Down Expand Up @@ -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)) {
Expand Down