mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-1
This commit is contained in:
8
Makefile
8
Makefile
@@ -384,10 +384,10 @@ test-data: start-docker ## Add test data to the local instance.
|
||||
$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) sampledata -w 1
|
||||
|
||||
@echo You may need to restart the Mattermost server before using the following
|
||||
@echo ====================================================================================
|
||||
@echo Login with a system admin account email=user-0@sample.mattermost.com password=user-0
|
||||
@echo Login with a regular account email=user-1@sample.mattermost.com password=user-1
|
||||
@echo ====================================================================================
|
||||
@echo ========================================================================
|
||||
@echo Login with a system admin account username=sysadmin password=sysadmin
|
||||
@echo Login with a regular account username=user-1 password=user-1
|
||||
@echo ========================================================================
|
||||
|
||||
run-server: start-docker ## Starts the server.
|
||||
@echo Running mattermost for development
|
||||
|
||||
37
NOTICE.txt
37
NOTICE.txt
@@ -1284,33 +1284,32 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
|
||||
|
||||
---
|
||||
|
||||
This product contains a modified portion of 'user_agent', a Go library that parses HTTP User Agents by Miquel Sabaté Solà.
|
||||
This product contains a modified portion of 'durafmt', a Go library that formats time.Duration strings into a human readable format by Wesley Hill.
|
||||
|
||||
* HOMEPAGE:
|
||||
* https://github.com/mssola/user_agent
|
||||
* https://github.com/hako/durafmt
|
||||
|
||||
* LICENSE:
|
||||
|
||||
Copyright (c) 2012-2016 Miquel Sabaté Solà
|
||||
Copyright (c) 2016 Wesley Hill
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func TestCreateChannel(t *testing.T) {
|
||||
@@ -1766,3 +1767,75 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestAutocompleteChannels(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// A private channel to make sure private channels are not used
|
||||
utils.DisableDebugLogForTest()
|
||||
ptown, _ := th.Client.CreateChannel(&model.Channel{
|
||||
DisplayName: "Town",
|
||||
Name: "town",
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
})
|
||||
utils.EnableDebugLogForTest()
|
||||
defer func() {
|
||||
th.Client.DeleteChannel(ptown.Id)
|
||||
}()
|
||||
|
||||
for _, tc := range []struct {
|
||||
description string
|
||||
teamId string
|
||||
fragment string
|
||||
expectedIncludes []string
|
||||
expectedExcludes []string
|
||||
}{
|
||||
{
|
||||
"Basic town-square",
|
||||
th.BasicTeam.Id,
|
||||
"town",
|
||||
[]string{"town-square"},
|
||||
[]string{"off-topic", "town"},
|
||||
},
|
||||
{
|
||||
"Basic off-topic",
|
||||
th.BasicTeam.Id,
|
||||
"off-to",
|
||||
[]string{"off-topic"},
|
||||
[]string{"town-square", "town"},
|
||||
},
|
||||
{
|
||||
"Basic town square and off topic",
|
||||
th.BasicTeam.Id,
|
||||
"to",
|
||||
[]string{"off-topic", "town-square"},
|
||||
[]string{"town"},
|
||||
},
|
||||
} {
|
||||
if channels, resp := th.Client.AutocompleteChannelsForTeam(tc.teamId, tc.fragment); resp.Error != nil {
|
||||
t.Fatal("Test case " + tc.description + " failed. Err: " + resp.Error.Error())
|
||||
} else {
|
||||
for _, expectedInclude := range tc.expectedIncludes {
|
||||
found := false
|
||||
for _, channel := range *channels {
|
||||
if channel.Name == expectedInclude {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("Test case " + tc.description + " failed. Expected but didn't find channel: " + expectedInclude)
|
||||
}
|
||||
}
|
||||
for _, expectedExclude := range tc.expectedExcludes {
|
||||
for _, channel := range *channels {
|
||||
if channel.Name == expectedExclude {
|
||||
t.Fatal("Test case " + tc.description + " failed. Found channel we didn't want: " + expectedExclude)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapToJson(c.App.ClientConfigWithNoAccounts())))
|
||||
w.Write([]byte(model.MapToJson(c.App.ClientConfigWithComputed())))
|
||||
}
|
||||
|
||||
func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
11
api4/team.go
11
api4/team.go
@@ -741,15 +741,16 @@ func getTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
if team, err := c.App.GetTeam(c.Params.TeamId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) &&
|
||||
(team.Type != model.TEAM_OPEN || team.AllowOpenInvite) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
etag := strconv.FormatInt(team.LastTeamIconUpdate, 10)
|
||||
|
||||
if c.HandleEtag(etag, "Get Team Icon", w, r) {
|
||||
|
||||
@@ -141,7 +141,7 @@ func New(options ...Option) (outApp *App, outErr error) {
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CONFIG_CHANGED, "", "", "", nil)
|
||||
|
||||
message.Add("config", app.ClientConfigWithNoAccounts())
|
||||
message.Add("config", app.ClientConfigWithComputed())
|
||||
app.Go(func() {
|
||||
app.Publish(message)
|
||||
})
|
||||
|
||||
@@ -273,15 +273,17 @@ func (a *App) GetSiteURL() string {
|
||||
return a.siteURL
|
||||
}
|
||||
|
||||
// ClientConfigWithNoAccounts gets the configuration in a format suitable for sending to the client.
|
||||
func (a *App) ClientConfigWithNoAccounts() map[string]string {
|
||||
// ClientConfigWithComputed gets the configuration in a format suitable for sending to the client.
|
||||
func (a *App) ClientConfigWithComputed() map[string]string {
|
||||
respCfg := map[string]string{}
|
||||
for k, v := range a.ClientConfig() {
|
||||
respCfg[k] = v
|
||||
}
|
||||
|
||||
// NoAccounts is not actually part of the configuration, but is expected by the client.
|
||||
// These properties are not configurable, but nevertheless represent configuration expected
|
||||
// by the client.
|
||||
respCfg["NoAccounts"] = strconv.FormatBool(a.IsFirstUserAccount())
|
||||
respCfg["MaxPostSize"] = strconv.Itoa(a.MaxPostSize())
|
||||
|
||||
return respCfg
|
||||
}
|
||||
|
||||
@@ -64,12 +64,15 @@ func TestAsymmetricSigningKey(t *testing.T) {
|
||||
assert.NotEmpty(t, th.App.ClientConfig()["AsymmetricSigningPublicKey"])
|
||||
}
|
||||
|
||||
func TestClientConfigWithNoAccounts(t *testing.T) {
|
||||
func TestClientConfigWithComputed(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
config := th.App.ClientConfigWithNoAccounts()
|
||||
config := th.App.ClientConfigWithComputed()
|
||||
if _, ok := config["NoAccounts"]; !ok {
|
||||
t.Fatal("expected NoAccounts in returned config")
|
||||
}
|
||||
if _, ok := config["MaxPostSize"]; !ok {
|
||||
t.Fatal("expected MaxPostSize in returned config")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1086,7 +1086,7 @@ func (a *App) ImportReaction(data *ReactionImportData, post *model.Post, dryRun
|
||||
}
|
||||
|
||||
func (a *App) ImportReply(data *ReplyImportData, post *model.Post, dryRun bool) *model.AppError {
|
||||
if err := validateReplyImportData(data, post.CreateAt); err != nil {
|
||||
if err := validateReplyImportData(data, post.CreateAt, a.MaxPostSize()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1136,7 +1136,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, dryRun bool)
|
||||
}
|
||||
|
||||
func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
|
||||
if err := validatePostImportData(data); err != nil {
|
||||
if err := validatePostImportData(data, a.MaxPostSize()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1271,14 +1271,14 @@ func validateReactionImportData(data *ReactionImportData, parentCreateAt int64)
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateReplyImportData(data *ReplyImportData, parentCreateAt int64) *model.AppError {
|
||||
func validateReplyImportData(data *ReplyImportData, parentCreateAt int64, maxPostSize int) *model.AppError {
|
||||
if data.User == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.user_missing.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if data.Message == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.message_missing.error", nil, "", http.StatusBadRequest)
|
||||
} else if utf8.RuneCountInString(*data.Message) > model.POST_MESSAGE_MAX_RUNES {
|
||||
} else if utf8.RuneCountInString(*data.Message) > maxPostSize {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.message_length.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -1293,7 +1293,7 @@ func validateReplyImportData(data *ReplyImportData, parentCreateAt int64) *model
|
||||
return nil
|
||||
}
|
||||
|
||||
func validatePostImportData(data *PostImportData) *model.AppError {
|
||||
func validatePostImportData(data *PostImportData, maxPostSize int) *model.AppError {
|
||||
if data.Team == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_post_import_data.team_missing.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -1308,7 +1308,7 @@ func validatePostImportData(data *PostImportData) *model.AppError {
|
||||
|
||||
if data.Message == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_post_import_data.message_missing.error", nil, "", http.StatusBadRequest)
|
||||
} else if utf8.RuneCountInString(*data.Message) > model.POST_MESSAGE_MAX_RUNES {
|
||||
} else if utf8.RuneCountInString(*data.Message) > maxPostSize {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_post_import_data.message_length.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -1326,7 +1326,7 @@ func validatePostImportData(data *PostImportData) *model.AppError {
|
||||
|
||||
if data.Replies != nil {
|
||||
for _, reply := range *data.Replies {
|
||||
validateReplyImportData(&reply, *data.CreateAt)
|
||||
validateReplyImportData(&reply, *data.CreateAt, maxPostSize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1446,7 +1446,7 @@ func validateDirectChannelImportData(data *DirectChannelImportData) *model.AppEr
|
||||
}
|
||||
|
||||
func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.AppError {
|
||||
if err := validateDirectPostImportData(data); err != nil {
|
||||
if err := validateDirectPostImportData(data, a.MaxPostSize()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1572,7 +1572,7 @@ func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateDirectPostImportData(data *DirectPostImportData) *model.AppError {
|
||||
func validateDirectPostImportData(data *DirectPostImportData, maxPostSize int) *model.AppError {
|
||||
if data.ChannelMembers == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.channel_members_required.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -1591,7 +1591,7 @@ func validateDirectPostImportData(data *DirectPostImportData) *model.AppError {
|
||||
|
||||
if data.Message == nil {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.message_missing.error", nil, "", http.StatusBadRequest)
|
||||
} else if utf8.RuneCountInString(*data.Message) > model.POST_MESSAGE_MAX_RUNES {
|
||||
} else if utf8.RuneCountInString(*data.Message) > maxPostSize {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.message_length.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -1624,7 +1624,7 @@ func validateDirectPostImportData(data *DirectPostImportData) *model.AppError {
|
||||
|
||||
if data.Replies != nil {
|
||||
for _, reply := range *data.Replies {
|
||||
validateReplyImportData(&reply, *data.CreateAt)
|
||||
validateReplyImportData(&reply, *data.CreateAt, maxPostSize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1640,12 +1640,13 @@ func validateDirectPostImportData(data *DirectPostImportData) *model.AppError {
|
||||
func (a *App) OldImportPost(post *model.Post) {
|
||||
// Workaround for empty messages, which may be the case if they are webhook posts.
|
||||
firstIteration := true
|
||||
maxPostSize := a.MaxPostSize()
|
||||
for messageRuneCount := utf8.RuneCountInString(post.Message); messageRuneCount > 0 || firstIteration; messageRuneCount = utf8.RuneCountInString(post.Message) {
|
||||
firstIteration = false
|
||||
var remainder string
|
||||
if messageRuneCount > model.POST_MESSAGE_MAX_RUNES {
|
||||
remainder = string(([]rune(post.Message))[model.POST_MESSAGE_MAX_RUNES:])
|
||||
post.Message = truncateRunes(post.Message, model.POST_MESSAGE_MAX_RUNES)
|
||||
if messageRuneCount > maxPostSize {
|
||||
remainder = string(([]rune(post.Message))[maxPostSize:])
|
||||
post.Message = truncateRunes(post.Message, maxPostSize)
|
||||
} else {
|
||||
remainder = ""
|
||||
}
|
||||
|
||||
@@ -628,12 +628,13 @@ func TestImportValidateReactionImportData(t *testing.T) {
|
||||
func TestImportValidateReplyImportData(t *testing.T) {
|
||||
// Test with minimum required valid properties.
|
||||
parentCreateAt := model.GetMillis() - 100
|
||||
maxPostSize := 10000
|
||||
data := ReplyImportData{
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateReplyImportData(&data, parentCreateAt); err != nil {
|
||||
if err := validateReplyImportData(&data, parentCreateAt, maxPostSize); err != nil {
|
||||
t.Fatal("Validation failed but should have been valid.")
|
||||
}
|
||||
|
||||
@@ -642,7 +643,7 @@ func TestImportValidateReplyImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateReplyImportData(&data, parentCreateAt); err == nil {
|
||||
if err := validateReplyImportData(&data, parentCreateAt, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -650,7 +651,7 @@ func TestImportValidateReplyImportData(t *testing.T) {
|
||||
User: ptrStr("username"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateReplyImportData(&data, parentCreateAt); err == nil {
|
||||
if err := validateReplyImportData(&data, parentCreateAt, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -658,17 +659,17 @@ func TestImportValidateReplyImportData(t *testing.T) {
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr("message"),
|
||||
}
|
||||
if err := validateReplyImportData(&data, parentCreateAt); err == nil {
|
||||
if err := validateReplyImportData(&data, parentCreateAt, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
// Test with invalid message.
|
||||
data = ReplyImportData{
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr(strings.Repeat("1234567890", 500)),
|
||||
Message: ptrStr(strings.Repeat("0", maxPostSize+1)),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateReplyImportData(&data, parentCreateAt); err == nil {
|
||||
if err := validateReplyImportData(&data, parentCreateAt, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to too long message.")
|
||||
}
|
||||
|
||||
@@ -678,7 +679,7 @@ func TestImportValidateReplyImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(0),
|
||||
}
|
||||
if err := validateReplyImportData(&data, parentCreateAt); err == nil {
|
||||
if err := validateReplyImportData(&data, parentCreateAt, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to 0 create-at value.")
|
||||
}
|
||||
|
||||
@@ -687,12 +688,13 @@ func TestImportValidateReplyImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(parentCreateAt - 100),
|
||||
}
|
||||
if err := validateReplyImportData(&data, parentCreateAt); err == nil {
|
||||
if err := validateReplyImportData(&data, parentCreateAt, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due parent with newer create-at value.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportValidatePostImportData(t *testing.T) {
|
||||
maxPostSize := 10000
|
||||
|
||||
// Test with minimum required valid properties.
|
||||
data := PostImportData{
|
||||
@@ -702,7 +704,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validatePostImportData(&data); err != nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err != nil {
|
||||
t.Fatal("Validation failed but should have been valid.")
|
||||
}
|
||||
|
||||
@@ -713,7 +715,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validatePostImportData(&data); err == nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -723,7 +725,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validatePostImportData(&data); err == nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -733,7 +735,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validatePostImportData(&data); err == nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -743,7 +745,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
User: ptrStr("username"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validatePostImportData(&data); err == nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -753,7 +755,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr("message"),
|
||||
}
|
||||
if err := validatePostImportData(&data); err == nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -762,10 +764,10 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
Team: ptrStr("teamname"),
|
||||
Channel: ptrStr("channelname"),
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr(strings.Repeat("1234567890", 500)),
|
||||
Message: ptrStr(strings.Repeat("0", maxPostSize+1)),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validatePostImportData(&data); err == nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to too long message.")
|
||||
}
|
||||
|
||||
@@ -777,7 +779,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(0),
|
||||
}
|
||||
if err := validatePostImportData(&data); err == nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to 0 create-at value.")
|
||||
}
|
||||
|
||||
@@ -801,7 +803,7 @@ func TestImportValidatePostImportData(t *testing.T) {
|
||||
Reactions: &reactions,
|
||||
Replies: &replies,
|
||||
}
|
||||
if err := validatePostImportData(&data); err != nil {
|
||||
if err := validatePostImportData(&data, maxPostSize); err != nil {
|
||||
t.Fatal("Should have succeeded.")
|
||||
}
|
||||
}
|
||||
@@ -917,6 +919,7 @@ func TestImportValidateDirectChannelImportData(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
maxPostSize := 10000
|
||||
|
||||
// Test with minimum required valid properties.
|
||||
data := DirectPostImportData{
|
||||
@@ -928,7 +931,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err != nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err != nil {
|
||||
t.Fatal("Validation failed but should have been valid.")
|
||||
}
|
||||
|
||||
@@ -938,7 +941,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -950,7 +953,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -962,7 +965,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
User: ptrStr("username"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -974,7 +977,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr("message"),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to missing required property.")
|
||||
}
|
||||
|
||||
@@ -985,7 +988,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to unsuitable number of members.")
|
||||
}
|
||||
|
||||
@@ -997,7 +1000,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to unsuitable number of members.")
|
||||
}
|
||||
|
||||
@@ -1018,7 +1021,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to unsuitable number of members.")
|
||||
}
|
||||
|
||||
@@ -1033,7 +1036,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err != nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err != nil {
|
||||
t.Fatal("Validation failed but should have been valid.")
|
||||
}
|
||||
|
||||
@@ -1044,10 +1047,10 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
model.NewId(),
|
||||
},
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr(strings.Repeat("1234567890", 500)),
|
||||
Message: ptrStr(strings.Repeat("0", maxPostSize+1)),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to too long message.")
|
||||
}
|
||||
|
||||
@@ -1061,7 +1064,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(0),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Should have failed due to 0 create-at value.")
|
||||
}
|
||||
|
||||
@@ -1081,7 +1084,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err == nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err == nil {
|
||||
t.Fatal("Validation should have failed due to non-member flagged.")
|
||||
}
|
||||
|
||||
@@ -1099,7 +1102,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
}
|
||||
if err := validateDirectPostImportData(&data); err != nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1130,7 +1133,7 @@ func TestImportValidateDirectPostImportData(t *testing.T) {
|
||||
Replies: &replies,
|
||||
}
|
||||
|
||||
if err := validateDirectPostImportData(&data); err != nil {
|
||||
if err := validateDirectPostImportData(&data, maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
11
app/post.go
11
app/post.go
@@ -958,3 +958,14 @@ func (a *App) ImageProxyRemover() (f func(string) string) {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) MaxPostSize() int {
|
||||
maxPostSize := model.POST_MESSAGE_MAX_RUNES_V1
|
||||
if result := <-a.Srv.Store.Post().GetMaxPostSize(); result.Err != nil {
|
||||
l4g.Error(result.Err)
|
||||
} else {
|
||||
maxPostSize = result.Data.(int)
|
||||
}
|
||||
|
||||
return maxPostSize
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -17,6 +18,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/store/storetest"
|
||||
)
|
||||
|
||||
func TestUpdatePostEditAt(t *testing.T) {
|
||||
@@ -383,3 +386,59 @@ func TestMakeOpenGraphURLsAbsolute(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxPostSize(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
Description string
|
||||
StoreMaxPostSize int
|
||||
ExpectedMaxPostSize int
|
||||
ExpectedError *model.AppError
|
||||
}{
|
||||
{
|
||||
"error fetching max post size",
|
||||
0,
|
||||
model.POST_MESSAGE_MAX_RUNES_V1,
|
||||
model.NewAppError("TestMaxPostSize", "this is an error", nil, "", http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
"4000 rune limit",
|
||||
4000,
|
||||
4000,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"16383 rune limit",
|
||||
16383,
|
||||
16383,
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(testCase.Description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockStore := &storetest.Store{}
|
||||
defer mockStore.AssertExpectations(t)
|
||||
|
||||
mockStore.PostStore.On("GetMaxPostSize").Return(
|
||||
storetest.NewStoreChannel(store.StoreResult{
|
||||
Data: testCase.StoreMaxPostSize,
|
||||
Err: testCase.ExpectedError,
|
||||
}),
|
||||
)
|
||||
|
||||
app := App{
|
||||
Srv: &Server{
|
||||
Store: mockStore,
|
||||
},
|
||||
config: atomic.Value{},
|
||||
}
|
||||
|
||||
assert.Equal(t, testCase.ExpectedMaxPostSize, app.MaxPostSize())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@@ -149,8 +150,10 @@ func (a *App) StartServer() error {
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.Forward80To443 {
|
||||
if host, _, err := net.SplitHostPort(addr); err != nil {
|
||||
if host, port, err := net.SplitHostPort(addr); err != nil {
|
||||
l4g.Error("Unable to setup forwarding: " + err.Error())
|
||||
} else if port != "443" {
|
||||
return fmt.Errorf(utils.T("api.server.start_server.forward80to443.enabled_but_listening_on_wrong_port"), port)
|
||||
} else {
|
||||
httpListenAddress := net.JoinHostPort(host, "http")
|
||||
|
||||
@@ -169,6 +172,8 @@ func (a *App) StartServer() error {
|
||||
}()
|
||||
}
|
||||
}
|
||||
} else if *a.Config().ServiceSettings.UseLetsEncrypt {
|
||||
return errors.New(utils.T("api.server.start_server.forward80to443.disabled_while_using_lets_encrypt"))
|
||||
}
|
||||
|
||||
a.Srv.didFinishListen = make(chan struct{})
|
||||
|
||||
@@ -940,6 +940,8 @@ func (a *App) UpdateActive(user *model.User, active bool) (*model.User, *model.A
|
||||
}
|
||||
}
|
||||
|
||||
a.sendUpdatedUserEvent(*ruser, false)
|
||||
|
||||
return ruser, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.
|
||||
}
|
||||
}
|
||||
|
||||
func SplitWebhookPost(post *model.Post) ([]*model.Post, *model.AppError) {
|
||||
func SplitWebhookPost(post *model.Post, maxPostSize int) ([]*model.Post, *model.AppError) {
|
||||
splits := make([]*model.Post, 0)
|
||||
remainingText := post.Message
|
||||
|
||||
@@ -159,12 +159,12 @@ func SplitWebhookPost(post *model.Post) ([]*model.Post, *model.AppError) {
|
||||
return nil, model.NewAppError("SplitWebhookPost", "web.incoming_webhook.split_props_length.app_error", map[string]interface{}{"Max": model.POST_PROPS_MAX_USER_RUNES}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
for utf8.RuneCountInString(remainingText) > model.POST_MESSAGE_MAX_RUNES {
|
||||
for utf8.RuneCountInString(remainingText) > maxPostSize {
|
||||
split := base
|
||||
x := 0
|
||||
for index := range remainingText {
|
||||
x++
|
||||
if x > model.POST_MESSAGE_MAX_RUNES {
|
||||
if x > maxPostSize {
|
||||
split.Message = remainingText[:index]
|
||||
remainingText = remainingText[index:]
|
||||
break
|
||||
@@ -266,7 +266,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
}
|
||||
}
|
||||
|
||||
splits, err := SplitWebhookPost(post)
|
||||
splits, err := SplitWebhookPost(post, a.MaxPostSize())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -383,23 +383,25 @@ func TestSplitWebhookPost(t *testing.T) {
|
||||
Expected []*model.Post
|
||||
}
|
||||
|
||||
maxPostSize := 10000
|
||||
|
||||
for name, tc := range map[string]TestCase{
|
||||
"LongPost": {
|
||||
Post: &model.Post{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES*3/2),
|
||||
Message: strings.Repeat("本", maxPostSize*3/2),
|
||||
},
|
||||
Expected: []*model.Post{
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES),
|
||||
Message: strings.Repeat("本", maxPostSize),
|
||||
},
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES/2),
|
||||
Message: strings.Repeat("本", maxPostSize/2),
|
||||
},
|
||||
},
|
||||
},
|
||||
"LongPostAndMultipleAttachments": {
|
||||
Post: &model.Post{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES*3/2),
|
||||
Message: strings.Repeat("本", maxPostSize*3/2),
|
||||
Props: map[string]interface{}{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
@@ -416,10 +418,10 @@ func TestSplitWebhookPost(t *testing.T) {
|
||||
},
|
||||
Expected: []*model.Post{
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES),
|
||||
Message: strings.Repeat("本", maxPostSize),
|
||||
},
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES/2),
|
||||
Message: strings.Repeat("本", maxPostSize/2),
|
||||
Props: map[string]interface{}{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
@@ -452,7 +454,7 @@ func TestSplitWebhookPost(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
splits, err := SplitWebhookPost(tc.Post)
|
||||
splits, err := SplitWebhookPost(tc.Post, maxPostSize)
|
||||
if tc.Expected == nil {
|
||||
require.NotNil(t, err)
|
||||
} else {
|
||||
|
||||
@@ -333,6 +333,13 @@ func createUser(idx int, teamMemberships int, channelMemberships int, teamsAndCh
|
||||
firstName := fake.FirstName()
|
||||
lastName := fake.LastName()
|
||||
username := fmt.Sprintf("%s.%s", strings.ToLower(firstName), strings.ToLower(lastName))
|
||||
if idx == 0 {
|
||||
username = "sysadmin"
|
||||
password = "sysadmin"
|
||||
email = "sysadmin@sample.mattermost.com"
|
||||
} else if idx == 1 {
|
||||
username = "user-1"
|
||||
}
|
||||
position := fake.JobTitle()
|
||||
roles := "system_user"
|
||||
if idx%5 == 0 {
|
||||
|
||||
6
glide.lock
generated
6
glide.lock
generated
@@ -1,5 +1,5 @@
|
||||
hash: 822849f55f8ab4b5c7545597b209edb6114bcf1009a552a9ee2503ff8d3fda09
|
||||
updated: 2018-03-07T13:01:49.575101746+01:00
|
||||
hash: 287b82849f1c7303ee3eb29c9d0879d404469f7df2ba9b37828e55b0320ef11f
|
||||
updated: 2018-03-21T13:01:34.996412416+01:00
|
||||
imports:
|
||||
- name: github.com/alecthomas/log4go
|
||||
version: 3fbce08846379ec7f4f6bc7fce6dd01ce28fae4c
|
||||
@@ -63,6 +63,8 @@ imports:
|
||||
version: afe77393c53b66afe9212810d9b2013859d04ae6
|
||||
- name: github.com/gorilla/websocket
|
||||
version: 4ac909741dfa57448bfadfdbca0cf7eeaa68f0e2
|
||||
- name: github.com/hako/durafmt
|
||||
version: 987f93c94e473e74aadc826871e61ae6b3360ebb
|
||||
- name: github.com/hashicorp/errwrap
|
||||
version: 7554cd9344cec97297fa6649b055a8c98c2a1e55
|
||||
- name: github.com/hashicorp/go-immutable-radix
|
||||
|
||||
@@ -34,7 +34,6 @@ import:
|
||||
version: 4.0.7
|
||||
subpackages:
|
||||
- pkg/credentials
|
||||
- package: github.com/mssola/user_agent
|
||||
- package: github.com/nicksnyder/go-i18n
|
||||
version: v1.10.0
|
||||
subpackages:
|
||||
@@ -78,3 +77,4 @@ import:
|
||||
- store/memstore
|
||||
- package: gopkg.in/yaml.v2
|
||||
- package: github.com/avct/uasurfer
|
||||
- package: github.com/hako/durafmt
|
||||
|
||||
20
i18n/en.json
20
i18n/en.json
@@ -1958,6 +1958,14 @@
|
||||
"id": "api.server.new_server.init.info",
|
||||
"translation": "Server is initializing..."
|
||||
},
|
||||
{
|
||||
"id": "api.server.start_server.forward80to443.disabled_while_using_lets_encrypt",
|
||||
"translation": "Must enable Forward80To443 when using LetsEncrypt"
|
||||
},
|
||||
{
|
||||
"id": "api.server.start_server.forward80to443.enabled_but_listening_on_wrong_port",
|
||||
"translation": "Cannot forward port 80 to port 443 while listening on port %s: disable Forward80To443 if using a proxy server"
|
||||
},
|
||||
{
|
||||
"id": "api.server.start_server.listening.info",
|
||||
"translation": "Server is listening on %v"
|
||||
@@ -6450,6 +6458,18 @@
|
||||
"id": "store.sql_post.permanent_delete_by_user.too_many.app_error",
|
||||
"translation": "We couldn't select the posts to delete for the user (too many), please re-run"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_post.query_max_post_size.error",
|
||||
"translation": "We couldn't determine the maximum supported post size"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_post.query_max_post_size.unrecognized_driver",
|
||||
"translation": "No implementation found to determine the maximum supported post size"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_post.query_max_post_size.max_post_size_bytes",
|
||||
"translation": "Post.Message supports at most %d bytes"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_post.save.app_error",
|
||||
"translation": "We couldn't save the Post"
|
||||
|
||||
@@ -1748,6 +1748,17 @@ func (c *Client4) RemoveUserFromChannel(channelId, userId string) (bool, *Respon
|
||||
}
|
||||
}
|
||||
|
||||
// AutocompleteChannelsForTeam will return an ordered list of channels autocomplete suggestions
|
||||
func (c *Client4) AutocompleteChannelsForTeam(teamId, name string) (*ChannelList, *Response) {
|
||||
query := fmt.Sprintf("?name=%v", name)
|
||||
if r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+"/autocomplete"+query, ""); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return ChannelListFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// Post Section
|
||||
|
||||
// CreatePost creates a post based on the provided post struct.
|
||||
|
||||
@@ -23,6 +23,11 @@ type Emoji struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func inSystemEmoji(emojiName string) bool {
|
||||
_, ok := SystemEmojis[emojiName]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (emoji *Emoji) IsValid() *AppError {
|
||||
if len(emoji.Id) != 26 {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.id.app_error", nil, "", http.StatusBadRequest)
|
||||
@@ -40,7 +45,7 @@ func (emoji *Emoji) IsValid() *AppError {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(emoji.Name) == 0 || len(emoji.Name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscore(emoji.Name, false) {
|
||||
if len(emoji.Name) == 0 || len(emoji.Name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscore(emoji.Name, false) || inSystemEmoji(emoji.Name) {
|
||||
return NewAppError("Emoji.IsValid", "model.emoji.name.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
|
||||
6
model/emoji_data.go
Normal file
6
model/emoji_data.go
Normal file
File diff suppressed because one or more lines are too long
@@ -80,4 +80,9 @@ func TestEmojiIsValid(t *testing.T) {
|
||||
if err := emoji.IsValid(); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
emoji.Name = "croissant"
|
||||
if err := emoji.IsValid(); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,9 @@ const (
|
||||
POST_FILEIDS_MAX_RUNES = 150
|
||||
POST_FILENAMES_MAX_RUNES = 4000
|
||||
POST_HASHTAGS_MAX_RUNES = 1000
|
||||
POST_MESSAGE_MAX_RUNES = 4000
|
||||
POST_MESSAGE_MAX_RUNES_V1 = 4000
|
||||
POST_MESSAGE_MAX_BYTES_V2 = 65535 // Maximum size of a TEXT column in MySQL
|
||||
POST_MESSAGE_MAX_RUNES_V2 = POST_MESSAGE_MAX_BYTES_V2 / 4 // Assume a worst-case representation
|
||||
POST_PROPS_MAX_RUNES = 8000
|
||||
POST_PROPS_MAX_USER_RUNES = POST_PROPS_MAX_RUNES - 400 // Leave some room for system / pre-save modifications
|
||||
POST_CUSTOM_TYPE_PREFIX = "custom_"
|
||||
@@ -141,7 +143,7 @@ func (o *Post) Etag() string {
|
||||
return Etag(o.Id, o.UpdateAt)
|
||||
}
|
||||
|
||||
func (o *Post) IsValid() *AppError {
|
||||
func (o *Post) IsValid(maxPostSize int) *AppError {
|
||||
|
||||
if len(o.Id) != 26 {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
||||
@@ -179,7 +181,7 @@ func (o *Post) IsValid() *AppError {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.original_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Message) > POST_MESSAGE_MAX_RUNES {
|
||||
if utf8.RuneCountInString(o.Message) > maxPostSize {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.msg.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,72 +23,73 @@ func TestPostJson(t *testing.T) {
|
||||
|
||||
func TestPostIsValid(t *testing.T) {
|
||||
o := Post{}
|
||||
maxPostSize := 10000
|
||||
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.Id = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.UpdateAt = GetMillis()
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.UserId = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.ChannelId = NewId()
|
||||
o.RootId = "123"
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.RootId = ""
|
||||
o.ParentId = "123"
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.ParentId = NewId()
|
||||
o.RootId = ""
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.ParentId = ""
|
||||
o.Message = strings.Repeat("0", 4001)
|
||||
if err := o.IsValid(); err == nil {
|
||||
o.Message = strings.Repeat("0", maxPostSize+1)
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.Message = strings.Repeat("0", 4000)
|
||||
if err := o.IsValid(); err != nil {
|
||||
o.Message = strings.Repeat("0", maxPostSize)
|
||||
if err := o.IsValid(maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
o.Message = "test"
|
||||
if err := o.IsValid(); err != nil {
|
||||
if err := o.IsValid(maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
o.Type = "junk"
|
||||
if err := o.IsValid(); err == nil {
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.Type = POST_CUSTOM_TYPE_PREFIX + "type"
|
||||
if err := o.IsValid(); err != nil {
|
||||
if err := o.IsValid(maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"bytes"
|
||||
"sync"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
@@ -21,7 +21,11 @@ import (
|
||||
|
||||
type SqlPostStore struct {
|
||||
SqlStore
|
||||
metrics einterfaces.MetricsInterface
|
||||
metrics einterfaces.MetricsInterface
|
||||
lastPostTimeCache *utils.Cache
|
||||
lastPostsCache *utils.Cache
|
||||
maxPostSizeOnce sync.Once
|
||||
maxPostSizeCached int
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -32,12 +36,9 @@ const (
|
||||
LAST_POSTS_CACHE_SEC = 900 // 15 minutes
|
||||
)
|
||||
|
||||
var lastPostTimeCache = utils.NewLru(LAST_POST_TIME_CACHE_SIZE)
|
||||
var lastPostsCache = utils.NewLru(LAST_POSTS_CACHE_SIZE)
|
||||
|
||||
func (s SqlPostStore) ClearCaches() {
|
||||
lastPostTimeCache.Purge()
|
||||
lastPostsCache.Purge()
|
||||
func (s *SqlPostStore) ClearCaches() {
|
||||
s.lastPostTimeCache.Purge()
|
||||
s.lastPostsCache.Purge()
|
||||
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Last Post Time - Purge")
|
||||
@@ -47,8 +48,11 @@ func (s SqlPostStore) ClearCaches() {
|
||||
|
||||
func NewSqlPostStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.PostStore {
|
||||
s := &SqlPostStore{
|
||||
SqlStore: sqlStore,
|
||||
metrics: metrics,
|
||||
SqlStore: sqlStore,
|
||||
metrics: metrics,
|
||||
lastPostTimeCache: utils.NewLru(LAST_POST_TIME_CACHE_SIZE),
|
||||
lastPostsCache: utils.NewLru(LAST_POSTS_CACHE_SIZE),
|
||||
maxPostSizeCached: model.POST_MESSAGE_MAX_RUNES_V1,
|
||||
}
|
||||
|
||||
for _, db := range sqlStore.GetAllConns() {
|
||||
@@ -59,18 +63,18 @@ func NewSqlPostStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) st
|
||||
table.ColMap("RootId").SetMaxSize(26)
|
||||
table.ColMap("ParentId").SetMaxSize(26)
|
||||
table.ColMap("OriginalId").SetMaxSize(26)
|
||||
table.ColMap("Message").SetMaxSize(4000)
|
||||
table.ColMap("Message").SetMaxSize(model.POST_MESSAGE_MAX_BYTES_V2)
|
||||
table.ColMap("Type").SetMaxSize(26)
|
||||
table.ColMap("Hashtags").SetMaxSize(1000)
|
||||
table.ColMap("Props").SetMaxSize(8000)
|
||||
table.ColMap("Filenames").SetMaxSize(4000)
|
||||
table.ColMap("Filenames").SetMaxSize(model.POST_FILENAMES_MAX_RUNES)
|
||||
table.ColMap("FileIds").SetMaxSize(150)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SqlPostStore) CreateIndexesIfNotExists() {
|
||||
func (s *SqlPostStore) CreateIndexesIfNotExists() {
|
||||
s.CreateIndexIfNotExists("idx_posts_update_at", "Posts", "UpdateAt")
|
||||
s.CreateIndexIfNotExists("idx_posts_create_at", "Posts", "CreateAt")
|
||||
s.CreateIndexIfNotExists("idx_posts_delete_at", "Posts", "DeleteAt")
|
||||
@@ -86,15 +90,23 @@ func (s SqlPostStore) CreateIndexesIfNotExists() {
|
||||
s.CreateFullTextIndexIfNotExists("idx_posts_hashtags_txt", "Posts", "Hashtags")
|
||||
}
|
||||
|
||||
func (s SqlPostStore) Save(post *model.Post) store.StoreChannel {
|
||||
func (s *SqlPostStore) Save(post *model.Post) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if len(post.Id) > 0 {
|
||||
result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.save.existing.app_error", nil, "id="+post.Id, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var maxPostSize int
|
||||
if result := <-s.GetMaxPostSize(); result.Err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.save.app_error", nil, "id="+post.Id+", "+result.Err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
maxPostSize = result.Data.(int)
|
||||
}
|
||||
|
||||
post.PreSave()
|
||||
if result.Err = post.IsValid(); result.Err != nil {
|
||||
if result.Err = post.IsValid(maxPostSize); result.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -122,7 +134,7 @@ func (s SqlPostStore) Save(post *model.Post) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) store.StoreChannel {
|
||||
func (s *SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
newPost.UpdateAt = model.GetMillis()
|
||||
newPost.PreCommit()
|
||||
@@ -133,7 +145,15 @@ func (s SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) store.Sto
|
||||
oldPost.Id = model.NewId()
|
||||
oldPost.PreCommit()
|
||||
|
||||
if result.Err = newPost.IsValid(); result.Err != nil {
|
||||
var maxPostSize int
|
||||
if result := <-s.GetMaxPostSize(); result.Err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.update.app_error", nil, "id="+newPost.Id+", "+result.Err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
maxPostSize = result.Data.(int)
|
||||
}
|
||||
|
||||
if result.Err = newPost.IsValid(maxPostSize); result.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -155,11 +175,19 @@ func (s SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) store.Sto
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) Overwrite(post *model.Post) store.StoreChannel {
|
||||
func (s *SqlPostStore) Overwrite(post *model.Post) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
post.UpdateAt = model.GetMillis()
|
||||
|
||||
if result.Err = post.IsValid(); result.Err != nil {
|
||||
var maxPostSize int
|
||||
if result := <-s.GetMaxPostSize(); result.Err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.overwrite.app_error", nil, "id="+post.Id+", "+result.Err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
maxPostSize = result.Data.(int)
|
||||
}
|
||||
|
||||
if result.Err = post.IsValid(maxPostSize); result.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -171,7 +199,7 @@ func (s SqlPostStore) Overwrite(post *model.Post) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetFlaggedPosts(userId string, offset int, limit int) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetFlaggedPosts(userId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
pl := model.NewPostList()
|
||||
|
||||
@@ -189,7 +217,7 @@ func (s SqlPostStore) GetFlaggedPosts(userId string, offset int, limit int) stor
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
pl := model.NewPostList()
|
||||
|
||||
@@ -234,7 +262,7 @@ func (s SqlPostStore) GetFlaggedPostsForTeam(userId, teamId string, offset int,
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
pl := model.NewPostList()
|
||||
|
||||
@@ -263,7 +291,7 @@ func (s SqlPostStore) GetFlaggedPostsForChannel(userId, channelId string, offset
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) Get(id string) store.StoreChannel {
|
||||
func (s *SqlPostStore) Get(id string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
pl := model.NewPostList()
|
||||
|
||||
@@ -308,7 +336,7 @@ func (s SqlPostStore) Get(id string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetSingle(id string) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetSingle(id string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var post model.Post
|
||||
err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id})
|
||||
@@ -325,12 +353,12 @@ type etagPosts struct {
|
||||
UpdateAt int64
|
||||
}
|
||||
|
||||
func (s SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
lastPostTimeCache.Remove(channelId)
|
||||
func (s *SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
s.lastPostTimeCache.Remove(channelId)
|
||||
|
||||
// Keys are "{channelid}{limit}" and caching only occurs on limits of 30 and 60
|
||||
lastPostsCache.Remove(channelId + "30")
|
||||
lastPostsCache.Remove(channelId + "60")
|
||||
s.lastPostsCache.Remove(channelId + "30")
|
||||
s.lastPostsCache.Remove(channelId + "60")
|
||||
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Last Post Time - Remove by Channel Id")
|
||||
@@ -338,10 +366,10 @@ func (s SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if allowFromCache {
|
||||
if cacheItem, ok := lastPostTimeCache.Get(channelId); ok {
|
||||
if cacheItem, ok := s.lastPostTimeCache.Get(channelId); ok {
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheHitCounter("Last Post Time")
|
||||
}
|
||||
@@ -366,11 +394,11 @@ func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.Store
|
||||
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, et.UpdateAt)
|
||||
}
|
||||
|
||||
lastPostTimeCache.AddWithExpiresInSecs(channelId, et.UpdateAt, LAST_POST_TIME_CACHE_SEC)
|
||||
s.lastPostTimeCache.AddWithExpiresInSecs(channelId, et.UpdateAt, LAST_POST_TIME_CACHE_SEC)
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) Delete(postId string, time int64) store.StoreChannel {
|
||||
func (s *SqlPostStore) Delete(postId string, time int64) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
_, err := s.GetMaster().Exec("Update Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId})
|
||||
if err != nil {
|
||||
@@ -379,7 +407,7 @@ func (s SqlPostStore) Delete(postId string, time int64) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) permanentDelete(postId string) store.StoreChannel {
|
||||
func (s *SqlPostStore) permanentDelete(postId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
_, err := s.GetMaster().Exec("DELETE FROM Posts WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"Id": postId, "RootId": postId})
|
||||
if err != nil {
|
||||
@@ -388,7 +416,7 @@ func (s SqlPostStore) permanentDelete(postId string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) store.StoreChannel {
|
||||
func (s *SqlPostStore) permanentDeleteAllCommentByUser(userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
_, err := s.GetMaster().Exec("DELETE FROM Posts WHERE UserId = :UserId AND RootId != ''", map[string]interface{}{"UserId": userId})
|
||||
if err != nil {
|
||||
@@ -397,7 +425,7 @@ func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) store.Store
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) PermanentDeleteByUser(userId string) store.StoreChannel {
|
||||
func (s *SqlPostStore) PermanentDeleteByUser(userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
// First attempt to delete all the comments for a user
|
||||
if r := <-s.permanentDeleteAllCommentByUser(userId); r.Err != nil {
|
||||
@@ -437,7 +465,7 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) PermanentDeleteByChannel(channelId string) store.StoreChannel {
|
||||
func (s *SqlPostStore) PermanentDeleteByChannel(channelId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Posts WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.PermanentDeleteByChannel", "store.sql_post.permanent_delete_by_channel.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
|
||||
@@ -445,7 +473,7 @@ func (s SqlPostStore) PermanentDeleteByChannel(channelId string) store.StoreChan
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFromCache bool) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFromCache bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if limit > 1000 {
|
||||
result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_posts.app_error", nil, "channelId="+channelId, http.StatusBadRequest)
|
||||
@@ -454,7 +482,7 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro
|
||||
|
||||
// Caching only occurs on limits of 30 and 60, the common limits requested by MM clients
|
||||
if allowFromCache && offset == 0 && (limit == 60 || limit == 30) {
|
||||
if cacheItem, ok := lastPostsCache.Get(fmt.Sprintf("%s%v", channelId, limit)); ok {
|
||||
if cacheItem, ok := s.lastPostsCache.Get(fmt.Sprintf("%s%v", channelId, limit)); ok {
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheHitCounter("Last Posts Cache")
|
||||
}
|
||||
@@ -498,7 +526,7 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro
|
||||
|
||||
// Caching only occurs on limits of 30 and 60, the common limits requested by MM clients
|
||||
if offset == 0 && (limit == 60 || limit == 30) {
|
||||
lastPostsCache.AddWithExpiresInSecs(fmt.Sprintf("%s%v", channelId, limit), list, LAST_POSTS_CACHE_SEC)
|
||||
s.lastPostsCache.AddWithExpiresInSecs(fmt.Sprintf("%s%v", channelId, limit), list, LAST_POSTS_CACHE_SEC)
|
||||
}
|
||||
|
||||
result.Data = list
|
||||
@@ -506,12 +534,12 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if allowFromCache {
|
||||
// If the last post in the channel's time is less than or equal to the time we are getting posts since,
|
||||
// we can safely return no posts.
|
||||
if cacheItem, ok := lastPostTimeCache.Get(channelId); ok && cacheItem.(int64) <= time {
|
||||
if cacheItem, ok := s.lastPostTimeCache.Get(channelId); ok && cacheItem.(int64) <= time {
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheHitCounter("Last Post Time")
|
||||
}
|
||||
@@ -576,22 +604,22 @@ func (s SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache
|
||||
}
|
||||
}
|
||||
|
||||
lastPostTimeCache.AddWithExpiresInSecs(channelId, latestUpdate, LAST_POST_TIME_CACHE_SEC)
|
||||
s.lastPostTimeCache.AddWithExpiresInSecs(channelId, latestUpdate, LAST_POST_TIME_CACHE_SEC)
|
||||
|
||||
result.Data = list
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPostsBefore(channelId string, postId string, numPosts int, offset int) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetPostsBefore(channelId string, postId string, numPosts int, offset int) store.StoreChannel {
|
||||
return s.getPostsAround(channelId, postId, numPosts, offset, true)
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPostsAfter(channelId string, postId string, numPosts int, offset int) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetPostsAfter(channelId string, postId string, numPosts int, offset int) store.StoreChannel {
|
||||
return s.getPostsAround(channelId, postId, numPosts, offset, false)
|
||||
}
|
||||
|
||||
func (s SqlPostStore) getPostsAround(channelId string, postId string, numPosts int, offset int, before bool) store.StoreChannel {
|
||||
func (s *SqlPostStore) getPostsAround(channelId string, postId string, numPosts int, offset int, before bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var direction string
|
||||
var sort string
|
||||
@@ -672,7 +700,7 @@ func (s SqlPostStore) getPostsAround(channelId string, postId string, numPosts i
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) store.StoreChannel {
|
||||
func (s *SqlPostStore) getRootPosts(channelId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var posts []*model.Post
|
||||
_, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt DESC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit})
|
||||
@@ -684,7 +712,7 @@ func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) stor
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) getParentsPosts(channelId string, offset int, limit int) store.StoreChannel {
|
||||
func (s *SqlPostStore) getParentsPosts(channelId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var posts []*model.Post
|
||||
_, err := s.GetReplica().Select(&posts, `
|
||||
@@ -771,7 +799,7 @@ var specialSearchChar = []string{
|
||||
":",
|
||||
}
|
||||
|
||||
func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchParams) store.StoreChannel {
|
||||
func (s *SqlPostStore) Search(teamId string, userId string, params *model.SearchParams) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
queryParams := map[string]interface{}{
|
||||
"TeamId": teamId,
|
||||
@@ -945,7 +973,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) store.StoreChannel {
|
||||
func (s *SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT DISTINCT
|
||||
@@ -998,7 +1026,7 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) store.Sto
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) store.StoreChannel {
|
||||
func (s *SqlPostStore) AnalyticsPostCountsByDay(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT
|
||||
@@ -1053,7 +1081,7 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) store.StoreChannel
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) store.StoreChannel {
|
||||
func (s *SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT
|
||||
@@ -1084,7 +1112,7 @@ func (s SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustH
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPostsCreatedAt(channelId string, time int64) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetPostsCreatedAt(channelId string, time int64) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := `SELECT * FROM Posts WHERE CreateAt = :CreateAt AND ChannelId = :ChannelId`
|
||||
|
||||
@@ -1099,7 +1127,7 @@ func (s SqlPostStore) GetPostsCreatedAt(channelId string, time int64) store.Stor
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPostsByIds(postIds []string) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetPostsByIds(postIds []string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
keys := bytes.Buffer{}
|
||||
params := make(map[string]interface{})
|
||||
@@ -1127,7 +1155,7 @@ func (s SqlPostStore) GetPostsByIds(postIds []string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) store.StoreChannel {
|
||||
func (s *SqlPostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var posts []*model.PostForIndexing
|
||||
_, err1 := s.GetSearchReplica().Select(&posts,
|
||||
@@ -1167,7 +1195,7 @@ func (s SqlPostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, l
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) store.StoreChannel {
|
||||
func (s *SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var query string
|
||||
if s.DriverName() == "postgres" {
|
||||
@@ -1191,7 +1219,7 @@ func (s SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) store.Sto
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetOldest() store.StoreChannel {
|
||||
func (s *SqlPostStore) GetOldest() store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var post model.Post
|
||||
err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts ORDER BY CreateAt LIMIT 1")
|
||||
@@ -1202,3 +1230,66 @@ func (s SqlPostStore) GetOldest() store.StoreChannel {
|
||||
result.Data = &post
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) determineMaxPostSize() int {
|
||||
var maxPostSize int = model.POST_MESSAGE_MAX_RUNES_V1
|
||||
var maxPostSizeBytes int32
|
||||
|
||||
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
// The Post.Message column in Postgres has historically been VARCHAR(4000), but
|
||||
// may be manually enlarged to support longer posts.
|
||||
if err := s.GetReplica().SelectOne(&maxPostSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(character_maximum_length, 0)
|
||||
FROM
|
||||
information_schema.columns
|
||||
WHERE
|
||||
table_name = 'posts'
|
||||
AND column_name = 'message'
|
||||
`); err != nil {
|
||||
l4g.Error(utils.T("store.sql_post.query_max_post_size.error") + err.Error())
|
||||
}
|
||||
} else if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
// The Post.Message column in MySQL has historically been TEXT, with a maximum
|
||||
// limit of 65535.
|
||||
if err := s.GetReplica().SelectOne(&maxPostSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(CHARACTER_MAXIMUM_LENGTH, 0)
|
||||
FROM
|
||||
INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE
|
||||
table_schema = DATABASE()
|
||||
AND table_name = 'Posts'
|
||||
AND column_name = 'Message'
|
||||
LIMIT 0, 1
|
||||
`); err != nil {
|
||||
l4g.Error(utils.T("store.sql_post.query_max_post_size.error") + err.Error())
|
||||
}
|
||||
} else {
|
||||
l4g.Warn(utils.T("store.sql_post.query_max_post_size.unrecognized_driver"))
|
||||
}
|
||||
|
||||
l4g.Trace(utils.T("store.sql_post.query_max_post_size.max_post_size_bytes"), maxPostSizeBytes)
|
||||
|
||||
// Assume a worst-case representation of four bytes per rune.
|
||||
maxPostSize = int(maxPostSizeBytes) / 4
|
||||
|
||||
// To maintain backwards compatibility, don't yield a maximum post
|
||||
// size smaller than the previous limit, even though it wasn't
|
||||
// actually possible to store 4000 runes in all cases.
|
||||
if maxPostSize < model.POST_MESSAGE_MAX_RUNES_V1 {
|
||||
maxPostSize = model.POST_MESSAGE_MAX_RUNES_V1
|
||||
}
|
||||
|
||||
return maxPostSize
|
||||
}
|
||||
|
||||
// GetMaxPostSize returns the maximum number of runes that may be stored in a post.
|
||||
func (s *SqlPostStore) GetMaxPostSize() store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
s.maxPostSizeOnce.Do(func() {
|
||||
s.maxPostSizeCached = s.determineMaxPostSize()
|
||||
})
|
||||
result.Data = s.maxPostSizeCached
|
||||
})
|
||||
}
|
||||
|
||||
@@ -199,6 +199,7 @@ type PostStore interface {
|
||||
GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel
|
||||
PermanentDeleteBatch(endTime int64, limit int64) StoreChannel
|
||||
GetOldest() StoreChannel
|
||||
GetMaxPostSize() StoreChannel
|
||||
}
|
||||
|
||||
type UserStore interface {
|
||||
|
||||
@@ -422,3 +422,18 @@ func (_m *PostStore) Update(newPost *model.Post, oldPost *model.Post) store.Stor
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
func (_m *PostStore) GetMaxPostSize() store.StoreChannel {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ func TestPostStore(t *testing.T, ss store.Store) {
|
||||
t.Run("GetPostsBatchForIndexing", func(t *testing.T) { testPostStoreGetPostsBatchForIndexing(t, ss) })
|
||||
t.Run("PermanentDeleteBatch", func(t *testing.T) { testPostStorePermanentDeleteBatch(t, ss) })
|
||||
t.Run("GetOldest", func(t *testing.T) { testPostStoreGetOldest(t, ss) })
|
||||
t.Run("TestGetMaxPostSize", func(t *testing.T) { testGetMaxPostSize(t, ss) })
|
||||
}
|
||||
|
||||
func testPostStoreSave(t *testing.T, ss store.Store) {
|
||||
@@ -1783,3 +1784,8 @@ func testPostStoreGetOldest(t *testing.T, ss store.Store) {
|
||||
|
||||
assert.EqualValues(t, o2.Id, r1.Id)
|
||||
}
|
||||
|
||||
func testGetMaxPostSize(t *testing.T, ss store.Store) {
|
||||
assert.Equal(t, model.POST_MESSAGE_MAX_RUNES_V2, (<-ss.Post().GetMaxPostSize()).Data.(int))
|
||||
assert.Equal(t, model.POST_MESSAGE_MAX_RUNES_V2, (<-ss.Post().GetMaxPostSize()).Data.(int))
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<li><span class="bold">Channel: </span>{{.Props.ChannelName}}</li>
|
||||
<li><span class="bold">Started: </span>{{.Props.Started}}</li>
|
||||
<li><span class="bold">Ended: </span>{{.Props.Ended}}</li>
|
||||
<li><span class="bold">Duration: </span>{{.Props.Duration}} Minutes</li>
|
||||
<li><span class="bold">Duration: </span>{{.Props.Duration}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<table class="participants">
|
||||
@@ -88,4 +88,4 @@
|
||||
</div>
|
||||
|
||||
<p>Exported on {{.Props.ExportDate}}</p>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<td class="email">{{.Props.Email}}</td>
|
||||
<td class="joined">{{.Props.Joined}}</td>
|
||||
<td class="left">{{.Props.Left}}</td>
|
||||
<td class="duration">{{.Props.DurationMinutes}} Minutes</td>
|
||||
<td class="duration">{{.Props.Duration}}</td>
|
||||
<td class="messages">{{.Props.NumMessages}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
@@ -29,7 +29,8 @@ func encodeRFC2047Word(s string) string {
|
||||
type SmtpConnectionInfo struct {
|
||||
SmtpUsername string
|
||||
SmtpPassword string
|
||||
SmtpServer string
|
||||
SmtpServerName string
|
||||
SmtpServerHost string
|
||||
SmtpPort string
|
||||
SkipCertVerification bool
|
||||
ConnectionSecurity string
|
||||
@@ -42,11 +43,11 @@ type authChooser struct {
|
||||
}
|
||||
|
||||
func (a *authChooser) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
||||
smtpAddress := a.connectionInfo.SmtpServer + ":" + a.connectionInfo.SmtpPort
|
||||
smtpAddress := a.connectionInfo.SmtpServerName + ":" + a.connectionInfo.SmtpPort
|
||||
a.Auth = LoginAuth(a.connectionInfo.SmtpUsername, a.connectionInfo.SmtpPassword, smtpAddress)
|
||||
for _, method := range server.Auth {
|
||||
if method == "PLAIN" {
|
||||
a.Auth = smtp.PlainAuth("", a.connectionInfo.SmtpUsername, a.connectionInfo.SmtpPassword, a.connectionInfo.SmtpServer+":"+a.connectionInfo.SmtpPort)
|
||||
a.Auth = smtp.PlainAuth("", a.connectionInfo.SmtpUsername, a.connectionInfo.SmtpPassword, a.connectionInfo.SmtpServerName+":"+a.connectionInfo.SmtpPort)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -91,11 +92,11 @@ func ConnectToSMTPServerAdvanced(connectionInfo *SmtpConnectionInfo) (net.Conn,
|
||||
var conn net.Conn
|
||||
var err error
|
||||
|
||||
smtpAddress := connectionInfo.SmtpServer + ":" + connectionInfo.SmtpPort
|
||||
smtpAddress := connectionInfo.SmtpServerHost + ":" + connectionInfo.SmtpPort
|
||||
if connectionInfo.ConnectionSecurity == model.CONN_SECURITY_TLS {
|
||||
tlsconfig := &tls.Config{
|
||||
InsecureSkipVerify: connectionInfo.SkipCertVerification,
|
||||
ServerName: connectionInfo.SmtpServer,
|
||||
ServerName: connectionInfo.SmtpServerName,
|
||||
}
|
||||
|
||||
conn, err = tls.Dial("tcp", smtpAddress, tlsconfig)
|
||||
@@ -117,14 +118,15 @@ func ConnectToSMTPServer(config *model.Config) (net.Conn, *model.AppError) {
|
||||
&SmtpConnectionInfo{
|
||||
ConnectionSecurity: config.EmailSettings.ConnectionSecurity,
|
||||
SkipCertVerification: *config.EmailSettings.SkipServerCertificateVerification,
|
||||
SmtpServer: config.EmailSettings.SMTPServer,
|
||||
SmtpServerName: config.EmailSettings.SMTPServer,
|
||||
SmtpServerHost: config.EmailSettings.SMTPServer,
|
||||
SmtpPort: config.EmailSettings.SMTPPort,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func NewSMTPClientAdvanced(conn net.Conn, hostname string, connectionInfo *SmtpConnectionInfo) (*smtp.Client, *model.AppError) {
|
||||
c, err := smtp.NewClient(conn, connectionInfo.SmtpServer+":"+connectionInfo.SmtpPort)
|
||||
c, err := smtp.NewClient(conn, connectionInfo.SmtpServerName+":"+connectionInfo.SmtpPort)
|
||||
if err != nil {
|
||||
l4g.Error(T("utils.mail.new_client.open.error"), err)
|
||||
return nil, model.NewAppError("SendMail", "utils.mail.connect_smtp.open_tls.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -141,7 +143,7 @@ func NewSMTPClientAdvanced(conn net.Conn, hostname string, connectionInfo *SmtpC
|
||||
if connectionInfo.ConnectionSecurity == model.CONN_SECURITY_STARTTLS {
|
||||
tlsconfig := &tls.Config{
|
||||
InsecureSkipVerify: connectionInfo.SkipCertVerification,
|
||||
ServerName: connectionInfo.SmtpServer,
|
||||
ServerName: connectionInfo.SmtpServerName,
|
||||
}
|
||||
c.StartTLS(tlsconfig)
|
||||
}
|
||||
@@ -161,7 +163,8 @@ func NewSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
|
||||
&SmtpConnectionInfo{
|
||||
ConnectionSecurity: config.EmailSettings.ConnectionSecurity,
|
||||
SkipCertVerification: *config.EmailSettings.SkipServerCertificateVerification,
|
||||
SmtpServer: config.EmailSettings.SMTPServer,
|
||||
SmtpServerName: config.EmailSettings.SMTPServer,
|
||||
SmtpServerHost: config.EmailSettings.SMTPServer,
|
||||
SmtpPort: config.EmailSettings.SMTPPort,
|
||||
Auth: *config.EmailSettings.EnableSMTPAuth,
|
||||
SmtpUsername: config.EmailSettings.SMTPUsername,
|
||||
|
||||
@@ -47,7 +47,8 @@ func TestMailConnectionAdvanced(t *testing.T) {
|
||||
&SmtpConnectionInfo{
|
||||
ConnectionSecurity: cfg.EmailSettings.ConnectionSecurity,
|
||||
SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification,
|
||||
SmtpServer: cfg.EmailSettings.SMTPServer,
|
||||
SmtpServerName: cfg.EmailSettings.SMTPServer,
|
||||
SmtpServerHost: cfg.EmailSettings.SMTPServer,
|
||||
SmtpPort: cfg.EmailSettings.SMTPPort,
|
||||
},
|
||||
); err != nil {
|
||||
@@ -60,7 +61,8 @@ func TestMailConnectionAdvanced(t *testing.T) {
|
||||
&SmtpConnectionInfo{
|
||||
ConnectionSecurity: cfg.EmailSettings.ConnectionSecurity,
|
||||
SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification,
|
||||
SmtpServer: cfg.EmailSettings.SMTPServer,
|
||||
SmtpServerName: cfg.EmailSettings.SMTPServer,
|
||||
SmtpServerHost: cfg.EmailSettings.SMTPServer,
|
||||
SmtpPort: cfg.EmailSettings.SMTPPort,
|
||||
Auth: *cfg.EmailSettings.EnableSMTPAuth,
|
||||
SmtpUsername: cfg.EmailSettings.SMTPUsername,
|
||||
@@ -76,7 +78,8 @@ func TestMailConnectionAdvanced(t *testing.T) {
|
||||
&SmtpConnectionInfo{
|
||||
ConnectionSecurity: cfg.EmailSettings.ConnectionSecurity,
|
||||
SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification,
|
||||
SmtpServer: "wrongServer",
|
||||
SmtpServerName: "wrongServer",
|
||||
SmtpServerHost: "wrongServer",
|
||||
SmtpPort: "553",
|
||||
},
|
||||
); err == nil {
|
||||
@@ -225,10 +228,11 @@ func TestSendMailUsingConfigAdvanced(t *testing.T) {
|
||||
func TestAuthMethods(t *testing.T) {
|
||||
auth := &authChooser{
|
||||
connectionInfo: &SmtpConnectionInfo{
|
||||
SmtpUsername: "test",
|
||||
SmtpPassword: "fakepass",
|
||||
SmtpServer: "fakeserver",
|
||||
SmtpPort: "25",
|
||||
SmtpUsername: "test",
|
||||
SmtpPassword: "fakepass",
|
||||
SmtpServerName: "fakeserver",
|
||||
SmtpServerHost: "fakeserver",
|
||||
SmtpPort: "25",
|
||||
},
|
||||
}
|
||||
tests := []struct {
|
||||
|
||||
24
vendor/github.com/hako/durafmt/.gitignore
generated
vendored
Normal file
24
vendor/github.com/hako/durafmt/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
21
vendor/github.com/hako/durafmt/.travis.yml
generated
vendored
Normal file
21
vendor/github.com/hako/durafmt/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.5
|
||||
- 1.6
|
||||
- 1.7
|
||||
- 1.8
|
||||
- 1.9
|
||||
- tip
|
||||
|
||||
before_install:
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
|
||||
script:
|
||||
- GOARCH=386 go test # test 32bit architectures.
|
||||
- go test -coverprofile=coverage.txt -covermode=atomic
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
sudo: false
|
||||
46
vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md
generated
vendored
Normal file
46
vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at wesley@hakobaito.co.uk. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
9
vendor/github.com/hako/durafmt/CONTRIBUTING.md
generated
vendored
Normal file
9
vendor/github.com/hako/durafmt/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Contributing
|
||||
|
||||
Contributions are welcome! Fork this repo and add your changes and submit a PR.
|
||||
|
||||
If you would like to fix a bug, add a feature or provide feedback you can do so in the issues section.
|
||||
|
||||
You can run tests by runnning `go test`. Running `go test; go vet; golint` is recommended.
|
||||
|
||||
durafmt is also tested against `gometalinter`.
|
||||
21
vendor/github.com/hako/durafmt/LICENSE
generated
vendored
Normal file
21
vendor/github.com/hako/durafmt/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Wesley Hill
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
80
vendor/github.com/hako/durafmt/README.md
generated
vendored
Normal file
80
vendor/github.com/hako/durafmt/README.md
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
# durafmt
|
||||
|
||||
[](https://travis-ci.org/hako/durafmt) [](https://goreportcard.com/report/github.com/hako/durafmt) [](https://codecov.io/gh/hako/durafmt) [](https://godoc.org/github.com/hako/durafmt)
|
||||
[](https://www.codetriage.com/hako/durafmt)
|
||||
|
||||
|
||||
|
||||
durafmt is a tiny Go library that formats `time.Duration` strings into a human readable format.
|
||||
|
||||
```
|
||||
go get github.com/hako/durafmt
|
||||
```
|
||||
|
||||
# Why
|
||||
|
||||
If you've worked with `time.Duration` in Go, you most likely have come across this:
|
||||
|
||||
```
|
||||
53m28.587093086s // :)
|
||||
```
|
||||
|
||||
The above seems very easy to read, unless your duration looks like this:
|
||||
|
||||
```
|
||||
354h22m3.24s // :S
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
### durafmt.ParseString()
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
duration, err := durafmt.ParseString("354h22m3.24s")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds
|
||||
// duration.String() // String representation. "2 weeks 18 hours 22 minutes 3 seconds"
|
||||
}
|
||||
```
|
||||
|
||||
### durafmt.Parse()
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
timeduration := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second)
|
||||
duration := durafmt.Parse(timeduration).String()
|
||||
fmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds
|
||||
}
|
||||
```
|
||||
|
||||
# Contributing
|
||||
|
||||
Contributions are welcome! Fork this repo and add your changes and submit a PR.
|
||||
|
||||
If you would like to fix a bug, add a feature or provide feedback you can do so in the issues section.
|
||||
|
||||
You can run tests by runnning `go test`. Running `go test; go vet; golint` is recommended.
|
||||
|
||||
durafmt is also tested against `gometalinter`.
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
120
vendor/github.com/hako/durafmt/durafmt.go
generated
vendored
Normal file
120
vendor/github.com/hako/durafmt/durafmt.go
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// Package durafmt formats time.Duration into a human readable format.
|
||||
package durafmt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
units = []string{"years", "weeks", "days", "hours", "minutes", "seconds", "milliseconds"}
|
||||
)
|
||||
|
||||
// Durafmt holds the parsed duration and the original input duration.
|
||||
type Durafmt struct {
|
||||
duration time.Duration
|
||||
input string // Used as reference.
|
||||
}
|
||||
|
||||
// Parse creates a new *Durafmt struct, returns error if input is invalid.
|
||||
func Parse(dinput time.Duration) *Durafmt {
|
||||
input := dinput.String()
|
||||
return &Durafmt{dinput, input}
|
||||
}
|
||||
|
||||
// ParseString creates a new *Durafmt struct from a string.
|
||||
// returns an error if input is invalid.
|
||||
func ParseString(input string) (*Durafmt, error) {
|
||||
if input == "0" || input == "-0" {
|
||||
return nil, errors.New("durafmt: missing unit in duration " + input)
|
||||
}
|
||||
duration, err := time.ParseDuration(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Durafmt{duration, input}, nil
|
||||
}
|
||||
|
||||
// String parses d *Durafmt into a human readable duration.
|
||||
func (d *Durafmt) String() string {
|
||||
var duration string
|
||||
|
||||
// Check for minus durations.
|
||||
if string(d.input[0]) == "-" {
|
||||
duration += "-"
|
||||
d.duration = -d.duration
|
||||
}
|
||||
|
||||
// Convert duration.
|
||||
seconds := int64(d.duration.Seconds()) % 60
|
||||
minutes := int64(d.duration.Minutes()) % 60
|
||||
hours := int64(d.duration.Hours()) % 24
|
||||
days := int64(d.duration/(24*time.Hour)) % 365 % 7
|
||||
|
||||
// Edge case between 364 and 365 days.
|
||||
// We need to calculate weeks from what is left from years
|
||||
leftYearDays := int64(d.duration/(24*time.Hour)) % 365
|
||||
weeks := leftYearDays / 7
|
||||
if leftYearDays >= 364 && leftYearDays < 365 {
|
||||
weeks = 52
|
||||
}
|
||||
|
||||
years := int64(d.duration/(24*time.Hour)) / 365
|
||||
milliseconds := int64(d.duration/time.Millisecond) -
|
||||
(seconds * 1000) - (minutes * 60000) - (hours * 3600000) -
|
||||
(days * 86400000) - (weeks * 604800000) - (years * 31536000000)
|
||||
|
||||
// Create a map of the converted duration time.
|
||||
durationMap := map[string]int64{
|
||||
"milliseconds": milliseconds,
|
||||
"seconds": seconds,
|
||||
"minutes": minutes,
|
||||
"hours": hours,
|
||||
"days": days,
|
||||
"weeks": weeks,
|
||||
"years": years,
|
||||
}
|
||||
|
||||
// Construct duration string.
|
||||
for _, u := range units {
|
||||
v := durationMap[u]
|
||||
strval := strconv.FormatInt(v, 10)
|
||||
switch {
|
||||
// add to the duration string if v > 1.
|
||||
case v > 1:
|
||||
duration += strval + " " + u + " "
|
||||
// remove the plural 's', if v is 1.
|
||||
case v == 1:
|
||||
duration += strval + " " + strings.TrimRight(u, "s") + " "
|
||||
// omit any value with 0s or 0.
|
||||
case d.duration.String() == "0" || d.duration.String() == "0s":
|
||||
// note: milliseconds and minutes have the same suffix (m)
|
||||
// so we have to check if the units match with the suffix.
|
||||
|
||||
// check for a suffix that is NOT the milliseconds suffix.
|
||||
if strings.HasSuffix(d.input, string(u[0])) && !strings.Contains(d.input, "ms") {
|
||||
// if it happens that the units are milliseconds, skip.
|
||||
if u == "milliseconds" {
|
||||
continue
|
||||
}
|
||||
duration += strval + " " + u
|
||||
}
|
||||
// process milliseconds here.
|
||||
if u == "milliseconds" {
|
||||
if strings.Contains(d.input, "ms") {
|
||||
duration += strval + " " + u
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
// omit any value with 0.
|
||||
case v == 0:
|
||||
continue
|
||||
}
|
||||
}
|
||||
// trim any remaining spaces.
|
||||
duration = strings.TrimSpace(duration)
|
||||
return duration
|
||||
}
|
||||
174
vendor/github.com/hako/durafmt/durafmt_test.go
generated
vendored
Normal file
174
vendor/github.com/hako/durafmt/durafmt_test.go
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
package durafmt
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
testStrings []struct {
|
||||
test string
|
||||
expected string
|
||||
}
|
||||
testTimes []struct {
|
||||
test time.Duration
|
||||
expected string
|
||||
}
|
||||
)
|
||||
|
||||
// TestParse for durafmt time.Duration conversion.
|
||||
func TestParse(t *testing.T) {
|
||||
testTimes = []struct {
|
||||
test time.Duration
|
||||
expected string
|
||||
}{
|
||||
{1 * time.Millisecond, "1 millisecond"},
|
||||
{1 * time.Second, "1 second"},
|
||||
{1 * time.Hour, "1 hour"},
|
||||
{1 * time.Minute, "1 minute"},
|
||||
{2 * time.Millisecond, "2 milliseconds"},
|
||||
{2 * time.Second, "2 seconds"},
|
||||
{2 * time.Minute, "2 minutes"},
|
||||
{1 * time.Hour, "1 hour"},
|
||||
{2 * time.Hour, "2 hours"},
|
||||
{10 * time.Hour, "10 hours"},
|
||||
{24 * time.Hour, "1 day"},
|
||||
{48 * time.Hour, "2 days"},
|
||||
{120 * time.Hour, "5 days"},
|
||||
{168 * time.Hour, "1 week"},
|
||||
{672 * time.Hour, "4 weeks"},
|
||||
{8759 * time.Hour, "52 weeks 23 hours"},
|
||||
{8760 * time.Hour, "1 year"},
|
||||
{17519 * time.Hour, "1 year 52 weeks 23 hours"},
|
||||
{17520 * time.Hour, "2 years"},
|
||||
{26279 * time.Hour, "2 years 52 weeks 23 hours"},
|
||||
{26280 * time.Hour, "3 years"},
|
||||
{201479 * time.Hour, "22 years 52 weeks 23 hours"},
|
||||
{201480 * time.Hour, "23 years"},
|
||||
{-1 * time.Second, "-1 second"},
|
||||
{-10 * time.Second, "-10 seconds"},
|
||||
{-100 * time.Second, "-1 minute 40 seconds"},
|
||||
{-1 * time.Millisecond, "-1 millisecond"},
|
||||
{-10 * time.Millisecond, "-10 milliseconds"},
|
||||
{-100 * time.Millisecond, "-100 milliseconds"},
|
||||
}
|
||||
|
||||
for _, table := range testTimes {
|
||||
result := Parse(table.test).String()
|
||||
if result != table.expected {
|
||||
t.Errorf("Parse(%q).String() = %q. got %q, expected %q",
|
||||
table.test, result, result, table.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseString for durafmt duration string conversion.
|
||||
func TestParseString(t *testing.T) {
|
||||
testStrings = []struct {
|
||||
test string
|
||||
expected string
|
||||
}{
|
||||
{"1ms", "1 millisecond"},
|
||||
{"2ms", "2 milliseconds"},
|
||||
{"1s", "1 second"},
|
||||
{"2s", "2 seconds"},
|
||||
{"1m", "1 minute"},
|
||||
{"2m", "2 minutes"},
|
||||
{"1h", "1 hour"},
|
||||
{"2h", "2 hours"},
|
||||
{"10h", "10 hours"},
|
||||
{"24h", "1 day"},
|
||||
{"48h", "2 days"},
|
||||
{"120h", "5 days"},
|
||||
{"168h", "1 week"},
|
||||
{"672h", "4 weeks"},
|
||||
{"8759h", "52 weeks 23 hours"},
|
||||
{"8760h", "1 year"},
|
||||
{"17519h", "1 year 52 weeks 23 hours"},
|
||||
{"17520h", "2 years"},
|
||||
{"26279h", "2 years 52 weeks 23 hours"},
|
||||
{"26280h", "3 years"},
|
||||
{"201479h", "22 years 52 weeks 23 hours"},
|
||||
{"201480h", "23 years"},
|
||||
{"1m0s", "1 minute"},
|
||||
{"1m2s", "1 minute 2 seconds"},
|
||||
{"3h4m5s", "3 hours 4 minutes 5 seconds"},
|
||||
{"6h7m8s9ms", "6 hours 7 minutes 8 seconds 9 milliseconds"},
|
||||
{"0ms", "0 milliseconds"},
|
||||
{"0s", "0 seconds"},
|
||||
{"0m", "0 minutes"},
|
||||
{"0h", "0 hours"},
|
||||
{"0m1ms", "1 millisecond"},
|
||||
{"0m1s", "1 second"},
|
||||
{"0m1m", "1 minute"},
|
||||
{"0m2ms", "2 milliseconds"},
|
||||
{"0m2s", "2 seconds"},
|
||||
{"0m2m", "2 minutes"},
|
||||
{"0m2m3h", "3 hours 2 minutes"},
|
||||
{"0m2m34h", "1 day 10 hours 2 minutes"},
|
||||
{"0m56h7m8ms", "2 days 8 hours 7 minutes 8 milliseconds"},
|
||||
{"-1ms", "-1 millisecond"},
|
||||
{"-1s", "-1 second"},
|
||||
{"-1m", "-1 minute"},
|
||||
{"-1h", "-1 hour"},
|
||||
{"-2ms", "-2 milliseconds"},
|
||||
{"-2s", "-2 seconds"},
|
||||
{"-2m", "-2 minutes"},
|
||||
{"-2h", "-2 hours"},
|
||||
{"-10h", "-10 hours"},
|
||||
{"-24h", "-1 day"},
|
||||
{"-48h", "-2 days"},
|
||||
{"-120h", "-5 days"},
|
||||
{"-168h", "-1 week"},
|
||||
{"-672h", "-4 weeks"},
|
||||
{"-8760h", "-1 year"},
|
||||
{"-1m0s", "-1 minute"},
|
||||
{"-0m2s", "-2 seconds"},
|
||||
{"-0m2m", "-2 minutes"},
|
||||
{"-0m2m3h", "-3 hours 2 minutes"},
|
||||
{"-0m2m34h", "-1 day 10 hours 2 minutes"},
|
||||
{"-0ms", "-0 milliseconds"},
|
||||
{"-0s", "-0 seconds"},
|
||||
{"-0m", "-0 minutes"},
|
||||
{"-0h", "-0 hours"},
|
||||
}
|
||||
|
||||
for _, table := range testStrings {
|
||||
d, err := ParseString(table.test)
|
||||
if err != nil {
|
||||
t.Errorf("%q", err)
|
||||
}
|
||||
result := d.String()
|
||||
if result != table.expected {
|
||||
t.Errorf("d.String() = %q. got %q, expected %q",
|
||||
table.test, result, table.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestInvalidDuration for invalid inputs.
|
||||
func TestInvalidDuration(t *testing.T) {
|
||||
testStrings = []struct {
|
||||
test string
|
||||
expected string
|
||||
}{
|
||||
{"1", ""},
|
||||
{"1d", ""},
|
||||
{"1w", ""},
|
||||
{"1wk", ""},
|
||||
{"1y", ""},
|
||||
{"", ""},
|
||||
{"m1", ""},
|
||||
{"1nmd", ""},
|
||||
{"0", ""},
|
||||
{"-0", ""},
|
||||
}
|
||||
|
||||
for _, table := range testStrings {
|
||||
_, err := ParseString(table.test)
|
||||
if err == nil {
|
||||
t.Errorf("ParseString(%q). got %q, expected %q",
|
||||
table.test, err, table.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user