From 50c16021f6670c1ce55075c1b383dabd7a793a2c Mon Sep 17 00:00:00 2001 From: Rez Moss Date: Tue, 20 Aug 2024 19:17:32 -0400 Subject: [PATCH 1/2] fixed 3238 ProvisionAndInviteSCIMUser --- github/scim.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/github/scim.go b/github/scim.go index 02136d7ef91..3043a89d56d 100644 --- a/github/scim.go +++ b/github/scim.go @@ -110,19 +110,22 @@ func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org str // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#provision-and-invite-a-scim-user // //meta:operation POST /scim/v2/organizations/{org}/Users -func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*Response, error) { +func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*SCIMUserAttributes, *Response, error) { + u := fmt.Sprintf("scim/v2/organizations/%v/Users", org) - u, err := addOptions(u, opts) + + req, err := s.client.NewRequest("POST", u, opts) if err != nil { - return nil, err - } + return nil, nil, err + } - req, err := s.client.NewRequest("POST", u, nil) + user := new(SCIMUserAttributes) + resp, err := s.client.Do(ctx, req, user) if err != nil { - return nil, err + return nil, resp, err } - return s.client.Do(ctx, req, nil) + return user, resp, nil } // GetSCIMProvisioningInfoForUser returns SCIM provisioning information for a user. From 02064f69fedd338cb87e2a86defd09a34736ba18 Mon Sep 17 00:00:00 2001 From: Rez Moss Date: Tue, 20 Aug 2024 19:46:58 -0400 Subject: [PATCH 2/2] test for issue 3238 --- github/scim.go | 3 +-- github/scim_test.go | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/github/scim.go b/github/scim.go index 3043a89d56d..4b34c1663cd 100644 --- a/github/scim.go +++ b/github/scim.go @@ -111,13 +111,12 @@ func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org str // //meta:operation POST /scim/v2/organizations/{org}/Users func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*SCIMUserAttributes, *Response, error) { - u := fmt.Sprintf("scim/v2/organizations/%v/Users", org) req, err := s.client.NewRequest("POST", u, opts) if err != nil { return nil, nil, err - } + } user := new(SCIMUserAttributes) resp, err := s.client.Do(ctx, req, user) diff --git a/github/scim_test.go b/github/scim_test.go index 9e5274766aa..2ae4f194456 100644 --- a/github/scim_test.go +++ b/github/scim_test.go @@ -127,7 +127,8 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) { mux.HandleFunc("/scim/v2/organizations/o/Users", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - w.WriteHeader(http.StatusOK) + w.WriteHeader(http.StatusCreated) + fmt.Fprint(w, `{"id":"1234567890","userName":"userName"}`) }) ctx := context.Background() @@ -143,19 +144,31 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) { }, }, } - _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + user, _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) if err != nil { - t.Errorf("SCIM.ListSCIMProvisionedIdentities returned error: %v", err) + t.Errorf("SCIM.ProvisionAndInviteSCIMUser returned error: %v", err) + } + + want := &SCIMUserAttributes{ + ID: String("1234567890"), + UserName: "userName", + } + if !cmp.Equal(user, want) { + t.Errorf("SCIM.ProvisionAndInviteSCIMUser returned %+v, want %+v", user, want) } const methodName = "ProvisionAndInviteSCIMUser" testBadOptions(t, methodName, func() (err error) { - _, err = client.SCIM.ProvisionAndInviteSCIMUser(ctx, "\n", opts) + _, _, err = client.SCIM.ProvisionAndInviteSCIMUser(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + got, resp, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err }) }