Skip to content

Commit

Permalink
Omit OpenID Connect customization template claims when none are set (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
F21 committed Jan 10, 2023
1 parent 93166f4 commit e4ff2a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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
31 changes: 31 additions & 0 deletions github/actions_oidc_test.go
Expand Up @@ -148,3 +148,34 @@ 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"
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)
})
}

0 comments on commit e4ff2a2

Please sign in to comment.