mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Posts * Add missing translation * Fix internal store marshaling * [MM-22051] Remove To/From JSON (Channels) (#18116) * Channels * Channel members * ChannelSearch * Channel categories, list, sidebar, stats, view * Fix conversions * [MM-22051] Remove To/From JSON (Users) (#18121) * User related structs * Fix return * Team related structures (#18127) * [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130) * Status * Bot * Reaction * Thread * FileInfo * Some fixes * Translations update from Weblate (#18143) * Translated using Weblate (German) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ * Translated using Weblate (German) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Translated using Weblate (English (Australia)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/ * Translated using Weblate (Bulgarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/ * Translated using Weblate (Japanese) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/ * Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/ Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> * [MM-22051] Remove To/From JSON methods from model (#18138) * Scheme * Role * Session * Config * Status * Fix logic * Emoji * GuestsInvite * Group * Command * ClusterInfo * License * Job * System * Plugin * Command2 * IncomingWebhook * OutgoingWebhook * Fix tests * Update traslation * Some fixes * Add missing return * Simplify * Make Config.ToJSONFiltered() return []byte * Make Busy.ToJSON() return []byte * Include error in log * Split logic * [MM-22051] Remove To/From JSON (final) (#18150) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * [MM-23280] Fix linting for ToJSON/FromJSON (#18153) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * Fix linting for ToJSON/FromJSON * Fix conversions Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
324 lines
8.5 KiB
Go
324 lines
8.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestLicenseFeaturesToMap(t *testing.T) {
|
|
f := Features{}
|
|
f.SetDefaults()
|
|
|
|
m := f.ToMap()
|
|
|
|
CheckTrue(t, m["ldap"].(bool))
|
|
CheckTrue(t, m["ldap_groups"].(bool))
|
|
CheckTrue(t, m["mfa"].(bool))
|
|
CheckTrue(t, m["google"].(bool))
|
|
CheckTrue(t, m["office365"].(bool))
|
|
CheckTrue(t, m["compliance"].(bool))
|
|
CheckTrue(t, m["cluster"].(bool))
|
|
CheckTrue(t, m["metrics"].(bool))
|
|
CheckTrue(t, m["mhpns"].(bool))
|
|
CheckTrue(t, m["saml"].(bool))
|
|
CheckTrue(t, m["elastic_search"].(bool))
|
|
CheckTrue(t, m["email_notification_contents"].(bool))
|
|
CheckTrue(t, m["data_retention"].(bool))
|
|
CheckTrue(t, m["message_export"].(bool))
|
|
CheckTrue(t, m["custom_permissions_schemes"].(bool))
|
|
CheckTrue(t, m["id_loaded"].(bool))
|
|
CheckTrue(t, m["future"].(bool))
|
|
CheckTrue(t, m["shared_channels"].(bool))
|
|
CheckTrue(t, m["remote_cluster_service"].(bool))
|
|
}
|
|
|
|
func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
|
f := Features{}
|
|
f.SetDefaults()
|
|
|
|
CheckInt(t, *f.Users, 0)
|
|
CheckTrue(t, *f.LDAP)
|
|
CheckTrue(t, *f.LDAPGroups)
|
|
CheckTrue(t, *f.MFA)
|
|
CheckTrue(t, *f.GoogleOAuth)
|
|
CheckTrue(t, *f.Office365OAuth)
|
|
CheckTrue(t, *f.Compliance)
|
|
CheckTrue(t, *f.Cluster)
|
|
CheckTrue(t, *f.Metrics)
|
|
CheckTrue(t, *f.MHPNS)
|
|
CheckTrue(t, *f.SAML)
|
|
CheckTrue(t, *f.Elasticsearch)
|
|
CheckTrue(t, *f.EmailNotificationContents)
|
|
CheckTrue(t, *f.DataRetention)
|
|
CheckTrue(t, *f.MessageExport)
|
|
CheckTrue(t, *f.CustomPermissionsSchemes)
|
|
CheckTrue(t, *f.GuestAccountsPermissions)
|
|
CheckTrue(t, *f.IDLoadedPushNotifications)
|
|
CheckTrue(t, *f.SharedChannels)
|
|
CheckTrue(t, *f.RemoteClusterService)
|
|
CheckTrue(t, *f.FutureFeatures)
|
|
|
|
f = Features{}
|
|
f.SetDefaults()
|
|
|
|
*f.Users = 300
|
|
*f.FutureFeatures = false
|
|
*f.LDAP = true
|
|
*f.LDAPGroups = true
|
|
*f.MFA = true
|
|
*f.GoogleOAuth = true
|
|
*f.Office365OAuth = true
|
|
*f.Compliance = true
|
|
*f.Cluster = true
|
|
*f.Metrics = true
|
|
*f.MHPNS = true
|
|
*f.SAML = true
|
|
*f.Elasticsearch = true
|
|
*f.DataRetention = true
|
|
*f.MessageExport = true
|
|
*f.CustomPermissionsSchemes = true
|
|
*f.GuestAccounts = true
|
|
*f.GuestAccountsPermissions = true
|
|
*f.EmailNotificationContents = true
|
|
*f.IDLoadedPushNotifications = true
|
|
*f.SharedChannels = true
|
|
|
|
f.SetDefaults()
|
|
|
|
CheckInt(t, *f.Users, 300)
|
|
CheckTrue(t, *f.LDAP)
|
|
CheckTrue(t, *f.LDAPGroups)
|
|
CheckTrue(t, *f.MFA)
|
|
CheckTrue(t, *f.GoogleOAuth)
|
|
CheckTrue(t, *f.Office365OAuth)
|
|
CheckTrue(t, *f.Compliance)
|
|
CheckTrue(t, *f.Cluster)
|
|
CheckTrue(t, *f.Metrics)
|
|
CheckTrue(t, *f.MHPNS)
|
|
CheckTrue(t, *f.SAML)
|
|
CheckTrue(t, *f.Elasticsearch)
|
|
CheckTrue(t, *f.EmailNotificationContents)
|
|
CheckTrue(t, *f.DataRetention)
|
|
CheckTrue(t, *f.MessageExport)
|
|
CheckTrue(t, *f.CustomPermissionsSchemes)
|
|
CheckTrue(t, *f.GuestAccounts)
|
|
CheckTrue(t, *f.GuestAccountsPermissions)
|
|
CheckTrue(t, *f.IDLoadedPushNotifications)
|
|
CheckTrue(t, *f.SharedChannels)
|
|
CheckTrue(t, *f.RemoteClusterService)
|
|
CheckFalse(t, *f.FutureFeatures)
|
|
}
|
|
|
|
func TestLicenseIsExpired(t *testing.T) {
|
|
l1 := License{}
|
|
l1.ExpiresAt = GetMillis() - 1000
|
|
assert.True(t, l1.IsExpired())
|
|
|
|
l1.ExpiresAt = GetMillis() + 10000
|
|
assert.False(t, l1.IsExpired())
|
|
}
|
|
|
|
func TestLicenseIsPastGracePeriod(t *testing.T) {
|
|
l1 := License{}
|
|
l1.ExpiresAt = GetMillis() - LicenseGracePeriod - 1000
|
|
assert.True(t, l1.IsPastGracePeriod())
|
|
|
|
l1.ExpiresAt = GetMillis() + 1000
|
|
assert.False(t, l1.IsPastGracePeriod())
|
|
}
|
|
|
|
func TestLicenseIsStarted(t *testing.T) {
|
|
l1 := License{}
|
|
l1.StartsAt = GetMillis() - 1000
|
|
|
|
assert.True(t, l1.IsStarted())
|
|
|
|
l1.StartsAt = GetMillis() + 10000
|
|
assert.False(t, l1.IsStarted())
|
|
}
|
|
|
|
func TestLicenseRecordIsValid(t *testing.T) {
|
|
lr := LicenseRecord{
|
|
CreateAt: GetMillis(),
|
|
Bytes: "asdfghjkl;",
|
|
}
|
|
|
|
err := lr.IsValid()
|
|
assert.NotNil(t, err)
|
|
|
|
lr.Id = NewId()
|
|
lr.CreateAt = 0
|
|
err = lr.IsValid()
|
|
assert.NotNil(t, err)
|
|
|
|
lr.CreateAt = GetMillis()
|
|
lr.Bytes = ""
|
|
err = lr.IsValid()
|
|
assert.NotNil(t, err)
|
|
|
|
lr.Bytes = strings.Repeat("0123456789", 1001)
|
|
err = lr.IsValid()
|
|
assert.NotNil(t, err)
|
|
|
|
lr.Bytes = "ASDFGHJKL;"
|
|
err = lr.IsValid()
|
|
assert.Nil(t, err)
|
|
}
|
|
|
|
func TestLicenseRecordPreSave(t *testing.T) {
|
|
lr := LicenseRecord{}
|
|
lr.PreSave()
|
|
|
|
assert.NotZero(t, lr.CreateAt)
|
|
}
|
|
|
|
func TestLicense_IsTrialLicense(t *testing.T) {
|
|
t.Run("detect trial license directly from the flag", func(t *testing.T) {
|
|
license := &License{
|
|
IsTrial: true,
|
|
}
|
|
assert.True(t, license.IsTrial)
|
|
|
|
license.IsTrial = false
|
|
assert.False(t, license.IsTrialLicense())
|
|
})
|
|
|
|
t.Run("detect trial license form duration", func(t *testing.T) {
|
|
startDate, err := time.Parse(time.RFC822, "01 Jan 21 00:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
endDate, err := time.Parse(time.RFC822, "31 Jan 21 08:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
license := &License{
|
|
StartsAt: startDate.UnixNano() / int64(time.Millisecond),
|
|
ExpiresAt: endDate.UnixNano() / int64(time.Millisecond),
|
|
}
|
|
assert.True(t, license.IsTrialLicense())
|
|
|
|
endDate, err = time.Parse(time.RFC822, "01 Feb 21 08:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
license.ExpiresAt = endDate.UnixNano() / int64(time.Millisecond)
|
|
assert.False(t, license.IsTrialLicense())
|
|
|
|
// 30 days + 23 hours 59 mins 59 seconds
|
|
endDate, err = time.Parse("02 Jan 06 15:04:05 MST", "31 Jan 21 23:59:59 UTC")
|
|
assert.NoError(t, err)
|
|
license.ExpiresAt = endDate.UnixNano() / int64(time.Millisecond)
|
|
assert.True(t, license.IsTrialLicense())
|
|
})
|
|
|
|
t.Run("detect trial with both flag and duration", func(t *testing.T) {
|
|
startDate, err := time.Parse(time.RFC822, "01 Jan 21 00:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
endDate, err := time.Parse(time.RFC822, "31 Jan 21 08:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
license := &License{
|
|
IsTrial: true,
|
|
StartsAt: startDate.UnixNano() / int64(time.Millisecond),
|
|
ExpiresAt: endDate.UnixNano() / int64(time.Millisecond),
|
|
}
|
|
|
|
assert.True(t, license.IsTrialLicense())
|
|
license.IsTrial = false
|
|
|
|
// detecting trial from duration
|
|
assert.True(t, license.IsTrialLicense())
|
|
|
|
endDate, _ = time.Parse(time.RFC822, "1 Feb 2021 08:00 UTC")
|
|
license.ExpiresAt = endDate.UnixNano() / int64(time.Millisecond)
|
|
assert.False(t, license.IsTrialLicense())
|
|
|
|
license.IsTrial = true
|
|
assert.True(t, license.IsTrialLicense())
|
|
})
|
|
}
|
|
|
|
func TestLicense_IsSanctionedTrial(t *testing.T) {
|
|
t.Run("short duration sanctioned trial", func(t *testing.T) {
|
|
startDate, err := time.Parse(time.RFC822, "01 Jan 21 00:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
endDate, err := time.Parse(time.RFC822, "08 Jan 21 08:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
license := &License{
|
|
IsTrial: true,
|
|
StartsAt: startDate.UnixNano() / int64(time.Millisecond),
|
|
ExpiresAt: endDate.UnixNano() / int64(time.Millisecond),
|
|
}
|
|
|
|
assert.True(t, license.IsSanctionedTrial())
|
|
|
|
license.IsTrial = false
|
|
assert.False(t, license.IsSanctionedTrial())
|
|
})
|
|
|
|
t.Run("long duration sanctioned trial", func(t *testing.T) {
|
|
startDate, err := time.Parse(time.RFC822, "01 Jan 21 00:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
endDate, err := time.Parse(time.RFC822, "02 Feb 21 08:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
license := &License{
|
|
IsTrial: true,
|
|
StartsAt: startDate.UnixNano() / int64(time.Millisecond),
|
|
ExpiresAt: endDate.UnixNano() / int64(time.Millisecond),
|
|
}
|
|
|
|
assert.True(t, license.IsSanctionedTrial())
|
|
|
|
license.IsTrial = false
|
|
assert.False(t, license.IsSanctionedTrial())
|
|
})
|
|
|
|
t.Run("invalid duration for sanctioned trial", func(t *testing.T) {
|
|
startDate, err := time.Parse(time.RFC822, "01 Jan 21 00:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
endDate, err := time.Parse(time.RFC822, "31 Jan 21 08:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
license := &License{
|
|
IsTrial: true,
|
|
StartsAt: startDate.UnixNano() / int64(time.Millisecond),
|
|
ExpiresAt: endDate.UnixNano() / int64(time.Millisecond),
|
|
}
|
|
|
|
assert.False(t, license.IsSanctionedTrial())
|
|
})
|
|
|
|
t.Run("boundary conditions for sanctioned trial", func(t *testing.T) {
|
|
startDate, err := time.Parse(time.RFC822, "01 Jan 21 00:00 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
// 29 days + 23 hours 59 mins 59 seconds
|
|
endDate, err := time.Parse("02 Jan 06 15:04:05 MST", "30 Jan 21 23:59:59 UTC")
|
|
assert.NoError(t, err)
|
|
|
|
license := &License{
|
|
IsTrial: true,
|
|
StartsAt: startDate.UnixNano() / int64(time.Millisecond),
|
|
ExpiresAt: endDate.UnixNano() / int64(time.Millisecond),
|
|
}
|
|
|
|
assert.True(t, license.IsSanctionedTrial())
|
|
|
|
// 31 days + 23 hours 59 mins 59 seconds
|
|
endDate, err = time.Parse("02 Jan 06 15:04:05 MST", "01 Feb 21 23:59:59 UTC")
|
|
assert.NoError(t, err)
|
|
license.ExpiresAt = endDate.UnixNano() / int64(time.Millisecond)
|
|
assert.True(t, license.IsSanctionedTrial())
|
|
})
|
|
}
|