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
2 changes: 1 addition & 1 deletion sysdig/internal/client/v2/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Client) DeleteOrganizationSecure(ctx context.Context, orgID string) (er
}

func (c *Client) UpdateOrganizationSecure(ctx context.Context, orgID string, org *OrganizationSecure) (organization *OrganizationSecure, errString string, err error) {
payload, err := Marshal(org)
payload, err := c.marshalCloudauthProto(org)
if err != nil {
return nil, "", err
}
Expand Down
47 changes: 47 additions & 0 deletions sysdig/internal/client/v2/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
package v2

import (
"context"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"

Expand Down Expand Up @@ -39,6 +42,50 @@ func TestMarshalOrg(t *testing.T) {
}
}

func TestUpdateOrganizationSecureUsesCamelCase(t *testing.T) {
t.Parallel()

var receivedBody string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
receivedBody = string(body)
// Return a valid protobuf JSON response
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"managementAccountId":"31ebd166-82ef-4ca4-baf9-ce760afa46fb","organizationRootId":"r-8llw"}`))
}))
defer server.Close()

c := newSysdigClient(
WithURL(server.URL),
WithToken("test-token"),
)

org := &OrganizationSecure{
cloudauth.CloudOrganization{
ManagementAccountId: "31ebd166-82ef-4ca4-baf9-ce760afa46fb",
OrganizationRootId: "r-8llw",
},
}

_, _, err := c.UpdateOrganizationSecure(context.Background(), "e69f12fd-934d-43cc-8b8c-2964aba20003", org)
if err != nil {
t.Fatalf("UpdateOrganizationSecure failed: %v", err)
}

if strings.Contains(receivedBody, "management_account_id") {
t.Errorf("request body uses snake_case (json.Marshal), expected camelCase (protojson.Marshal): %s", receivedBody)
}
if !strings.Contains(receivedBody, "managementAccountId") {
t.Errorf("request body missing camelCase field 'managementAccountId': %s", receivedBody)
}
if strings.Contains(receivedBody, "organization_root_id") {
t.Errorf("request body uses snake_case 'organization_root_id', expected camelCase 'organizationRootId': %s", receivedBody)
}
if !strings.Contains(receivedBody, "organizationRootId") {
t.Errorf("request body missing camelCase field 'organizationRootId': %s", receivedBody)
}
}

func TestUnmarshalOrg(t *testing.T) {
t.Parallel()
c := Client{}
Expand Down
Loading