Merge branch 'master' into mark-as-unread
Этот коммит содержится в:
@@ -6,14 +6,13 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAuditJson(t *testing.T) {
|
||||
audit := Audit{Id: NewId(), UserId: NewId(), CreateAt: GetMillis()}
|
||||
json := audit.ToJson()
|
||||
result := AuditFromJson(strings.NewReader(json))
|
||||
|
||||
if audit.Id != result.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, audit.Id, result.Id, "Ids do not match")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAuditsJson(t *testing.T) {
|
||||
@@ -13,9 +15,7 @@ func TestAuditsJson(t *testing.T) {
|
||||
json := audit.ToJson()
|
||||
result := AuditFromJson(strings.NewReader(json))
|
||||
|
||||
if audit.Id != result.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, audit.Id, result.Id, "Ids do not match")
|
||||
|
||||
var audits Audits = make([]Audit, 1)
|
||||
audits[0] = audit
|
||||
@@ -23,7 +23,5 @@ func TestAuditsJson(t *testing.T) {
|
||||
ljson := audits.ToJson()
|
||||
results := AuditsFromJson(strings.NewReader(ljson))
|
||||
|
||||
if audits[0].Id != results[0].Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, audits[0].Id, results[0].Id, "Ids do not match")
|
||||
}
|
||||
|
||||
@@ -18,10 +18,7 @@ func TestAuthJson(t *testing.T) {
|
||||
|
||||
json := a1.ToJson()
|
||||
ra1 := AuthDataFromJson(strings.NewReader(json))
|
||||
|
||||
if a1.Code != ra1.Code {
|
||||
t.Fatal("codes didn't match")
|
||||
}
|
||||
require.Equal(t, a1.Code, ra1.Code, "codes didn't match")
|
||||
|
||||
a2 := AuthorizeRequest{}
|
||||
a2.ClientId = NewId()
|
||||
@@ -30,9 +27,7 @@ func TestAuthJson(t *testing.T) {
|
||||
json = a2.ToJson()
|
||||
ra2 := AuthorizeRequestFromJson(strings.NewReader(json))
|
||||
|
||||
if a2.ClientId != ra2.ClientId {
|
||||
t.Fatal("client ids didn't match")
|
||||
}
|
||||
require.Equal(t, a2.ClientId, ra2.ClientId, "client ids didn't match")
|
||||
}
|
||||
|
||||
func TestAuthPreSave(t *testing.T) {
|
||||
@@ -51,85 +46,59 @@ func TestAuthIsValid(t *testing.T) {
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.ClientId = NewRandomString(28)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Client Id")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Client Id")
|
||||
|
||||
ad.ClientId = NewId()
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.UserId = NewRandomString(28)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed User Id")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed User Id")
|
||||
|
||||
ad.UserId = NewId()
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.Code = NewRandomString(129)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Code to long")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Code to long")
|
||||
|
||||
ad.Code = ""
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Code not set")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Code not set")
|
||||
|
||||
ad.Code = NewId()
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.ExpiresIn = 0
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid ExpiresIn")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid ExpiresIn")
|
||||
|
||||
ad.ExpiresIn = 1
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.CreateAt = 0
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Invalid Create At")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Invalid Create At")
|
||||
|
||||
ad.CreateAt = 1
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.State = NewRandomString(129)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid State")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid State")
|
||||
|
||||
ad.State = NewRandomString(128)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.Scope = NewRandomString(1025)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid Scope")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid Scope")
|
||||
|
||||
ad.Scope = NewRandomString(128)
|
||||
require.NotNil(t, ad.IsValid())
|
||||
|
||||
ad.RedirectUri = ""
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed Redirect URI not set")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed Redirect URI not set")
|
||||
|
||||
ad.RedirectUri = NewRandomString(28)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid URL")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid URL")
|
||||
|
||||
ad.RedirectUri = NewRandomString(257)
|
||||
if err := ad.IsValid(); err == nil {
|
||||
t.Fatal("Should have failed invalid URL")
|
||||
}
|
||||
require.NotNil(t, ad.IsValid(), "Should have failed invalid URL")
|
||||
|
||||
ad.RedirectUri = "http://example.com"
|
||||
if err := ad.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, ad.IsValid())
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestChannelSearchJson(t *testing.T) {
|
||||
@@ -13,7 +15,5 @@ func TestChannelSearchJson(t *testing.T) {
|
||||
json := channelSearch.ToJson()
|
||||
rchannelSearch := ChannelSearchFromJson(strings.NewReader(json))
|
||||
|
||||
if channelSearch.Term != rchannelSearch.Term {
|
||||
t.Fatal("Terms do not match")
|
||||
}
|
||||
assert.Equal(t, channelSearch.Term, rchannelSearch.Term)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClusterDiscovery(t *testing.T) {
|
||||
@@ -18,9 +20,8 @@ func TestClusterDiscovery(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
result1 := ClusterDiscoveryFromJson(strings.NewReader(json))
|
||||
|
||||
if result1.ClusterName != "cluster_name" {
|
||||
t.Fatal("should be set")
|
||||
}
|
||||
assert.NotNil(t, result1)
|
||||
assert.Equal(t, "cluster_name", result1.ClusterName)
|
||||
|
||||
result2 := ClusterDiscoveryFromJson(strings.NewReader(json))
|
||||
result3 := ClusterDiscoveryFromJson(strings.NewReader(json))
|
||||
@@ -31,9 +32,7 @@ func TestClusterDiscovery(t *testing.T) {
|
||||
result3.Id = "3"
|
||||
result3.Hostname = "something_diff"
|
||||
|
||||
if !o.IsEqual(result1) {
|
||||
t.Fatal("Should be equal")
|
||||
}
|
||||
assert.True(t, o.IsEqual(result1))
|
||||
|
||||
list := make([]*ClusterDiscovery, 0)
|
||||
list = append(list, &o)
|
||||
@@ -45,9 +44,7 @@ func TestClusterDiscovery(t *testing.T) {
|
||||
return !o.IsEqual(in)
|
||||
})
|
||||
|
||||
if len(rlist) != 1 {
|
||||
t.Fatal("should only have 1 result")
|
||||
}
|
||||
assert.Len(t, rlist, 1)
|
||||
|
||||
o.AutoFillHostname()
|
||||
o.Hostname = ""
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClusterInfoJson(t *testing.T) {
|
||||
@@ -13,9 +15,7 @@ func TestClusterInfoJson(t *testing.T) {
|
||||
json := cluster.ToJson()
|
||||
result := ClusterInfoFromJson(strings.NewReader(json))
|
||||
|
||||
if cluster.IpAddress != result.IpAddress {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
assert.Equal(t, cluster.IpAddress, result.IpAddress, "Ids do not match")
|
||||
}
|
||||
|
||||
func TestClusterInfosJson(t *testing.T) {
|
||||
@@ -25,7 +25,5 @@ func TestClusterInfosJson(t *testing.T) {
|
||||
json := ClusterInfosToJson(clusterInfos)
|
||||
result := ClusterInfosFromJson(strings.NewReader(json))
|
||||
|
||||
if clusterInfos[0].IpAddress != result[0].IpAddress {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
assert.Equal(t, clusterInfos[0].IpAddress, result[0].IpAddress, "Ids do not match")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCommandJson(t *testing.T) {
|
||||
@@ -13,9 +15,7 @@ func TestCommandJson(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
ro := CommandFromJson(strings.NewReader(json))
|
||||
|
||||
if o.Id != ro.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, o.Id, ro.Id, "Ids do not match")
|
||||
}
|
||||
|
||||
func TestCommandIsValid(t *testing.T) {
|
||||
@@ -33,134 +33,82 @@ func TestCommandIsValid(t *testing.T) {
|
||||
Description: "",
|
||||
}
|
||||
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Id = ""
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.Id = NewId()
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Token = ""
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.Token = NewId()
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.CreateAt = 0
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.UpdateAt = 0
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.UpdateAt = GetMillis()
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.CreatorId = ""
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.CreatorId = NewId()
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.TeamId = ""
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.TeamId = NewId()
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Trigger = ""
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.Trigger = strings.Repeat("1", 129)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.Trigger = strings.Repeat("1", 128)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.URL = ""
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.URL = "1234"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.URL = "https://example.com"
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Method = "https://example.com"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.Method = COMMAND_METHOD_GET
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Method = COMMAND_METHOD_POST
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.DisplayName = strings.Repeat("1", 65)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.DisplayName = strings.Repeat("1", 64)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Description = strings.Repeat("1", 129)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.Description = strings.Repeat("1", 128)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
}
|
||||
|
||||
func TestCommandPreSave(t *testing.T) {
|
||||
|
||||
@@ -5,17 +5,17 @@ package model
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCommandWebhookPreSave(t *testing.T) {
|
||||
h := CommandWebhook{}
|
||||
h.PreSave()
|
||||
if len(h.Id) != 26 {
|
||||
t.Fatal("Id should be generated")
|
||||
}
|
||||
if h.CreateAt == 0 {
|
||||
t.Fatal("CreateAt should be set")
|
||||
}
|
||||
|
||||
require.Len(t, h.Id, 26, "Id should be generated")
|
||||
require.NotEqual(t, 0, h.CreateAt, "CreateAt should be set")
|
||||
}
|
||||
|
||||
func TestCommandWebhookIsValid(t *testing.T) {
|
||||
@@ -44,11 +44,14 @@ func TestCommandWebhookIsValid(t *testing.T) {
|
||||
tmp := h
|
||||
test.Transform()
|
||||
err := h.IsValid()
|
||||
if test.ExpectedError == "" && err != nil {
|
||||
t.Fatal("hook should be valid")
|
||||
} else if test.ExpectedError != "" && test.ExpectedError != err.Id {
|
||||
t.Fatal("expected " + test.ExpectedError + " error")
|
||||
|
||||
if test.ExpectedError == "" {
|
||||
assert.Error(t, err, "hook should be valid")
|
||||
} else {
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, test.ExpectedError, err.Id, "expected "+test.ExpectedError+" error")
|
||||
}
|
||||
|
||||
h = tmp
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCompliance(t *testing.T) {
|
||||
@@ -13,7 +15,5 @@ func TestCompliance(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
result := ComplianceFromJson(strings.NewReader(json))
|
||||
|
||||
if o.Desc != result.Desc {
|
||||
t.Fatal("JobName do not match")
|
||||
}
|
||||
require.Equal(t, o.Desc, result.Desc, "JobName do not match")
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ const (
|
||||
LDAP_SETTINGS_DEFAULT_GROUP_ID_ATTRIBUTE = ""
|
||||
|
||||
SAML_SETTINGS_DEFAULT_ID_ATTRIBUTE = ""
|
||||
SAML_SETTINGS_DEFAULT_GUEST_ATTRIBUTE = ""
|
||||
SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE = ""
|
||||
SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE = ""
|
||||
SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE = ""
|
||||
@@ -1907,6 +1908,7 @@ type SamlSettings struct {
|
||||
|
||||
// User Mapping
|
||||
IdAttribute *string
|
||||
GuestAttribute *string
|
||||
FirstNameAttribute *string
|
||||
LastNameAttribute *string
|
||||
EmailAttribute *string
|
||||
@@ -1999,6 +2001,9 @@ func (s *SamlSettings) SetDefaults() {
|
||||
s.IdAttribute = NewString(SAML_SETTINGS_DEFAULT_ID_ATTRIBUTE)
|
||||
}
|
||||
|
||||
if s.GuestAttribute == nil {
|
||||
s.GuestAttribute = NewString(SAML_SETTINGS_DEFAULT_GUEST_ATTRIBUTE)
|
||||
}
|
||||
if s.FirstNameAttribute == nil {
|
||||
s.FirstNameAttribute = NewString(SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE)
|
||||
}
|
||||
@@ -2835,6 +2840,15 @@ func (ss *SamlSettings) isValid() *AppError {
|
||||
if !(*ss.CanonicalAlgorithm == SAML_SETTINGS_CANONICAL_ALGORITHM_C14N || *ss.CanonicalAlgorithm == SAML_SETTINGS_CANONICAL_ALGORITHM_C14N11) {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.saml_canonical_algorithm.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(*ss.GuestAttribute) > 0 {
|
||||
if !(strings.Contains(*ss.GuestAttribute, "=")) {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.saml_guest_attribute.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
if len(strings.Split(*ss.GuestAttribute, "=")) != 2 {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.saml_guest_attribute.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -195,6 +195,21 @@ func TestConfigIsValidFakeAlgorithm(t *testing.T) {
|
||||
require.Equal(t, "model.config.is_valid.saml_signature_algorithm.app_error", err.Message)
|
||||
}
|
||||
|
||||
func TestConfigOverwriteGuestSettings(t *testing.T) {
|
||||
const attribute = "FakeAttributeName"
|
||||
c1 := Config{
|
||||
SamlSettings: SamlSettings{
|
||||
GuestAttribute: NewString(attribute),
|
||||
},
|
||||
}
|
||||
|
||||
c1.SetDefaults()
|
||||
|
||||
if *c1.SamlSettings.GuestAttribute != attribute {
|
||||
t.Fatal("SamlSettings.GuestAttribute should be overwritten")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing.T) {
|
||||
c1 := Config{}
|
||||
c1.SetDefaults()
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEmojiSearchJson(t *testing.T) {
|
||||
@@ -13,7 +15,5 @@ func TestEmojiSearchJson(t *testing.T) {
|
||||
json := emojiSearch.ToJson()
|
||||
remojiSearch := EmojiSearchFromJson(strings.NewReader(json))
|
||||
|
||||
if emojiSearch.Term != remojiSearch.Term {
|
||||
t.Fatal("Terms do not match")
|
||||
}
|
||||
require.Equal(t, emojiSearch.Term, remojiSearch.Term, "Terms do not match")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -14,7 +15,5 @@ func TestInitialLoadJson(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
ro := InitialLoadFromJson(strings.NewReader(json))
|
||||
|
||||
if o.User.Id != ro.User.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, o.User.Id, ro.User.Id, "Ids do not match")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLicenseFeaturesToMap(t *testing.T) {
|
||||
@@ -102,27 +104,20 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
func TestLicenseIsExpired(t *testing.T) {
|
||||
l1 := License{}
|
||||
l1.ExpiresAt = GetMillis() - 1000
|
||||
if !l1.IsExpired() {
|
||||
t.Fatal("license should be expired")
|
||||
}
|
||||
assert.True(t, l1.IsExpired())
|
||||
|
||||
l1.ExpiresAt = GetMillis() + 10000
|
||||
if l1.IsExpired() {
|
||||
t.Fatal("license should not be expired")
|
||||
}
|
||||
assert.False(t, l1.IsExpired())
|
||||
}
|
||||
|
||||
func TestLicenseIsStarted(t *testing.T) {
|
||||
l1 := License{}
|
||||
l1.StartsAt = GetMillis() - 1000
|
||||
if !l1.IsStarted() {
|
||||
t.Fatal("license should be started")
|
||||
}
|
||||
|
||||
assert.True(t, l1.IsStarted())
|
||||
|
||||
l1.StartsAt = GetMillis() + 10000
|
||||
if l1.IsStarted() {
|
||||
t.Fatal("license should not be started")
|
||||
}
|
||||
assert.False(t, l1.IsStarted())
|
||||
}
|
||||
|
||||
func TestLicenseToFromJson(t *testing.T) {
|
||||
@@ -147,9 +142,7 @@ func TestLicenseToFromJson(t *testing.T) {
|
||||
j := l.ToJson()
|
||||
|
||||
l1 := LicenseFromJson(strings.NewReader(j))
|
||||
if l1 == nil {
|
||||
t.Fatalf("Decoding failed but should have passed.")
|
||||
}
|
||||
assert.NotNil(t, l1)
|
||||
|
||||
CheckString(t, l1.Id, l.Id)
|
||||
CheckInt64(t, l1.IssuedAt, l.IssuedAt)
|
||||
@@ -184,9 +177,7 @@ func TestLicenseToFromJson(t *testing.T) {
|
||||
|
||||
invalid := `{"asdf`
|
||||
l2 := LicenseFromJson(strings.NewReader(invalid))
|
||||
if l2 != nil {
|
||||
t.Fatalf("Should have failed but didn't")
|
||||
}
|
||||
assert.Nil(t, l2)
|
||||
}
|
||||
|
||||
func TestLicenseRecordIsValid(t *testing.T) {
|
||||
@@ -195,38 +186,31 @@ func TestLicenseRecordIsValid(t *testing.T) {
|
||||
Bytes: "asdfghjkl;",
|
||||
}
|
||||
|
||||
if err := lr.IsValid(); err == nil {
|
||||
t.Fatalf("Should have been invalid")
|
||||
}
|
||||
err := lr.IsValid()
|
||||
assert.NotNil(t, err)
|
||||
|
||||
lr.Id = NewId()
|
||||
lr.CreateAt = 0
|
||||
if err := lr.IsValid(); err == nil {
|
||||
t.Fatalf("Should have been invalid")
|
||||
}
|
||||
err = lr.IsValid()
|
||||
assert.NotNil(t, err)
|
||||
|
||||
lr.CreateAt = GetMillis()
|
||||
lr.Bytes = ""
|
||||
if err := lr.IsValid(); err == nil {
|
||||
t.Fatalf("Should have been invalid")
|
||||
}
|
||||
err = lr.IsValid()
|
||||
assert.NotNil(t, err)
|
||||
|
||||
lr.Bytes = strings.Repeat("0123456789", 1001)
|
||||
if err := lr.IsValid(); err == nil {
|
||||
t.Fatalf("Should have been invalid")
|
||||
}
|
||||
err = lr.IsValid()
|
||||
assert.NotNil(t, err)
|
||||
|
||||
lr.Bytes = "ASDFGHJKL;"
|
||||
if err := lr.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = lr.IsValid()
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestLicenseRecordPreSave(t *testing.T) {
|
||||
lr := LicenseRecord{}
|
||||
lr.PreSave()
|
||||
|
||||
if lr.CreateAt == 0 {
|
||||
t.Fatal("CreateAt should not be zero")
|
||||
}
|
||||
assert.NotZero(t, lr.CreateAt)
|
||||
}
|
||||
|
||||
@@ -4,48 +4,31 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func CheckInt(t *testing.T, got int, expected int) {
|
||||
if got != expected {
|
||||
debug.PrintStack()
|
||||
t.Fatalf("Got: %v, Expected: %v", got, expected)
|
||||
}
|
||||
assert.Equal(t, got, expected)
|
||||
}
|
||||
|
||||
func CheckInt64(t *testing.T, got int64, expected int64) {
|
||||
if got != expected {
|
||||
debug.PrintStack()
|
||||
t.Fatalf("Got: %v, Expected: %v", got, expected)
|
||||
}
|
||||
assert.Equal(t, got, expected)
|
||||
}
|
||||
|
||||
func CheckString(t *testing.T, got string, expected string) {
|
||||
if got != expected {
|
||||
debug.PrintStack()
|
||||
t.Fatalf("Got: %v, Expected: %v", got, expected)
|
||||
}
|
||||
assert.Equal(t, got, expected)
|
||||
}
|
||||
|
||||
func CheckTrue(t *testing.T, test bool) {
|
||||
if !test {
|
||||
debug.PrintStack()
|
||||
t.Fatal("Expected true")
|
||||
}
|
||||
assert.True(t, test)
|
||||
}
|
||||
|
||||
func CheckFalse(t *testing.T, test bool) {
|
||||
if test {
|
||||
debug.PrintStack()
|
||||
t.Fatal("Expected true")
|
||||
}
|
||||
assert.False(t, test)
|
||||
}
|
||||
|
||||
func CheckBool(t *testing.T, got bool, expected bool) {
|
||||
if got != expected {
|
||||
debug.PrintStack()
|
||||
t.Fatalf("Got: %v, Expected: %v", got, expected)
|
||||
}
|
||||
assert.Equal(t, got, expected)
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ func TestOAuthAppJson(t *testing.T) {
|
||||
json := a1.ToJson()
|
||||
ra1 := OAuthAppFromJson(strings.NewReader(json))
|
||||
|
||||
if a1.Id != ra1.Id {
|
||||
t.Fatal("ids did not match")
|
||||
}
|
||||
require.Equal(t, a1.Id, ra1.Id, "ids did not match")
|
||||
}
|
||||
|
||||
func TestOAuthAppPreSave(t *testing.T) {
|
||||
|
||||
@@ -57,9 +57,7 @@ func TestPreferencePreUpdate(t *testing.T) {
|
||||
preference.PreUpdate()
|
||||
|
||||
var props map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(preference.Value)).Decode(&props); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, json.NewDecoder(strings.NewReader(preference.Value)).Decode(&props))
|
||||
|
||||
require.Equal(t, "#ff0000", props["color"], "shouldn't have changed valid props")
|
||||
require.Equal(t, "#faf", props["color2"], "shouldn't have changed valid props")
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSamlCertificateStatusJson(t *testing.T) {
|
||||
@@ -13,12 +15,8 @@ func TestSamlCertificateStatusJson(t *testing.T) {
|
||||
json := status.ToJson()
|
||||
rstatus := SamlCertificateStatusFromJson(strings.NewReader(json))
|
||||
|
||||
if status.IdpCertificateFile != rstatus.IdpCertificateFile {
|
||||
t.Fatal("IdpCertificateFile do not match")
|
||||
}
|
||||
require.Equal(t, status.IdpCertificateFile, rstatus.IdpCertificateFile, "IdpCertificateFile do not match")
|
||||
|
||||
rstatus = SamlCertificateStatusFromJson(strings.NewReader("junk"))
|
||||
if rstatus != nil {
|
||||
t.Fatal("should be nil")
|
||||
}
|
||||
require.Nil(t, rstatus, "should be nil")
|
||||
}
|
||||
|
||||
@@ -12,77 +12,103 @@ import (
|
||||
)
|
||||
|
||||
func TestSplitWords(t *testing.T) {
|
||||
if words := splitWords(""); len(words) != 0 {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words := splitWords("")
|
||||
require.Equal(t, 0, len(words))
|
||||
|
||||
if words := splitWords(" "); len(words) != 0 {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords(" ")
|
||||
require.Equal(t, 0, len(words))
|
||||
|
||||
if words := splitWords("word"); len(words) != 1 || words[0] != "word" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("word")
|
||||
require.Equal(t, 1, len(words))
|
||||
require.Equal(t, "word", words[0])
|
||||
|
||||
if words := splitWords("wo\"rd"); len(words) != 2 || words[0] != "wo" || words[1] != "\"rd" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("wo\"rd")
|
||||
require.Equal(t, 2, len(words))
|
||||
require.Equal(t, "wo", words[0])
|
||||
require.Equal(t, "\"rd", words[1])
|
||||
|
||||
if words := splitWords("wo\"rd\""); len(words) != 2 || words[0] != "wo" || words[1] != "\"rd\"" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("wo\"rd\"")
|
||||
require.Equal(t, 2, len(words))
|
||||
require.Equal(t, "wo", words[0])
|
||||
require.Equal(t, "\"rd\"", words[1])
|
||||
|
||||
if words := splitWords("wo-\"rd\""); len(words) != 2 || words[0] != "wo" || words[1] != "-\"rd\"" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("wo-\"rd\"")
|
||||
require.Equal(t, 2, len(words))
|
||||
require.Equal(t, "wo", words[0])
|
||||
require.Equal(t, "-\"rd\"", words[1])
|
||||
|
||||
if words := splitWords("word1 word2 word3"); len(words) != 3 || words[0] != "word1" || words[1] != "word2" || words[2] != "word3" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("word1 word2 word3")
|
||||
require.Equal(t, 3, len(words))
|
||||
require.Equal(t, "word1", words[0])
|
||||
require.Equal(t, "word2", words[1])
|
||||
require.Equal(t, "word3", words[2])
|
||||
|
||||
if words := splitWords("word1 \"word2 word3"); len(words) != 3 || words[0] != "word1" || words[1] != "\"word2" || words[2] != "word3" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("word1 \"word2 word3")
|
||||
require.Equal(t, 3, len(words))
|
||||
require.Equal(t, "word1", words[0])
|
||||
require.Equal(t, "\"word2", words[1])
|
||||
require.Equal(t, "word3", words[2])
|
||||
|
||||
if words := splitWords("\"word1 word2 word3"); len(words) != 3 || words[0] != "\"word1" || words[1] != "word2" || words[2] != "word3" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("\"word1 word2 word3")
|
||||
require.Equal(t, 3, len(words))
|
||||
require.Equal(t, "\"word1", words[0])
|
||||
require.Equal(t, "word2", words[1])
|
||||
require.Equal(t, "word3", words[2])
|
||||
|
||||
if words := splitWords("word1 word2 word3\""); len(words) != 4 || words[0] != "word1" || words[1] != "word2" || words[2] != "word3" || words[3] != "\"" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("word1 word2 word3\"")
|
||||
require.Equal(t, 4, len(words))
|
||||
require.Equal(t, "word1", words[0])
|
||||
require.Equal(t, "word2", words[1])
|
||||
require.Equal(t, "word3", words[2])
|
||||
require.Equal(t, "\"", words[3])
|
||||
|
||||
if words := splitWords("word1 #word2 ##word3"); len(words) != 3 || words[0] != "word1" || words[1] != "#word2" || words[2] != "##word3" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("word1 #word2 ##word3")
|
||||
require.Equal(t, 3, len(words))
|
||||
require.Equal(t, "word1", words[0])
|
||||
require.Equal(t, "#word2", words[1])
|
||||
require.Equal(t, "##word3", words[2])
|
||||
|
||||
if words := splitWords(" word1 word2 word3 "); len(words) != 3 || words[0] != "word1" || words[1] != "word2" || words[2] != "word3" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords(" word1 word2 word3 ")
|
||||
require.Equal(t, 3, len(words))
|
||||
require.Equal(t, "word1", words[0])
|
||||
require.Equal(t, "word2", words[1])
|
||||
require.Equal(t, "word3", words[2])
|
||||
|
||||
if words := splitWords("\"quoted\""); len(words) != 1 || words[0] != "\"quoted\"" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("\"quoted\"")
|
||||
require.Equal(t, 1, len(words))
|
||||
require.Equal(t, "\"quoted\"", words[0])
|
||||
|
||||
if words := splitWords("-\"quoted\""); len(words) != 1 || words[0] != "-\"quoted\"" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("-\"quoted\"")
|
||||
require.Equal(t, 1, len(words))
|
||||
require.Equal(t, "-\"quoted\"", words[0])
|
||||
|
||||
if words := splitWords("\"quoted multiple words\""); len(words) != 1 || words[0] != "\"quoted multiple words\"" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("\"quoted multiple words\"")
|
||||
require.Equal(t, 1, len(words))
|
||||
require.Equal(t, "\"quoted multiple words\"", words[0])
|
||||
|
||||
if words := splitWords("some stuff \"quoted multiple words\" more stuff"); len(words) != 5 || words[0] != "some" || words[1] != "stuff" || words[2] != "\"quoted multiple words\"" || words[3] != "more" || words[4] != "stuff" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("some stuff \"quoted multiple words\" more stuff")
|
||||
require.Equal(t, 5, len(words))
|
||||
require.Equal(t, "some", words[0])
|
||||
require.Equal(t, "stuff", words[1])
|
||||
require.Equal(t, "\"quoted multiple words\"", words[2])
|
||||
require.Equal(t, "more", words[3])
|
||||
require.Equal(t, "stuff", words[4])
|
||||
|
||||
if words := splitWords("some stuff -\"quoted multiple words\" more stuff"); len(words) != 5 || words[0] != "some" || words[1] != "stuff" || words[2] != "-\"quoted multiple words\"" || words[3] != "more" || words[4] != "stuff" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("some stuff -\"quoted multiple words\" more stuff")
|
||||
require.Equal(t, 5, len(words))
|
||||
require.Equal(t, "some", words[0])
|
||||
require.Equal(t, "stuff", words[1])
|
||||
require.Equal(t, "-\"quoted multiple words\"", words[2])
|
||||
require.Equal(t, "more", words[3])
|
||||
require.Equal(t, "stuff", words[4])
|
||||
|
||||
if words := splitWords("some \"stuff\" \"quoted multiple words\" #some \"more stuff\""); len(words) != 5 || words[0] != "some" || words[1] != "\"stuff\"" || words[2] != "\"quoted multiple words\"" || words[3] != "#some" || words[4] != "\"more stuff\"" {
|
||||
t.Fatalf("Incorrect output splitWords: %v", words)
|
||||
}
|
||||
words = splitWords("some \"stuff\" \"quoted multiple words\" #some \"more stuff\"")
|
||||
require.Equal(t, 5, len(words))
|
||||
require.Equal(t, "some", words[0])
|
||||
require.Equal(t, "\"stuff\"", words[1])
|
||||
require.Equal(t, "\"quoted multiple words\"", words[2])
|
||||
require.Equal(t, "#some", words[3])
|
||||
require.Equal(t, "\"more stuff\"", words[4])
|
||||
}
|
||||
|
||||
func TestParseSearchFlags(t *testing.T) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -12,8 +13,5 @@ func TestUserAccessTokenSearchJson(t *testing.T) {
|
||||
userAccessTokenSearch := UserAccessTokenSearch{Term: NewId()}
|
||||
json := userAccessTokenSearch.ToJson()
|
||||
ruserAccessTokenSearch := UserAccessTokenSearchFromJson(strings.NewReader(json))
|
||||
|
||||
if userAccessTokenSearch.Term != ruserAccessTokenSearch.Term {
|
||||
t.Fatal("Terms do not match")
|
||||
}
|
||||
require.Equal(t, userAccessTokenSearch.Term, ruserAccessTokenSearch.Term, "Terms do not match")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUserSearchJson(t *testing.T) {
|
||||
@@ -13,7 +15,5 @@ func TestUserSearchJson(t *testing.T) {
|
||||
json := userSearch.ToJson()
|
||||
ruserSearch := UserSearchFromJson(bytes.NewReader(json))
|
||||
|
||||
if userSearch.Term != ruserSearch.Term {
|
||||
t.Fatal("Terms do not match")
|
||||
}
|
||||
assert.Equal(t, userSearch.Term, ruserSearch.Term, "Terms do not match")
|
||||
}
|
||||
|
||||
@@ -8,29 +8,21 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUserTermsOfServiceIsValid(t *testing.T) {
|
||||
s := UserTermsOfService{}
|
||||
|
||||
if err := s.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, s.IsValid(), "should be invalid")
|
||||
|
||||
s.UserId = NewId()
|
||||
if err := s.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, s.IsValid(), "should be invalid")
|
||||
|
||||
s.TermsOfServiceId = NewId()
|
||||
if err := s.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, s.IsValid(), "should be invalid")
|
||||
|
||||
s.CreateAt = GetMillis()
|
||||
if err := s.IsValid(); err != nil {
|
||||
t.Fatal("should be valid")
|
||||
}
|
||||
require.Nil(t, s.IsValid(), "should be valid")
|
||||
}
|
||||
|
||||
func TestUserTermsOfServiceJson(t *testing.T) {
|
||||
|
||||
@@ -16,13 +16,8 @@ import (
|
||||
func TestPasswordHash(t *testing.T) {
|
||||
hash := HashPassword("Test")
|
||||
|
||||
if !ComparePassword(hash, "Test") {
|
||||
t.Fatal("Passwords don't match")
|
||||
}
|
||||
|
||||
if ComparePassword(hash, "Test2") {
|
||||
t.Fatal("Passwords should not have matched")
|
||||
}
|
||||
assert.True(t, ComparePassword(hash, "Test"), "Passwords don't match")
|
||||
assert.False(t, ComparePassword(hash, "Test2"), "Passwords should not have matched")
|
||||
}
|
||||
|
||||
func TestUserDeepCopy(t *testing.T) {
|
||||
@@ -60,22 +55,15 @@ func TestUserJson(t *testing.T) {
|
||||
json := user.ToJson()
|
||||
ruser := UserFromJson(strings.NewReader(json))
|
||||
|
||||
if user.Id != ruser.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
assert.Equal(t, user.Id, ruser.Id, "Ids do not match")
|
||||
}
|
||||
|
||||
func TestUserPreSave(t *testing.T) {
|
||||
user := User{Password: "test"}
|
||||
user.PreSave()
|
||||
user.Etag(true, true)
|
||||
if user.Timezone == nil {
|
||||
t.Fatal("Timezone is nil")
|
||||
}
|
||||
|
||||
if user.Timezone["useAutomaticTimezone"] != "true" {
|
||||
t.Fatal("Timezone is not set to default")
|
||||
}
|
||||
assert.NotNil(t, user.Timezone, "Timezone is nil")
|
||||
assert.Equal(t, user.Timezone["useAutomaticTimezone"], "true", "Timezone is not set to default");
|
||||
}
|
||||
|
||||
func TestUserPreUpdate(t *testing.T) {
|
||||
@@ -86,39 +74,28 @@ func TestUserPreUpdate(t *testing.T) {
|
||||
func TestUserUpdateMentionKeysFromUsername(t *testing.T) {
|
||||
user := User{Username: "user"}
|
||||
user.SetDefaultNotifications()
|
||||
|
||||
if user.NotifyProps["mention_keys"] != "user,@user" {
|
||||
t.Fatalf("default mention keys are invalid: %v", user.NotifyProps["mention_keys"])
|
||||
}
|
||||
assert.Equalf(t, user.NotifyProps["mention_keys"], "user,@user", "default mention keys are invalid: %v", user.NotifyProps["mention_keys"])
|
||||
|
||||
user.Username = "person"
|
||||
user.UpdateMentionKeysFromUsername("user")
|
||||
if user.NotifyProps["mention_keys"] != "person,@person" {
|
||||
t.Fatalf("mention keys are invalid after changing username: %v", user.NotifyProps["mention_keys"])
|
||||
}
|
||||
assert.Equalf(t, user.NotifyProps["mention_keys"], "person,@person", "mention keys are invalid after changing username: %v", user.NotifyProps["mention_keys"])
|
||||
|
||||
user.NotifyProps["mention_keys"] += ",mention"
|
||||
user.UpdateMentionKeysFromUsername("person")
|
||||
if user.NotifyProps["mention_keys"] != "person,@person,mention" {
|
||||
t.Fatalf("mention keys are invalid after adding extra mention keyword: %v", user.NotifyProps["mention_keys"])
|
||||
}
|
||||
assert.Equalf(t, user.NotifyProps["mention_keys"], "person,@person,mention", "mention keys are invalid after adding extra mention keyword: %v", user.NotifyProps["mention_keys"])
|
||||
|
||||
user.Username = "user"
|
||||
user.UpdateMentionKeysFromUsername("person")
|
||||
if user.NotifyProps["mention_keys"] != "user,@user,mention" {
|
||||
t.Fatalf("mention keys are invalid after changing username with extra mention keyword: %v", user.NotifyProps["mention_keys"])
|
||||
}
|
||||
assert.Equalf(t, user.NotifyProps["mention_keys"], "user,@user,mention", "mention keys are invalid after changing username with extra mention keyword: %v", user.NotifyProps["mention_keys"])
|
||||
}
|
||||
|
||||
func TestUserIsValid(t *testing.T) {
|
||||
user := User{}
|
||||
|
||||
if err := user.IsValid(); !HasExpectedUserIsValidError(err, "id", "") {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := user.IsValid()
|
||||
require.True(t, HasExpectedUserIsValidError(err, "id", ""), "expected user is valid error: %s", err.Error())
|
||||
|
||||
user.Id = NewId()
|
||||
err := user.IsValid()
|
||||
err = user.IsValid()
|
||||
require.True(t, HasExpectedUserIsValidError(err, "create_at", user.Id), "expected user is valid error: %s", err.Error())
|
||||
|
||||
user.CreateAt = GetMillis()
|
||||
@@ -148,37 +125,28 @@ func TestUserIsValid(t *testing.T) {
|
||||
require.True(t, HasExpectedUserIsValidError(err, "nickname", user.Id), "expected user is valid error: %s", err.Error())
|
||||
|
||||
user.Nickname = strings.Repeat("a", 64)
|
||||
if err := user.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Error(t, user.IsValid())
|
||||
|
||||
user.FirstName = ""
|
||||
user.LastName = ""
|
||||
if err := user.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Error(t, user.IsValid())
|
||||
|
||||
user.FirstName = strings.Repeat("a", 65)
|
||||
if err := user.IsValid(); !HasExpectedUserIsValidError(err, "first_name", user.Id) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = user.IsValid()
|
||||
require.True(t, HasExpectedUserIsValidError(err, "first_name", user.Id), "expected user is valid error: %s", err.Error())
|
||||
|
||||
user.FirstName = strings.Repeat("a", 64)
|
||||
user.LastName = strings.Repeat("a", 65)
|
||||
if err := user.IsValid(); !HasExpectedUserIsValidError(err, "last_name", user.Id) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = user.IsValid()
|
||||
require.True(t, HasExpectedUserIsValidError(err, "last_name", user.Id), "expected user is valid error: %s", err.Error())
|
||||
|
||||
user.LastName = strings.Repeat("a", 64)
|
||||
user.Position = strings.Repeat("a", 128)
|
||||
if err := user.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Error(t, user.IsValid())
|
||||
|
||||
user.Position = strings.Repeat("a", 129)
|
||||
if err := user.IsValid(); !HasExpectedUserIsValidError(err, "position", user.Id) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = user.IsValid()
|
||||
require.True(t, HasExpectedUserIsValidError(err, "position", user.Id), "expected user is valid error: %s", err.Error())
|
||||
}
|
||||
|
||||
func HasExpectedUserIsValidError(err *AppError, fieldName string, userId string) bool {
|
||||
@@ -194,98 +162,53 @@ func HasExpectedUserIsValidError(err *AppError, fieldName string, userId string)
|
||||
|
||||
func TestUserGetFullName(t *testing.T) {
|
||||
user := User{}
|
||||
|
||||
if fullName := user.GetFullName(); fullName != "" {
|
||||
t.Fatal("Full name should be blank")
|
||||
}
|
||||
assert.Equal(t, user.GetFullName(), "", "Full name should be blank")
|
||||
|
||||
user.FirstName = "first"
|
||||
if fullName := user.GetFullName(); fullName != "first" {
|
||||
t.Fatal("Full name should be first name")
|
||||
}
|
||||
assert.Equal(t, user.GetFullName(), "first", "Full name should be first name")
|
||||
|
||||
user.FirstName = ""
|
||||
user.LastName = "last"
|
||||
if fullName := user.GetFullName(); fullName != "last" {
|
||||
t.Fatal("Full name should be last name")
|
||||
}
|
||||
assert.Equal(t, user.GetFullName(), "last", "Full name should be last name")
|
||||
|
||||
user.FirstName = "first"
|
||||
if fullName := user.GetFullName(); fullName != "first last" {
|
||||
t.Fatal("Full name should be first name and last name")
|
||||
}
|
||||
assert.Equal(t, user.GetFullName(), "first last", "Full name should be first name and last name")
|
||||
}
|
||||
|
||||
func TestUserGetDisplayName(t *testing.T) {
|
||||
user := User{Username: "username"}
|
||||
|
||||
if displayName := user.GetDisplayName(SHOW_FULLNAME); displayName != "username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayName(SHOW_NICKNAME_FULLNAME); displayName != "username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayName(SHOW_USERNAME); displayName != "username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
assert.Equal(t, user.GetDisplayName(SHOW_FULLNAME), "username", "Display name should be username")
|
||||
assert.Equal(t, user.GetDisplayName(SHOW_NICKNAME_FULLNAME), "username", "Display name should be username")
|
||||
assert.Equal(t, user.GetDisplayName(SHOW_USERNAME), "username", "Display name should be username")
|
||||
|
||||
user.FirstName = "first"
|
||||
user.LastName = "last"
|
||||
|
||||
if displayName := user.GetDisplayName(SHOW_FULLNAME); displayName != "first last" {
|
||||
t.Fatal("Display name should be full name")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayName(SHOW_NICKNAME_FULLNAME); displayName != "first last" {
|
||||
t.Fatal("Display name should be full name since there is no nickname")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayName(SHOW_USERNAME); displayName != "username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
assert.Equal(t, user.GetDisplayName(SHOW_FULLNAME), "first last", "Display name should be full name")
|
||||
assert.Equal(t, user.GetDisplayName(SHOW_NICKNAME_FULLNAME), "first last", "Display name should be full name since there is no nickname")
|
||||
assert.Equal(t, user.GetDisplayName(SHOW_USERNAME), "username", "Display name should be username")
|
||||
|
||||
user.Nickname = "nickname"
|
||||
if displayName := user.GetDisplayName(SHOW_NICKNAME_FULLNAME); displayName != "nickname" {
|
||||
t.Fatal("Display name should be nickname")
|
||||
}
|
||||
assert.Equal(t, user.GetDisplayName(SHOW_NICKNAME_FULLNAME), "nickname", "Display name should be nickname")
|
||||
}
|
||||
|
||||
func TestUserGetDisplayNameWithPrefix(t *testing.T) {
|
||||
user := User{Username: "username"}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_FULLNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_USERNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
assert.Equal(t, user.GetDisplayNameWithPrefix(SHOW_FULLNAME, "@"), "@username", "Display name should be username")
|
||||
assert.Equal(t, user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"), "@username", "Display name should be username")
|
||||
assert.Equal(t, user.GetDisplayNameWithPrefix(SHOW_USERNAME, "@"), "@username", "Display name should be username")
|
||||
|
||||
user.FirstName = "first"
|
||||
user.LastName = "last"
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_FULLNAME, "@"); displayName != "first last" {
|
||||
t.Fatal("Display name should be full name")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"); displayName != "first last" {
|
||||
t.Fatal("Display name should be full name since there is no nickname")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_USERNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
assert.Equal(t, user.GetDisplayNameWithPrefix(SHOW_FULLNAME, "@"), "first last", "Display name should be full name")
|
||||
assert.Equal(t, user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"), "first last", "Display name should be full name since there is no nickname")
|
||||
assert.Equal(t, user.GetDisplayNameWithPrefix(SHOW_USERNAME, "@"), "@username", "Display name should be username")
|
||||
|
||||
user.Nickname = "nickname"
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"); displayName != "nickname" {
|
||||
t.Fatal("Display name should be nickname")
|
||||
}
|
||||
assert.Equal(t, user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"), "nickname", "Display name should be nickname")
|
||||
}
|
||||
|
||||
var usernames = []struct {
|
||||
@@ -319,45 +242,23 @@ func TestValidUsername(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNormalizeUsername(t *testing.T) {
|
||||
if NormalizeUsername("Spin-punch") != "spin-punch" {
|
||||
t.Fatal("didn't normalize username properly")
|
||||
}
|
||||
if NormalizeUsername("PUNCH") != "punch" {
|
||||
t.Fatal("didn't normalize username properly")
|
||||
}
|
||||
if NormalizeUsername("spin") != "spin" {
|
||||
t.Fatal("didn't normalize username properly")
|
||||
}
|
||||
assert.Equal(t, NormalizeUsername("Spin-punch"), "spin-punch", "didn't normalize username properly")
|
||||
assert.Equal(t, NormalizeUsername("PUNCH"), "punch", "didn't normalize username properly")
|
||||
assert.Equal(t, NormalizeUsername("spin"), "spin", "didn't normalize username properly")
|
||||
}
|
||||
|
||||
func TestNormalizeEmail(t *testing.T) {
|
||||
if NormalizeEmail("TEST@EXAMPLE.COM") != "test@example.com" {
|
||||
t.Fatal("didn't normalize email properly")
|
||||
}
|
||||
if NormalizeEmail("TEST2@example.com") != "test2@example.com" {
|
||||
t.Fatal("didn't normalize email properly")
|
||||
}
|
||||
if NormalizeEmail("test3@example.com") != "test3@example.com" {
|
||||
t.Fatal("didn't normalize email properly")
|
||||
}
|
||||
assert.Equal(t, NormalizeEmail("TEST@EXAMPLE.COM"), "test@example.com", "didn't normalize email properly")
|
||||
assert.Equal(t, NormalizeEmail("TEST2@example.com"), "test2@example.com", "didn't normalize email properly")
|
||||
assert.Equal(t, NormalizeEmail("test3@example.com"), "test3@example.com", "didn't normalize email properly")
|
||||
}
|
||||
|
||||
func TestCleanUsername(t *testing.T) {
|
||||
if CleanUsername("Spin-punch") != "spin-punch" {
|
||||
t.Fatal("didn't clean name properly")
|
||||
}
|
||||
if CleanUsername("PUNCH") != "punch" {
|
||||
t.Fatal("didn't clean name properly")
|
||||
}
|
||||
if CleanUsername("spin'punch") != "spin-punch" {
|
||||
t.Fatal("didn't clean name properly")
|
||||
}
|
||||
if CleanUsername("spin") != "spin" {
|
||||
t.Fatal("didn't clean name properly")
|
||||
}
|
||||
if len(CleanUsername("all")) != 27 {
|
||||
t.Fatal("didn't clean name properly")
|
||||
}
|
||||
assert.Equal(t, CleanUsername("Spin-punch"), "spin-punch", "didn't clean name properly")
|
||||
assert.Equal(t, CleanUsername("PUNCH"), "punch", "didn't clean name properly")
|
||||
assert.Equal(t, CleanUsername("spin'punch"), "spin-punch", "didn't clean name properly")
|
||||
assert.Equal(t, CleanUsername("spin"), "spin", "didn't clean name properly")
|
||||
assert.Equal(t, len(CleanUsername("all")), 27, "didn't clean name properly")
|
||||
}
|
||||
|
||||
func TestRoles(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user