Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit OpenID Connect customization template claims when none are set #2620

Merged
merged 2 commits into from Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion github/actions_oidc.go
Expand Up @@ -13,7 +13,7 @@ import (
// OIDCSubjectClaimCustomTemplate represents an OIDC subject claim customization template.
type OIDCSubjectClaimCustomTemplate struct {
UseDefault *bool `json:"use_default,omitempty"`
IncludeClaimKeys []string `json:"include_claim_keys"`
IncludeClaimKeys []string `json:"include_claim_keys,omitempty"`
}

// GetOrgOIDCSubjectClaimCustomTemplate gets the subject claim customization template for an organization.
Expand Down
32 changes: 32 additions & 0 deletions github/actions_oidc_test.go
Expand Up @@ -148,3 +148,35 @@ func TestActionsService_SetRepoOIDCSubjectClaimCustomTemplate(t *testing.T) {
return client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "o", "r", input)
})
}

func TestActionService_SetRepoOIDCSubjectClaimCustomTemplateToDefault(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/actions/oidc/customization/sub", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"use_default":true}`+"\n")
w.WriteHeader(http.StatusCreated)
})

input := &OIDCSubjectClaimCustomTemplate{
UseDefault: Bool(true),
}
ctx := context.Background()
_, err := client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "o", "r", input)
if err != nil {
t.Errorf("Actions.SetRepoOIDCSubjectClaimCustomTemplate returned error: %v", err)
}

const methodName = "SetRepoOIDCSubjectClaimCustomTemplate"

F21 marked this conversation as resolved.
Show resolved Hide resolved
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "\n", "\n", input)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "o", "r", input)
})
}