[MM-60280] api4/license.go: add err check to JSON unmarshal (#28063)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d5cc2eb2f6
Коммит
6235f6cb77
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
Ссылка в новой задаче
Block a user