From c7ba92b95e9898e0a1610631dc5fa207cf6b6c33 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Mon, 5 Aug 2024 07:48:48 -0500 Subject: [PATCH] =?UTF-8?q?Fix:=20Organization=20Policy=20can't=20be=20upd?= =?UTF-8?q?ated=20if=20max=5Fttl=20and=20default=5Fttl=20=E2=80=A6=20(#925?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Organization Policy can't be updated if max_ttl and default_ttl are nil * added a unit test * updated test --- client/organization.go | 8 ++++++++ client/organization_test.go | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/client/organization.go b/client/organization.go index 628f7c9b..a714d747 100644 --- a/client/organization.go +++ b/client/organization.go @@ -72,6 +72,14 @@ func (client *ApiClient) OrganizationPolicyUpdate(payload OrganizationPolicyUpda return nil, err } + if payload.DefaultTtl != nil && *payload.DefaultTtl == "" { + payload.DefaultTtl = nil + } + + if payload.MaxTtl != nil && *payload.MaxTtl == "" { + payload.MaxTtl = nil + } + var result Organization if err := client.http.Post("/organizations/"+id+"/policies", payload, &result); err != nil { return nil, err diff --git a/client/organization_test.go b/client/organization_test.go index 8affa26e..7e14abe2 100644 --- a/client/organization_test.go +++ b/client/organization_test.go @@ -139,6 +139,46 @@ var _ = Describe("Organization", func() { }) }) + Describe("Emtpy string is passed as null", func() { + updatedMockOrganization := mockOrganization + updatedMockOrganization.DefaultTtl = nil + updatedMockOrganization.MaxTtl = nil + + var updatedOrganization *Organization + var err error + + emptyString := "" + + BeforeEach(func() { + mockOrganizationIdCall(organizationId) + originalUpdatePayload := OrganizationPolicyUpdatePayload{ + DefaultTtl: &emptyString, + MaxTtl: &emptyString, + } + + sentUpdatePayload := OrganizationPolicyUpdatePayload{ + DefaultTtl: nil, + MaxTtl: nil, + } + + httpCall = mockHttpClient.EXPECT(). + Post("/organizations/"+organizationId+"/policies", sentUpdatePayload, gomock.Any()). + Do(func(path string, request interface{}, response *Organization) { + *response = updatedMockOrganization + }).Times(1) + + updatedOrganization, err = apiClient.OrganizationPolicyUpdate(originalUpdatePayload) + }) + + It("Should not return an error", func() { + Expect(err).To(BeNil()) + }) + + It("Should return organization received from API", func() { + Expect(*updatedOrganization).To(Equal(updatedMockOrganization)) + }) + }) + Describe("OrganizationUserUpdateRole", func() { userId := "userId" roleId := "roleId"