diff --git a/server/channels/api4/license.go b/server/channels/api4/license.go index 5d73b9cd14..4d48ee3b3f 100644 --- a/server/channels/api4/license.go +++ b/server/channels/api4/license.go @@ -212,7 +212,12 @@ func requestTrialLicense(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = model.NewAppError("requestTrialLicense", "api.license.request-trial.bad-request", nil, "", http.StatusBadRequest) return } - json.Unmarshal(b, &trialRequest) + + err = json.Unmarshal(b, &trialRequest) + if err != nil { + c.Err = model.NewAppError("requestTrialLicense", "api.license.request-trial.bad-request", nil, "", http.StatusBadRequest).Wrap(err) + return + } var appErr *model.AppError // If any of the newly supported trial request fields are set (ie, not a legacy request), process this as a new trial request (requiring the new fields) otherwise fall back on the old method. diff --git a/server/channels/api4/license_test.go b/server/channels/api4/license_test.go index 060659ffef..352906e926 100644 --- a/server/channels/api4/license_test.go +++ b/server/channels/api4/license_test.go @@ -386,6 +386,18 @@ func TestRequestTrialLicense(t *testing.T) { CheckForbiddenStatus(t, resp) }) + t.Run("trial license invalid JSON", func(t *testing.T) { + // the JSON is invalid because it is missing a closing brace + + licenseManagerMock := &mocks.LicenseInterface{} + licenseManagerMock.On("CanStartTrial").Return(true, nil).Once() + th.App.Srv().Platform().SetLicenseManager(licenseManagerMock) + + resp, err := th.SystemAdminClient.DoAPIPost(context.Background(), "/trial-license", `{"users": 5`) + CheckErrorID(t, err, "api.license.request-trial.bad-request") + CheckBadRequestStatus(t, model.BuildResponse(resp)) + }) + t.Run("trial license user count less than current users", func(t *testing.T) { nUsers := 1 license := model.NewTestLicense()