Files
mattermost/model/license_test.go
Jesús Espino fe8a0f6485 Guest accounts feature (#11428)
* MM-14139: Creating permissions for invite/promote/demote guests (#10778)

* MM-14139: Creating permissions for invite/promote/demote guests

* Fixing tests

* Adding invite guest api endpoint (#10792)

* Adding invite guest api endpoint

* Adding i18n

* Adding some tests

* WIP

* Migrating Token.Extra info to bigger size (2048)

* Fixing tests

* Adding client function for invite guests

* Adding send guests invites tests

* Renaming file from guest to guest_invite

* Adding Promote/Demote users from/to guest endpoints (#10791)

* Adding Promote/Demote users from/to guest endpoints

* Adding i18n translations

* Adding the client functions

* Using getQueryBuilder function

* Addressing PR review comments

* Adding default channels to users on promte from guest (#10851)

* Adding default channels to users on promte from guest

* Addressing PR review comments

* Fixing merge problems

* Sending websockets events on promote/demote (#11403)

* Sending websockets events on promote/demote

* Fixing merge problems

* Fixing govet shadowing problem

* Fixing feature branch tests

* Avoiding leaking users data through websockets for guest accounts (#11489)

* Avoiding leaking users data through websockets for guest accounts

* Adding tests and fixing code error

* Fixing i18n

* Allow to enable/disable guests and other extra config settings (#11481)

* Allow to enable/disable guests and other extra config settings

* Fixing tests and moving license and config validation to api level

* Update api4/role_test.go

Co-Authored-By: George Goldberg <george@gberg.me>

* Update api4/role_test.go

Co-Authored-By: George Goldberg <george@gberg.me>

* Fixing typo

* fixing tests

* Managing correctly the guest channel leave behavior (#11578)

* MM-15134: Removing guests from teams or system on leave channels if needed

* WIP

* No deactivating the guest user when leave the last team

* Adding a couple of tests

* Fixing shadow variables

* Fixing tests

* fixing tests

* fixing shadow variables

* Adding guest counts for channel stats (#11646)

* Adding guest counts for channel stats

* Adding tests

* Fixing tests

* Fixing guest domain restrictions (#11660)

* Adding needed migration for the database

* Fixing migration
2019-07-22 22:13:39 +02:00

233 lines
5.6 KiB
Go

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"strings"
"testing"
)
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["future"].(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.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.GuestAccountsPermissions = true
*f.EmailNotificationContents = 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.GuestAccountsPermissions)
CheckFalse(t, *f.FutureFeatures)
}
func TestLicenseIsExpired(t *testing.T) {
l1 := License{}
l1.ExpiresAt = GetMillis() - 1000
if !l1.IsExpired() {
t.Fatal("license should be expired")
}
l1.ExpiresAt = GetMillis() + 10000
if l1.IsExpired() {
t.Fatal("license should not be expired")
}
}
func TestLicenseIsStarted(t *testing.T) {
l1 := License{}
l1.StartsAt = GetMillis() - 1000
if !l1.IsStarted() {
t.Fatal("license should be started")
}
l1.StartsAt = GetMillis() + 10000
if l1.IsStarted() {
t.Fatal("license should not be started")
}
}
func TestLicenseToFromJson(t *testing.T) {
f := Features{}
f.SetDefaults()
l := License{
Id: NewId(),
IssuedAt: GetMillis(),
StartsAt: GetMillis(),
ExpiresAt: GetMillis(),
Customer: &Customer{
Id: NewId(),
Name: NewId(),
Email: NewId(),
Company: NewId(),
PhoneNumber: NewId(),
},
Features: &f,
}
j := l.ToJson()
l1 := LicenseFromJson(strings.NewReader(j))
if l1 == nil {
t.Fatalf("Decoding failed but should have passed.")
}
CheckString(t, l1.Id, l.Id)
CheckInt64(t, l1.IssuedAt, l.IssuedAt)
CheckInt64(t, l1.StartsAt, l.StartsAt)
CheckInt64(t, l1.ExpiresAt, l.ExpiresAt)
CheckString(t, l1.Customer.Id, l.Customer.Id)
CheckString(t, l1.Customer.Name, l.Customer.Name)
CheckString(t, l1.Customer.Email, l.Customer.Email)
CheckString(t, l1.Customer.Company, l.Customer.Company)
CheckString(t, l1.Customer.PhoneNumber, l.Customer.PhoneNumber)
f1 := l1.Features
CheckInt(t, *f1.Users, *f.Users)
CheckBool(t, *f1.LDAP, *f.LDAP)
CheckBool(t, *f1.LDAPGroups, *f.LDAPGroups)
CheckBool(t, *f1.MFA, *f.MFA)
CheckBool(t, *f1.GoogleOAuth, *f.GoogleOAuth)
CheckBool(t, *f1.Office365OAuth, *f.Office365OAuth)
CheckBool(t, *f1.Compliance, *f.Compliance)
CheckBool(t, *f1.Cluster, *f.Cluster)
CheckBool(t, *f1.Metrics, *f.Metrics)
CheckBool(t, *f1.MHPNS, *f.MHPNS)
CheckBool(t, *f1.SAML, *f.SAML)
CheckBool(t, *f1.Elasticsearch, *f.Elasticsearch)
CheckBool(t, *f1.DataRetention, *f.DataRetention)
CheckBool(t, *f1.MessageExport, *f.MessageExport)
CheckBool(t, *f1.CustomPermissionsSchemes, *f.CustomPermissionsSchemes)
CheckBool(t, *f1.GuestAccountsPermissions, *f.GuestAccountsPermissions)
CheckBool(t, *f1.FutureFeatures, *f.FutureFeatures)
invalid := `{"asdf`
l2 := LicenseFromJson(strings.NewReader(invalid))
if l2 != nil {
t.Fatalf("Should have failed but didn't")
}
}
func TestLicenseRecordIsValid(t *testing.T) {
lr := LicenseRecord{
CreateAt: GetMillis(),
Bytes: "asdfghjkl;",
}
if err := lr.IsValid(); err == nil {
t.Fatalf("Should have been invalid")
}
lr.Id = NewId()
lr.CreateAt = 0
if err := lr.IsValid(); err == nil {
t.Fatalf("Should have been invalid")
}
lr.CreateAt = GetMillis()
lr.Bytes = ""
if err := lr.IsValid(); err == nil {
t.Fatalf("Should have been invalid")
}
lr.Bytes = strings.Repeat("0123456789", 1001)
if err := lr.IsValid(); err == nil {
t.Fatalf("Should have been invalid")
}
lr.Bytes = "ASDFGHJKL;"
if err := lr.IsValid(); err != nil {
t.Fatal(err)
}
}
func TestLicenseRecordPreSave(t *testing.T) {
lr := LicenseRecord{}
lr.PreSave()
if lr.CreateAt == 0 {
t.Fatal("CreateAt should not be zero")
}
}