chocolatey / chocolatey-licensed-issues

Issues for Licensed Editions of Chocolatey
19 stars 13 forks source link

Central Management Group CreateOrEdit endpoint throwing internal error in 0.12.0 when modifying group membership #377

Open sync-by-unito[bot] opened 5 months ago

sync-by-unito[bot] commented 5 months ago

What You Are Seeing?

When submitting a request to the CreateOrEdit endpoint and not providing the groups property in the json payload and error is thrown.

Prior to 0.12.0 you could supply computers, groups, or both and all would work correctly.

What is Expected?

I actually think this behavior is how it should have always happened, but we need to document in the Swagger document and also in our public documentation that these fields are now required.

How Did You Get This To Happen? (Steps to Reproduce)

  1. Create a WebSession variable
     $credential = Get-Credential
     $body = @{
            usernameOrEmailAddress = $Credential.UserName
            password               = $Credential.GetNetworkCredential().Password
        }

  $Result = Invoke-WebRequest -Uri "https://chocoserver.steviecoaster.dev/Account/Login" -Method POST -ContentType 'application/x-www-form-urlencoded' -Body $body -SessionVariable Session -ErrorAction Stop
  1. Send an API like below, editing for data available in your test environment(s)

$body = @{
            id        = $Id
            name      = $ccmGroupName
            computers = $computerArray
        }
 $params = @{
            Uri         = "https://chocoserver.steviecoaster.dev/api/services/app/Groups/CreateOrEdit"
            Method      = "POST"
            WebSession  = $Session
            ContentType = 'application/json'
            Body        = $body | ConvertTo-Json
        }

            $null = Invoke-RestMethod @params -ErrorAction Stop

System Details

Output Log

ccm-website.log

~~~sh 2023-12-18 09:56:44,991 42 [ERROR] - Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at ChocolateySoftware.ChocolateyManagement.Groups.GroupsAppService.Update(CreateOrEditGroupDto input) at ChocolateySoftware.ChocolateyManagement.Groups.GroupsAppService.CreateOrEdit(CreateOrEditGroupDto input) at lambda_method2172(Closure , Object ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) 2023-12-18 09:56:44,992 42 [INFO ] - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'. ~~~

Workarounds

You can modify the body of the request as follows:

$body = @{
            id        = $Id
            name      = $ccmGroupName
            computers = $computerArray
            groups    = @()
        }

Proposed Solution

Mark all fields required in Swagger documentation

Related Issues and Tickets

Zendesk Ticket

Done Checklist

┆Issue is synchronized with this Gitlab issue by Unito