add nil check for license manager (#21364)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9e72ca1867
Коммит
6aec81eb6e
@@ -106,7 +106,13 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// skip the restrictions if license is a sanctioned trial
|
// skip the restrictions if license is a sanctioned trial
|
||||||
if !license.IsSanctionedTrial() && license.IsTrialLicense() {
|
if !license.IsSanctionedTrial() && license.IsTrialLicense() {
|
||||||
canStartTrialLicense, err := c.App.Srv().Platform().LicenseManager().CanStartTrial()
|
lm := c.App.Srv().Platform().LicenseManager()
|
||||||
|
if lm == nil {
|
||||||
|
c.Err = model.NewAppError("addLicense", "api.license.upgrade_needed.app_error", nil, "", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
canStartTrialLicense, err := lm.CanStartTrial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, "", http.StatusInternalServerError)
|
c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, "", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -91,9 +91,6 @@ func TestUploadLicenseFile(t *testing.T) {
|
|||||||
mockLicenseValidator := mocks2.LicenseValidatorIface{}
|
mockLicenseValidator := mocks2.LicenseValidatorIface{}
|
||||||
defer testutils.ResetLicenseValidator()
|
defer testutils.ResetLicenseValidator()
|
||||||
|
|
||||||
//startTimestamp, err := time.Parse("2 Jan 2006 3:04 pm", "1 Jan 2021 12:00 am")
|
|
||||||
//require.Nil(t, err)
|
|
||||||
|
|
||||||
userCount := 100
|
userCount := 100
|
||||||
mills := model.GetMillis()
|
mills := model.GetMillis()
|
||||||
|
|
||||||
@@ -125,6 +122,37 @@ func TestUploadLicenseFile(t *testing.T) {
|
|||||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("try to get gone through trial, with TE build", func(t *testing.T) {
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = false })
|
||||||
|
th.App.Srv().Platform().SetLicenseManager(nil)
|
||||||
|
|
||||||
|
mockLicenseValidator := mocks2.LicenseValidatorIface{}
|
||||||
|
defer testutils.ResetLicenseValidator()
|
||||||
|
|
||||||
|
license := model.License{
|
||||||
|
Id: model.NewId(),
|
||||||
|
Features: &model.Features{
|
||||||
|
Users: model.NewInt(100),
|
||||||
|
},
|
||||||
|
Customer: &model.Customer{
|
||||||
|
Name: "Test",
|
||||||
|
},
|
||||||
|
StartsAt: model.GetMillis() + 100,
|
||||||
|
ExpiresAt: model.GetMillis() + 100 + (30*(time.Hour*24) + (time.Hour * 8)).Milliseconds(),
|
||||||
|
}
|
||||||
|
|
||||||
|
mockLicenseValidator.On("LicenseFromBytes", mock.Anything).Return(&license, nil).Once()
|
||||||
|
licenseBytes, err := json.Marshal(license)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
mockLicenseValidator.On("ValidateLicense", mock.Anything).Return(true, string(licenseBytes))
|
||||||
|
utils.LicenseValidator = &mockLicenseValidator
|
||||||
|
|
||||||
|
resp, err := th.SystemAdminClient.UploadLicenseFile([]byte(""))
|
||||||
|
CheckErrorID(t, err, "api.license.upgrade_needed.app_error")
|
||||||
|
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("allow uploading sanctioned trials even if server already gone through trial", func(t *testing.T) {
|
t.Run("allow uploading sanctioned trials even if server already gone through trial", func(t *testing.T) {
|
||||||
mockLicenseValidator := mocks2.LicenseValidatorIface{}
|
mockLicenseValidator := mocks2.LicenseValidatorIface{}
|
||||||
defer testutils.ResetLicenseValidator()
|
defer testutils.ResetLicenseValidator()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user