Skip to content

Commit

Permalink
Fix: Organization Policy can't be updated if max_ttl and default_ttl … (
Browse files Browse the repository at this point in the history
#925)

* Fix: Organization Policy can't be updated if max_ttl and default_ttl are nil

* added a unit test

* updated test
  • Loading branch information
TomerHeber authored Aug 5, 2024
1 parent 9601091 commit c7ba92b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions client/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c7ba92b

Please sign in to comment.