MM-34437 Preventing infinite trial requests (#17472)
* MM-34434: Added 'is_trial' boolean to all trial license requests and to the License struct. * MM-34434: Generalized the concept of a license request. * MM-34434: Verifies JSON field of license instance is set. * MM-34434: Added missing client param. * MM-34434: Added some tests of the request trial API endpoint. * MM-34434: Removed comment. * fix broken test (#17348) * Add missing wrapped errors (#17339) * Improve document extraction and including a document extraction command (#17183) * Add extract documents content command * Adding the extraction command and making the pure go pdf library as secondary option * Improving the memory usage and docextractor interface * Enable content extraction by default in all the instances * Tiny improvement on archive indexing * Adding App interface generation and the opentracing layer * Fixing linter errors * Addressing PR review comments * Addressing PR review comments * Update en.json (#17356) Automatic Merge * adding new feature flag (#17308) Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> * Bump no_output_timeout to 2 hours (#17358) * log invalid username (#17345) Automatic Merge * MM-34434: Added missing client param. MM-34434: Added some tests of the request trial API endpoint. MM-34434: Removed comment. * MM-34434: Switched to a hard-coded true value. * MM-34434: Reverts test change. * MM-34434: Removes unnecessary field. * MM-34434: Tests that is_trial is hard-coded by TrialLicenseRequest. * MM-34434: Removed accidental commit. * MM-34434: Removes unnecessary is_trial key from JSON payload. * MM-34434: Reverts to old pointer receiver variable name. * MM-34434: Removes test. * #MM-34437 Initialized license service * ##MM-34437 Verified at all points if server is trial elligible * WIp * #MM-34437 removed unused commented code * MM-34437 make a log less severe * #MM-34437 generated einterface mocks * #MM-34437 added license on new file * #MM-34437 removed unused translation * #MM-34437 some refactoring * Update api4/license.go * Update api4/license.go * #MM-34437 made a variable name consistent * #MM-34437 Added mocks for lince validator * #M--34437 Added license validator test framework * #MM-34437 Renamed isTrial method to isTrialLicense to avoid conflict with newlya dded field * #M--34437 Allowed sales-sanctioned trials * #MM-34437 fixed trial license API tests * Added tests for add license API * #MM-34437 fixed ValidateLicense test * #MM-34437 Added util tests * #MM-34437 using NoError for checking no error * #MM-34437 using NoError for checking no error * Added dummy piblic key for testing * Fixed tests * #MM-34437 udpaetd trial license URL for testing * #MM-34437 adjusted times for licences generated through admin portal * Reverted test-only changes Co-authored-by: Martin Kraft <martin@upspin.org> Co-authored-by: Hossein <hahmadia@users.noreply.github.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Jesús Espino <jespinog@gmail.com> Co-authored-by: Amy Blais <amy_blais@hotmail.com> Co-authored-by: Ben Cooke <benkcooke@gmail.com> Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Max Erenberg <max.erenberg@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6bb1cbca63
Коммит
e4aa729a0c
@@ -181,6 +181,12 @@ func RegisterNotificationInterface(f func(*Server) einterfaces.NotificationInter
|
||||
notificationInterface = f
|
||||
}
|
||||
|
||||
var licenseInterface func(*Server) einterfaces.LicenseInterface
|
||||
|
||||
func RegisterLicenseInterface(f func(*Server) einterfaces.LicenseInterface) {
|
||||
licenseInterface = f
|
||||
}
|
||||
|
||||
func (s *Server) initEnterprise() {
|
||||
if metricsInterface != nil {
|
||||
s.Metrics = metricsInterface(s)
|
||||
@@ -200,6 +206,11 @@ func (s *Server) initEnterprise() {
|
||||
if elasticsearchInterface != nil {
|
||||
s.SearchEngine.RegisterElasticsearchEngine(elasticsearchInterface(s))
|
||||
}
|
||||
|
||||
if licenseInterface != nil {
|
||||
s.LicenseManager = licenseInterface(s)
|
||||
}
|
||||
|
||||
if accountMigrationInterface != nil {
|
||||
s.AccountMigration = accountMigrationInterface(s)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,26 @@ func (s *Server) LoadLicense() {
|
||||
// ENV var overrides all other sources of license.
|
||||
licenseStr := os.Getenv(LicenseEnv)
|
||||
if licenseStr != "" {
|
||||
license, err := utils.LicenseValidator.LicenseFromBytes([]byte(licenseStr))
|
||||
if err != nil {
|
||||
mlog.Error("Failed to read license set in environment.", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
||||
// skip the restrictions if license is a sanctioned trial
|
||||
if !license.IsSanctionedTrial() && license.IsTrialLicense() {
|
||||
canStartTrialLicense, err := s.LicenseManager.CanStartTrial()
|
||||
if err != nil {
|
||||
mlog.Info("Failed to validate trial eligibility.", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !canStartTrialLicense {
|
||||
mlog.Info("Cannot start trial multiple times.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if s.ValidateAndSetLicenseBytes([]byte(licenseStr)) {
|
||||
mlog.Info("License key from ENV is valid, unlocking enterprise features.")
|
||||
}
|
||||
@@ -75,7 +95,7 @@ func (s *Server) LoadLicense() {
|
||||
}
|
||||
|
||||
func (s *Server) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) {
|
||||
success, licenseStr := utils.ValidateLicense(licenseBytes)
|
||||
success, licenseStr := utils.LicenseValidator.ValidateLicense(licenseBytes)
|
||||
if !success {
|
||||
return nil, model.NewAppError("addLicense", model.INVALID_LICENSE_ERROR, nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -174,7 +194,7 @@ func (s *Server) SetLicense(license *model.License) bool {
|
||||
}
|
||||
|
||||
func (s *Server) ValidateAndSetLicenseBytes(b []byte) bool {
|
||||
if success, licenseStr := utils.ValidateLicense(b); success {
|
||||
if success, licenseStr := utils.LicenseValidator.ValidateLicense(b); success {
|
||||
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||
s.SetLicense(license)
|
||||
return true
|
||||
@@ -228,22 +248,7 @@ func (s *Server) RemoveLicenseListener(id string) {
|
||||
}
|
||||
|
||||
func (s *Server) GetSanitizedClientLicense() map[string]string {
|
||||
sanitizedLicense := make(map[string]string)
|
||||
|
||||
for k, v := range s.ClientLicense() {
|
||||
sanitizedLicense[k] = v
|
||||
}
|
||||
|
||||
delete(sanitizedLicense, "Id")
|
||||
delete(sanitizedLicense, "Name")
|
||||
delete(sanitizedLicense, "Email")
|
||||
delete(sanitizedLicense, "IssuedAt")
|
||||
delete(sanitizedLicense, "StartsAt")
|
||||
delete(sanitizedLicense, "ExpiresAt")
|
||||
delete(sanitizedLicense, "SkuName")
|
||||
delete(sanitizedLicense, "SkuShortName")
|
||||
|
||||
return sanitizedLicense
|
||||
return utils.GetSanitizedClientLicense(s.ClientLicense())
|
||||
}
|
||||
|
||||
// RequestTrialLicense request a trial license from the mattermost official license server
|
||||
|
||||
@@ -191,6 +191,7 @@ type Server struct {
|
||||
Metrics einterfaces.MetricsInterface
|
||||
Notification einterfaces.NotificationInterface
|
||||
Saml einterfaces.SamlInterface
|
||||
LicenseManager einterfaces.LicenseInterface
|
||||
|
||||
CacheProvider cache.Provider
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user