Fix flaky TestRequestTrialLicense test (#18259)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
eaa37b52ee
Коммит
4dc54004ec
@@ -6,17 +6,19 @@ package api4
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/app"
|
||||||
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
"github.com/mattermost/mattermost-server/v6/utils"
|
"github.com/mattermost/mattermost-server/v6/utils"
|
||||||
mocks2 "github.com/mattermost/mattermost-server/v6/utils/mocks"
|
mocks2 "github.com/mattermost/mattermost-server/v6/utils/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v6/utils/testutils"
|
"github.com/mattermost/mattermost-server/v6/utils/testutils"
|
||||||
|
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetOldClientLicense(t *testing.T) {
|
func TestGetOldClientLicense(t *testing.T) {
|
||||||
@@ -219,8 +221,35 @@ func TestRequestTrialLicense(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("trial license user count less than current users", func(t *testing.T) {
|
t.Run("trial license user count less than current users", func(t *testing.T) {
|
||||||
t.Skip("MM-36695")
|
nUsers := 1
|
||||||
resp, err := th.SystemAdminClient.RequestTrialLicense(1)
|
license := model.NewTestLicense()
|
||||||
|
license.Features.Users = model.NewInt(nUsers)
|
||||||
|
licenseStr := license.ToJson()
|
||||||
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
res.WriteHeader(http.StatusOK)
|
||||||
|
response := map[string]string{
|
||||||
|
"license": licenseStr,
|
||||||
|
}
|
||||||
|
err := json.NewEncoder(res).Encode(response)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}))
|
||||||
|
defer testServer.Close()
|
||||||
|
|
||||||
|
mockLicenseValidator := mocks2.LicenseValidatorIface{}
|
||||||
|
defer testutils.ResetLicenseValidator()
|
||||||
|
|
||||||
|
mockLicenseValidator.On("ValidateLicense", mock.Anything).Return(true, licenseStr)
|
||||||
|
utils.LicenseValidator = &mockLicenseValidator
|
||||||
|
licenseManagerMock := &mocks.LicenseInterface{}
|
||||||
|
licenseManagerMock.On("CanStartTrial").Return(true, nil).Once()
|
||||||
|
th.App.Srv().LicenseManager = licenseManagerMock
|
||||||
|
|
||||||
|
defer func(requestTrialURL string) {
|
||||||
|
app.RequestTrialURL = requestTrialURL
|
||||||
|
}(app.RequestTrialURL)
|
||||||
|
app.RequestTrialURL = testServer.URL
|
||||||
|
|
||||||
|
resp, err := th.SystemAdminClient.RequestTrialLicense(nUsers)
|
||||||
CheckErrorID(t, err, "api.license.add_license.unique_users.app_error")
|
CheckErrorID(t, err, "api.license.add_license.unique_users.app_error")
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
requestTrialURL = "https://customers.mattermost.com/api/v1/trials"
|
|
||||||
LicenseEnv = "MM_LICENSE"
|
LicenseEnv = "MM_LICENSE"
|
||||||
LicenseRenewalURL = "https://customers.mattermost.com/subscribe/renew"
|
LicenseRenewalURL = "https://customers.mattermost.com/subscribe/renew"
|
||||||
JWTDefaultTokenExpiration = 7 * 24 * time.Hour // 7 days of expiration
|
JWTDefaultTokenExpiration = 7 * 24 * time.Hour // 7 days of expiration
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var RequestTrialURL = "https://customers.mattermost.com/api/v1/trials"
|
||||||
|
|
||||||
// JWTClaims custom JWT claims with the needed information for the
|
// JWTClaims custom JWT claims with the needed information for the
|
||||||
// renewal process
|
// renewal process
|
||||||
type JWTClaims struct {
|
type JWTClaims struct {
|
||||||
@@ -253,7 +254,7 @@ func (s *Server) GetSanitizedClientLicense() map[string]string {
|
|||||||
|
|
||||||
// RequestTrialLicense request a trial license from the mattermost official license server
|
// RequestTrialLicense request a trial license from the mattermost official license server
|
||||||
func (s *Server) RequestTrialLicense(trialRequest *model.TrialLicenseRequest) *model.AppError {
|
func (s *Server) RequestTrialLicense(trialRequest *model.TrialLicenseRequest) *model.AppError {
|
||||||
resp, err := http.Post(requestTrialURL, "application/json", bytes.NewBuffer([]byte(trialRequest.ToJson())))
|
resp, err := http.Post(RequestTrialURL, "application/json", bytes.NewBuffer([]byte(trialRequest.ToJson())))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, err.Error(), http.StatusBadRequest)
|
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user