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

Fix: Organization Policy can't be updated if max_ttl and default_ttl … #925

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading