Reject mysql for enterprise advanced (#31164)

* reject MySQL with the enterprise advanced license

If a user attempts to set an Enterprise Advanced License while
configured with MySQL, reject the license. This SKU is not compatible
with MYSQL.

* fix trial typo

* suppress trial banner if MySQL

* Update server/channels/app/platform/license_test.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix types

* suppress mysql from show start trial modal

* Skip MySQL-incompatible tests for access control and channel banner features

Skip the following tests when running with MySQL database:
- Access control policy tests (create, get, delete, check/test expressions, search, assign/unassign, get channels)
- Channel banner tests in TestPatchChannel and TestCanEditChannelBanner

These features are not supported on MySQL and the tests would fail.
Tests will continue to run normally on PostgreSQL.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Skip TestSearchChannelsForAccessControlPolicy subtest for MySQL

Add MySQL skip logic to the "SearchChannelsForAccessControlPolicy with regular user"
subtest as this access control feature is not supported on MySQL.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* reject trial license requests for MySQL

* return false on sku + mysql match, even if logger is nil

* Fix MySQL trial license tests to skip appropriately based on database driver

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Этот коммит содержится в:
Jesse Hallam
2025-05-26 15:44:32 -03:00
коммит произвёл GitHub
родитель f2bb82bc01
Коммит 70a42ffd5f
14 изменённых файлов: 244 добавлений и 5 удалений

Просмотреть файл

@@ -134,6 +134,10 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(errors.New("license.Features.Users is nil"))
}
if license.SkuShortName == model.LicenseShortSkuEnterpriseAdvanced && *ps.Config().SqlSettings.DriverName == model.DatabaseDriverMysql {
return nil, model.NewAppError("addLicense", "api.license.add_license.mysql.app_error", nil, "", http.StatusBadRequest).Wrap(errors.New("mysql is not supported for this license"))
}
uniqueUserCount, err := ps.Store.User().Count(model.UserCountOptions{})
if err != nil {
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, "", http.StatusBadRequest).Wrap(err)
@@ -225,6 +229,13 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo
}
func (ps *PlatformService) SetLicense(license *model.License) bool {
if license != nil && license.SkuShortName == model.LicenseShortSkuEnterpriseAdvanced && *ps.Config().SqlSettings.DriverName == model.DatabaseDriverMysql {
if ps.logger != nil {
ps.logger.Error("MySQL is not supported for this license", mlog.String("sku_short_name", license.SkuShortName))
}
return false
}
oldLicense := ps.licenseValue.Load()
defer func() {

Просмотреть файл

@@ -4,12 +4,17 @@
package platform
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin/plugintest/mock"
"github.com/mattermost/mattermost/server/v8/channels/utils"
mocks2 "github.com/mattermost/mattermost/server/v8/channels/utils/mocks"
"github.com/mattermost/mattermost/server/v8/channels/utils/testutils"
)
func TestLoadLicense(t *testing.T) {
@@ -30,6 +35,45 @@ func TestSaveLicense(t *testing.T) {
require.NotNil(t, err, "shouldn't have saved license")
}
func TestSaveEnterpriseAdvancedLicense(t *testing.T) {
th := Setup(t)
defer th.TearDown()
defer testutils.ResetLicenseValidator()
mockLicenseValidator := mocks2.LicenseValidatorIface{}
license := &model.License{
Id: model.NewId(),
Features: &model.Features{
Users: model.NewPointer(100),
},
Customer: &model.Customer{
Name: "TestName",
Email: "test@example.com",
},
SkuName: "SKU NAME",
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
StartsAt: model.GetMillis() - 1000,
ExpiresAt: model.GetMillis() + 100000,
}
mockLicenseValidator.On("LicenseFromBytes", mock.Anything).Return(license, nil).Once()
licenseBytes, err := json.Marshal(license)
require.NoError(t, err)
mockLicenseValidator.On("ValidateLicense", mock.Anything).Return(string(licenseBytes), nil)
utils.LicenseValidator = &mockLicenseValidator
_, appErr := th.Service.SaveLicense(licenseBytes)
if *th.Service.Config().SqlSettings.DriverName == model.DatabaseDriverMysql {
require.NotNil(t, appErr, "shouldn't have saved license")
require.Equal(t, "addLicense: api.license.add_license.mysql.app_error, mysql is not supported for this license", appErr.Error())
} else {
require.Nil(t, appErr, "should have saved license")
}
}
func TestRemoveLicense(t *testing.T) {
th := Setup(t)
defer th.TearDown()