From c3c8b28eb77dcfbed8e88f7daf135de0dea28478 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 26 Mar 2019 10:32:59 +0000 Subject: [PATCH] MM-14626: Make license expiry checks behave how they are meant to. (#10495) --- app/license.go | 12 +++++++----- app/license_test.go | 9 --------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/license.go b/app/license.go index 698c2194ba..ce50b1e2c8 100644 --- a/app/license.go +++ b/app/license.go @@ -62,6 +62,10 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) return nil, model.NewAppError("addLicense", "api.license.add_license.unique_users.app_error", map[string]interface{}{"Users": *license.Features.Users, "Count": uniqueUserCount}, "", http.StatusBadRequest) } + if license != nil && license.IsExpired() { + return nil, model.NewAppError("addLicense", model.EXPIRED_LICENSE_ERROR, nil, "", http.StatusBadRequest) + } + if ok := a.SetLicense(license); !ok { return nil, model.NewAppError("addLicense", model.EXPIRED_LICENSE_ERROR, nil, "", http.StatusBadRequest) } @@ -117,11 +121,9 @@ func (a *App) SetLicense(license *model.License) bool { if license != nil { license.Features.SetDefaults() - if !license.IsExpired() { - a.Srv.licenseValue.Store(license) - a.Srv.clientLicenseValue.Store(utils.GetClientLicense(license)) - return true - } + a.Srv.licenseValue.Store(license) + a.Srv.clientLicenseValue.Store(utils.GetClientLicense(license)) + return true } a.Srv.licenseValue.Store((*model.License)(nil)) diff --git a/app/license_test.go b/app/license_test.go index 085adf04f8..225d4e54d9 100644 --- a/app/license_test.go +++ b/app/license_test.go @@ -53,15 +53,6 @@ func TestSetLicense(t *testing.T) { t.Fatal("license should have worked") } - l2 := &model.License{} - l2.Features = &model.Features{} - l2.Customer = &model.Customer{} - l2.StartsAt = model.GetMillis() - 1000 - l2.ExpiresAt = model.GetMillis() - 100 - if ok := th.App.SetLicense(l2); ok { - t.Fatal("license should have failed") - } - l3 := &model.License{} l3.Features = &model.Features{} l3.Customer = &model.Customer{}