diff --git a/api4/license.go b/api4/license.go index 2e8474c804..2a6b61c916 100644 --- a/api4/license.go +++ b/api4/license.go @@ -242,6 +242,11 @@ func requestRenewalLink(c *Context, w http.ResponseWriter, r *http.Request) { return } + if c.App.Cloud() == nil { + c.Err = model.NewAppError("requestRenewalLink", "api.license.upgrade_needed.app_error", nil, "", http.StatusForbidden) + return + } + // check if it is possible to renew license on the portal with generated token e := c.App.Cloud().GetLicenseRenewalStatus(c.AppContext.Session().UserId, token) if e != nil { diff --git a/api4/license_test.go b/api4/license_test.go index ed1b78589f..5d3c04ec71 100644 --- a/api4/license_test.go +++ b/api4/license_test.go @@ -262,3 +262,19 @@ func TestRequestTrialLicense(t *testing.T) { CheckForbiddenStatus(t, resp) }) } + +func TestRequestRenewalLink(t *testing.T) { + th := Setup(t) + defer th.TearDown() + + require.NotPanics(t, func() { + cloudImpl := th.App.Srv().Cloud + defer func() { + th.App.Srv().Cloud = cloudImpl + }() + th.App.Srv().Cloud = nil + resp, err := th.SystemAdminClient.DoAPIGet("/license/renewal", "") + CheckErrorID(t, err, "app.license.generate_renewal_token.no_license") + require.Equal(t, http.StatusBadRequest, resp.StatusCode) + }) +}