Merge branch 'master' into mark-as-unread
Этот коммит содержится в:
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestChannelMemberJson(t *testing.T) {
|
||||
@@ -13,22 +15,16 @@ func TestChannelMemberJson(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
ro := ChannelMemberFromJson(strings.NewReader(json))
|
||||
|
||||
if o.ChannelId != ro.ChannelId {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, o.ChannelId, ro.ChannelId, "ids do not match")
|
||||
}
|
||||
|
||||
func TestChannelMemberIsValid(t *testing.T) {
|
||||
o := ChannelMember{}
|
||||
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.ChannelId = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.NotifyProps = GetDefaultChannelNotifyProps()
|
||||
o.UserId = NewId()
|
||||
@@ -40,34 +36,22 @@ func TestChannelMemberIsValid(t *testing.T) {
|
||||
}*/
|
||||
|
||||
o.NotifyProps["desktop"] = "junk"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.NotifyProps["desktop"] = "123456789012345678901"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.NotifyProps["desktop"] = CHANNEL_NOTIFY_ALL
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.NotifyProps["mark_unread"] = "123456789012345678901"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.NotifyProps["mark_unread"] = CHANNEL_MARK_UNREAD_ALL
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.Roles = ""
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Error(t, o.IsValid(), "should be invalid")
|
||||
}
|
||||
|
||||
func TestChannelUnreadJson(t *testing.T) {
|
||||
@@ -75,11 +59,6 @@ func TestChannelUnreadJson(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
ro := ChannelUnreadFromJson(strings.NewReader(json))
|
||||
|
||||
if o.TeamId != ro.TeamId {
|
||||
t.Fatal("Team Ids do not match")
|
||||
}
|
||||
|
||||
if o.MentionCount != ro.MentionCount {
|
||||
t.Fatal("MentionCount do not match")
|
||||
}
|
||||
require.Equal(t, o.TeamId, ro.TeamId, "team Ids do not match")
|
||||
require.Equal(t, o.MentionCount, ro.MentionCount, "mention count do not match")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestChannelJson(t *testing.T) {
|
||||
@@ -13,27 +15,21 @@ func TestChannelJson(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
ro := ChannelFromJson(strings.NewReader(json))
|
||||
|
||||
if o.Id != ro.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, o.Id, ro.Id)
|
||||
|
||||
p := ChannelPatch{Name: new(string)}
|
||||
*p.Name = NewId()
|
||||
json = p.ToJson()
|
||||
rp := ChannelPatchFromJson(strings.NewReader(json))
|
||||
|
||||
if *p.Name != *rp.Name {
|
||||
t.Fatal("names do not match")
|
||||
}
|
||||
require.Equal(t, *p.Name, *rp.Name)
|
||||
}
|
||||
|
||||
func TestChannelCopy(t *testing.T) {
|
||||
o := Channel{Id: NewId(), Name: NewId()}
|
||||
ro := o.DeepCopy()
|
||||
|
||||
if o.Id != ro.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, o.Id, ro.Id, "Ids do not match")
|
||||
}
|
||||
|
||||
func TestChannelPatch(t *testing.T) {
|
||||
@@ -47,97 +43,57 @@ func TestChannelPatch(t *testing.T) {
|
||||
o := Channel{Id: NewId(), Name: NewId()}
|
||||
o.Patch(p)
|
||||
|
||||
if *p.Name != o.Name {
|
||||
t.Fatal("do not match")
|
||||
}
|
||||
if *p.DisplayName != o.DisplayName {
|
||||
t.Fatal("do not match")
|
||||
}
|
||||
if *p.Header != o.Header {
|
||||
t.Fatal("do not match")
|
||||
}
|
||||
if *p.Purpose != o.Purpose {
|
||||
t.Fatal("do not match")
|
||||
}
|
||||
if *p.GroupConstrained != *o.GroupConstrained {
|
||||
t.Fatalf("expected %v got %v", *p.GroupConstrained, *o.GroupConstrained)
|
||||
}
|
||||
require.Equal(t, *p.Name, o.Name)
|
||||
require.Equal(t, *p.DisplayName, o.DisplayName)
|
||||
require.Equal(t, *p.Header, o.Header)
|
||||
require.Equal(t, *p.Purpose, o.Purpose)
|
||||
require.Equal(t, *p.GroupConstrained, *o.GroupConstrained)
|
||||
}
|
||||
|
||||
func TestChannelIsValid(t *testing.T) {
|
||||
o := Channel{}
|
||||
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.Id = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.UpdateAt = GetMillis()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.DisplayName = strings.Repeat("01234567890", 20)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.DisplayName = "1234"
|
||||
o.Name = "ZZZZZZZ"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.Name = "zzzzz"
|
||||
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.Type = "U"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.Type = "P"
|
||||
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.Header = strings.Repeat("01234567890", 100)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.Header = "1234"
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Purpose = strings.Repeat("01234567890", 30)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
require.Error(t, o.IsValid())
|
||||
|
||||
o.Purpose = "1234"
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
|
||||
o.Purpose = strings.Repeat("0123456789", 25)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, o.IsValid())
|
||||
}
|
||||
|
||||
func TestChannelPreSave(t *testing.T) {
|
||||
@@ -159,15 +115,11 @@ func TestGetGroupDisplayNameFromUsers(t *testing.T) {
|
||||
users[3] = &User{Username: NewId()}
|
||||
|
||||
name := GetGroupDisplayNameFromUsers(users, true)
|
||||
if len(name) > CHANNEL_NAME_MAX_LENGTH {
|
||||
t.Fatal("name too long")
|
||||
}
|
||||
require.LessOrEqual(t, len(name), CHANNEL_NAME_MAX_LENGTH)
|
||||
}
|
||||
|
||||
func TestGetGroupNameFromUserIds(t *testing.T) {
|
||||
name := GetGroupNameFromUserIds([]string{NewId(), NewId(), NewId(), NewId(), NewId()})
|
||||
|
||||
if len(name) > CHANNEL_NAME_MAX_LENGTH {
|
||||
t.Fatal("name too long")
|
||||
}
|
||||
require.LessOrEqual(t, len(name), CHANNEL_NAME_MAX_LENGTH)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClusterStatsJson(t *testing.T) {
|
||||
@@ -13,7 +15,5 @@ func TestClusterStatsJson(t *testing.T) {
|
||||
json := cluster.ToJson()
|
||||
result := ClusterStatsFromJson(strings.NewReader(json))
|
||||
|
||||
if cluster.Id != result.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
require.Equal(t, cluster.Id, result.Id, "Ids do not match")
|
||||
}
|
||||
|
||||
@@ -1687,6 +1687,7 @@ type LdapSettings struct {
|
||||
// Filtering
|
||||
UserFilter *string
|
||||
GroupFilter *string
|
||||
GuestFilter *string
|
||||
|
||||
// Group Mapping
|
||||
GroupDisplayNameAttribute *string
|
||||
@@ -1758,6 +1759,10 @@ func (s *LdapSettings) SetDefaults() {
|
||||
s.UserFilter = NewString("")
|
||||
}
|
||||
|
||||
if s.GuestFilter == nil {
|
||||
s.GuestFilter = NewString("")
|
||||
}
|
||||
|
||||
if s.GroupFilter == nil {
|
||||
s.GroupFilter = NewString("")
|
||||
}
|
||||
@@ -2784,6 +2789,12 @@ func (ls *LdapSettings) isValid() *AppError {
|
||||
return NewAppError("ValidateFilter", "ent.ldap.validate_filter.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if *ls.GuestFilter != "" {
|
||||
if _, err := ldap.CompileFilter(*ls.GuestFilter); err != nil {
|
||||
return NewAppError("LdapSettings.isValid", "ent.ldap.validate_guest_filter.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1018,6 +1018,105 @@ func TestLdapSettingsIsValid(t *testing.T) {
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
|
||||
{
|
||||
Name: "valid guest filter #1",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
GuestFilter: NewString("(property=value)"),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
{
|
||||
Name: "invalid guest filter #1",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
GuestFilter: NewString("("),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
{
|
||||
Name: "invalid guest filter #2",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
GuestFilter: NewString("()"),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
{
|
||||
Name: "valid guest filter #2",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
GuestFilter: NewString("(&(property=value)(otherthing=othervalue))"),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
{
|
||||
Name: "valid guest filter #3",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
GuestFilter: NewString("(&(property=value)(|(otherthing=othervalue)(other=thing)))"),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
{
|
||||
Name: "invalid guest filter #3",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
GuestFilter: NewString("(&(property=value)(|(otherthing=othervalue)(other=thing))"),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
{
|
||||
Name: "invalid guest filter #4",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
GuestFilter: NewString("(&(property=value)((otherthing=othervalue)(other=thing)))"),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
} {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
test.LdapSettings.SetDefaults()
|
||||
|
||||
@@ -5,9 +5,10 @@ package model
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestOutgoingWebhookJson(t *testing.T) {
|
||||
@@ -15,132 +16,81 @@ func TestOutgoingWebhookJson(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
ro := OutgoingWebhookFromJson(strings.NewReader(json))
|
||||
|
||||
if o.Id != ro.Id {
|
||||
t.Fatal("Ids do not match")
|
||||
}
|
||||
assert.Equal(t, o.Id, ro.Id, "Ids do not match")
|
||||
}
|
||||
|
||||
func TestOutgoingWebhookIsValid(t *testing.T) {
|
||||
o := OutgoingWebhook{}
|
||||
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNil(t, o.IsValid(), "empty declaration should be invalid")
|
||||
|
||||
o.Id = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "Id = NewId; %s should be invalid", o.Id)
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "CreateAt = GetMillis; %d should be invalid", o.CreateAt)
|
||||
|
||||
o.UpdateAt = GetMillis()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "UpdateAt = GetMillis; %d should be invalid", o.UpdateAt)
|
||||
|
||||
o.CreatorId = "123"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "CreatorId %s should be invalid", o.CreatorId)
|
||||
|
||||
o.CreatorId = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "CreatorId = NewId; %s should be invalid", o.CreatorId)
|
||||
|
||||
o.Token = "123"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "Token %s should be invalid", o.Token)
|
||||
|
||||
o.Token = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "Token = NewId; %s should be invalid", o.Token)
|
||||
|
||||
o.ChannelId = "123"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "ChannelId %s should be invalid", o.ChannelId)
|
||||
|
||||
o.ChannelId = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "ChannelId = NewId; %s should be invalid", o.ChannelId)
|
||||
|
||||
o.TeamId = "123"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "TeamId %s should be invalid", o.TeamId)
|
||||
|
||||
o.TeamId = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "TeamId = NewId; %s should be invalid", o.TeamId)
|
||||
|
||||
o.CallbackURLs = []string{"nowhere.com/"}
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "%v for CallbackURLs should be invalid", o.CallbackURLs)
|
||||
|
||||
o.CallbackURLs = []string{"http://nowhere.com/"}
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nilf(t, o.IsValid(), "%v for CallbackURLs should be valid", o.CallbackURLs)
|
||||
|
||||
o.DisplayName = strings.Repeat("1", 65)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "DisplayName length %d invalid, max length 64", len(o.DisplayName))
|
||||
|
||||
o.DisplayName = strings.Repeat("1", 64)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nilf(t, o.IsValid(), "DisplayName length %d should be valid, max length 64", len(o.DisplayName))
|
||||
|
||||
o.Description = strings.Repeat("1", 501)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "Description length %d should be invalid, max length 500", len(o.Description))
|
||||
|
||||
o.Description = strings.Repeat("1", 500)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nilf(t, o.IsValid(), "Description length %d should be valid, max length 500", len(o.Description))
|
||||
|
||||
o.ContentType = strings.Repeat("1", 129)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "ContentType length %d should be invalid, max length 128", len(o.ContentType))
|
||||
|
||||
o.ContentType = strings.Repeat("1", 128)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nilf(t, o.IsValid(), "ContentType length %d should be valid", len(o.ContentType))
|
||||
|
||||
o.Username = strings.Repeat("1", 65)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "Username length %d should be invalid, max length 64", len(o.Username))
|
||||
|
||||
o.Username = strings.Repeat("1", 64)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
assert.Nilf(t, o.IsValid(), "Username length %d should be valid", len(o.Username))
|
||||
|
||||
o.IconURL = strings.Repeat("1", 1025)
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NotNilf(t, o.IsValid(), "IconURL length %d should be invalid, max length 1024", len(o.IconURL))
|
||||
|
||||
o.IconURL = strings.Repeat("1", 1024)
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nilf(t, o.IsValid(), "IconURL length %d should be valid", len(o.IconURL))
|
||||
}
|
||||
|
||||
func TestOutgoingWebhookPayloadToFormValues(t *testing.T) {
|
||||
@@ -171,9 +121,9 @@ func TestOutgoingWebhookPayloadToFormValues(t *testing.T) {
|
||||
v.Set("text", "Text")
|
||||
v.Set("trigger_word", "TriggerWord")
|
||||
v.Set("file_ids", "FileIds")
|
||||
if got, want := p.ToFormValues(), v.Encode(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("Got %+v, wanted %+v", got, want)
|
||||
}
|
||||
got := p.ToFormValues()
|
||||
want := v.Encode()
|
||||
assert.Equalf(t, got, want, "Got %+v, wanted %+v", got, want)
|
||||
}
|
||||
|
||||
func TestOutgoingWebhookPreSave(t *testing.T) {
|
||||
@@ -189,12 +139,8 @@ func TestOutgoingWebhookPreUpdate(t *testing.T) {
|
||||
func TestOutgoingWebhookTriggerWordStartsWith(t *testing.T) {
|
||||
o := OutgoingWebhook{Id: NewId()}
|
||||
o.TriggerWords = append(o.TriggerWords, "foo")
|
||||
if !o.TriggerWordStartsWith("foobar") {
|
||||
t.Fatal("Should return true")
|
||||
}
|
||||
if o.TriggerWordStartsWith("barfoo") {
|
||||
t.Fatal("Should return false")
|
||||
}
|
||||
assert.True(t, o.TriggerWordStartsWith("foobar"), "Should return true")
|
||||
assert.False(t, o.TriggerWordStartsWith("barfoo"), "Should return false")
|
||||
}
|
||||
|
||||
func TestOutgoingWebhookResponseJson(t *testing.T) {
|
||||
@@ -204,7 +150,5 @@ func TestOutgoingWebhookResponseJson(t *testing.T) {
|
||||
json := o.ToJson()
|
||||
ro, _ := OutgoingWebhookResponseFromJson(strings.NewReader(json))
|
||||
|
||||
if *o.Text != *ro.Text {
|
||||
t.Fatal("Text does not match")
|
||||
}
|
||||
assert.Equal(t, *o.Text, *ro.Text, "Text does not match")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUserAccessTokenJson(t *testing.T) {
|
||||
@@ -16,43 +18,33 @@ func TestUserAccessTokenJson(t *testing.T) {
|
||||
json := a1.ToJson()
|
||||
ra1 := UserAccessTokenFromJson(strings.NewReader(json))
|
||||
|
||||
if a1.Token != ra1.Token {
|
||||
t.Fatal("tokens didn't match")
|
||||
}
|
||||
require.Equal(t, a1.Token, ra1.Token, "tokens didn't match")
|
||||
|
||||
tokens := []*UserAccessToken{&a1}
|
||||
json = UserAccessTokenListToJson(tokens)
|
||||
tokens = UserAccessTokenListFromJson(strings.NewReader(json))
|
||||
|
||||
if tokens[0].Token != a1.Token {
|
||||
t.Fatal("tokens didn't match")
|
||||
}
|
||||
require.Equal(t, tokens[0].Token, ra1.Token, "tokens didn't match")
|
||||
}
|
||||
|
||||
func TestUserAccessTokenIsValid(t *testing.T) {
|
||||
ad := UserAccessToken{}
|
||||
|
||||
if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.id.app_error" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := ad.IsValid()
|
||||
require.False(t, err == nil || err.Id != "model.user_access_token.is_valid.id.app_error")
|
||||
|
||||
ad.Id = NewRandomString(26)
|
||||
if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.token.app_error" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = ad.IsValid()
|
||||
require.False(t, err == nil || err.Id != "model.user_access_token.is_valid.token.app_error")
|
||||
|
||||
ad.Token = NewRandomString(26)
|
||||
if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.user_id.app_error" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = ad.IsValid()
|
||||
require.False(t, err == nil || err.Id != "model.user_access_token.is_valid.user_id.app_error")
|
||||
|
||||
ad.UserId = NewRandomString(26)
|
||||
if err := ad.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, ad.IsValid())
|
||||
|
||||
ad.Description = NewRandomString(256)
|
||||
if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.description.app_error" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = ad.IsValid()
|
||||
require.False(t, err == nil || err.Id != "model.user_access_token.is_valid.description.app_error")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestWebSocketRequest(t *testing.T) {
|
||||
@@ -13,13 +15,9 @@ func TestWebSocketRequest(t *testing.T) {
|
||||
json := m.ToJson()
|
||||
result := WebSocketRequestFromJson(strings.NewReader(json))
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("should not be nil")
|
||||
}
|
||||
require.NotNil(t, result)
|
||||
|
||||
badresult := WebSocketRequestFromJson(strings.NewReader("junk"))
|
||||
|
||||
if badresult != nil {
|
||||
t.Fatal("should have been nil")
|
||||
}
|
||||
require.Nil(t, badresult)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user