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 pkg/serviceaccounts/oidc_identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type OIDCIdentityQuery struct {
}

type OIDCIdentity struct {
Audience string `json:"Audience"`
Audience string `json:"Audience,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note that this can potentially change behaviour of the endpoint if endpoint treats differently null and empty values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It does change the behaviour (Audience no longer gets set with an empty string value) but that's the intended result because the current behaviour results in the existing bug. I don't think anyone would be reliant on this behaviour, what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think so, but wanted to raise the question to confirm that you were aware of it :) 👍

Issuer string `json:"Issuer"`
Name string `json:"Name"`
ServiceAccountID string `json:"ServiceAccountId"`
Expand Down
36 changes: 36 additions & 0 deletions pkg/serviceaccounts/oidc_identities_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package serviceaccounts

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
)

func TestOIDCIdentity_MarshalJSON_OmitsEmptyAudience(t *testing.T) {
identity := NewOIDCIdentity("ServiceAccounts-1", "name", "issuer", "subject")

data, err := json.Marshal(identity)
assert.NoError(t, err)

var result map[string]interface{}
err = json.Unmarshal(data, &result)
assert.NoError(t, err)

_, hasAudience := result["Audience"]
assert.False(t, hasAudience, "Audience must be omitted from JSON when unset")
}

func TestOIDCIdentity_MarshalJSON_IncludesAudienceWhenSet(t *testing.T) {
identity := NewOIDCIdentity("ServiceAccounts-1", "name", "issuer", "subject")
identity.Audience = "api://custom"

data, err := json.Marshal(identity)
assert.NoError(t, err)

var result map[string]interface{}
err = json.Unmarshal(data, &result)
assert.NoError(t, err)

assert.Equal(t, "api://custom", result["Audience"])
}
Loading