Merge branch 'master' into mark-as-unread
Этот коммит содержится в:
@@ -45,6 +45,20 @@ func TestCreateBot(t *testing.T) {
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "model.bot.is_valid.description.app_error", err.Id)
|
||||
})
|
||||
|
||||
t.Run("username contains . character", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
bot, err := th.App.CreateBot(&model.Bot{
|
||||
Username: "username.",
|
||||
Description: "a bot",
|
||||
OwnerId: th.BasicUser.Id,
|
||||
})
|
||||
require.NotNil(t, err)
|
||||
require.Nil(t, bot)
|
||||
require.Equal(t, "model.user.is_valid.email.app_error", err.Id)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("create bot", func(t *testing.T) {
|
||||
|
||||
@@ -143,6 +143,10 @@ func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message str
|
||||
var text string
|
||||
if err.Id == "api.channel.add_members.user_denied" {
|
||||
text = args.T("api.command_invite.group_constrained_user_denied")
|
||||
} else if err.Id == "store.sql_team.get_member.missing.app_error" {
|
||||
text = args.T("api.command_invite.user_not_in_team.app_error", map[string]interface{}{
|
||||
"Username": userProfile.Username,
|
||||
})
|
||||
} else {
|
||||
text = args.T("api.command_invite.fail.app_error")
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestInviteProvider(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "try to add a user which is not part of the team",
|
||||
expected: "api.command_invite.fail.app_error",
|
||||
expected: "api.command_invite.user_not_in_team.app_error",
|
||||
msg: basicUser4.Username,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -186,6 +186,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
|
||||
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "@channel", post.Message)
|
||||
assert.Equal(t, "true", post.Props["from_webhook"])
|
||||
|
||||
// Test Slack attachments text conversion.
|
||||
resp.Attachments = []*model.SlackAttachment{
|
||||
@@ -196,7 +197,11 @@ func TestHandleCommandResponsePost(t *testing.T) {
|
||||
|
||||
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "@here", resp.Attachments[0].Text)
|
||||
assert.Equal(t, "@channel", post.Message)
|
||||
if assert.Len(t, post.Attachments(), 1) {
|
||||
assert.Equal(t, "@here", post.Attachments()[0].Text)
|
||||
}
|
||||
assert.Equal(t, "true", post.Props["from_webhook"])
|
||||
|
||||
channel = th.CreatePrivateChannel(th.BasicTeam)
|
||||
resp.ChannelId = channel.Id
|
||||
|
||||
@@ -334,7 +334,7 @@ func (a *App) ImportUser(data *UserImportData, dryRun bool) *model.AppError {
|
||||
authData = nil
|
||||
} else {
|
||||
// If no AuthData or Password is specified, we must generate a password.
|
||||
password = model.NewId()
|
||||
password = model.GeneratePassword(*a.Config().PasswordSettings.MinimumLength)
|
||||
authData = nil
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,13 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
close(cchan)
|
||||
}()
|
||||
|
||||
userChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(upstreamRequest.UserId)
|
||||
userChan <- store.StoreResult{Data: user, Err: err}
|
||||
close(userChan)
|
||||
}()
|
||||
|
||||
result := <-pchan
|
||||
if result.Err != nil {
|
||||
if cookie == nil {
|
||||
@@ -89,7 +96,14 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
return "", model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "postId doesn't match", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channel, err := a.Srv.Store.Channel().Get(cookie.ChannelId, true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
upstreamRequest.ChannelId = cookie.ChannelId
|
||||
upstreamRequest.ChannelName = channel.Name
|
||||
upstreamRequest.TeamId = channel.TeamId
|
||||
upstreamRequest.Type = cookie.Type
|
||||
upstreamRequest.Context = cookie.Integration.Context
|
||||
datasource = cookie.DataSource
|
||||
@@ -112,6 +126,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
}
|
||||
|
||||
upstreamRequest.ChannelId = post.ChannelId
|
||||
upstreamRequest.ChannelName = channel.Name
|
||||
upstreamRequest.TeamId = channel.TeamId
|
||||
upstreamRequest.Type = action.Type
|
||||
upstreamRequest.Context = action.Integration.Context
|
||||
@@ -140,6 +155,27 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
upstreamURL = action.Integration.URL
|
||||
}
|
||||
|
||||
teamChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
team, err := a.Srv.Store.Team().Get(upstreamRequest.TeamId)
|
||||
teamChan <- store.StoreResult{Data: team, Err: err}
|
||||
close(teamChan)
|
||||
}()
|
||||
|
||||
ur := <-userChan
|
||||
if ur.Err != nil {
|
||||
return "", ur.Err
|
||||
}
|
||||
user := ur.Data.(*model.User)
|
||||
upstreamRequest.UserName = user.Username
|
||||
|
||||
tr := <-teamChan
|
||||
if tr.Err != nil {
|
||||
return "", tr.Err
|
||||
}
|
||||
team := tr.Data.(*model.Team)
|
||||
upstreamRequest.TeamName = team.Name
|
||||
|
||||
if upstreamRequest.Type == model.POST_ACTION_TYPE_SELECT {
|
||||
if selectedOption != "" {
|
||||
if upstreamRequest.Context == nil {
|
||||
|
||||
@@ -80,8 +80,11 @@ func TestPostAction(t *testing.T) {
|
||||
assert.NotNil(t, request)
|
||||
|
||||
assert.Equal(t, request.UserId, th.BasicUser.Id)
|
||||
assert.Equal(t, request.UserName, th.BasicUser.Username)
|
||||
assert.Equal(t, request.ChannelId, th.BasicChannel.Id)
|
||||
assert.Equal(t, request.ChannelName, th.BasicChannel.Name)
|
||||
assert.Equal(t, request.TeamId, th.BasicTeam.Id)
|
||||
assert.Equal(t, request.TeamName, th.BasicTeam.Name)
|
||||
assert.True(t, len(request.TriggerId) > 0)
|
||||
if request.Type == model.POST_ACTION_TYPE_SELECT {
|
||||
assert.Equal(t, request.DataSource, "some_source")
|
||||
|
||||
19
app/login.go
19
app/login.go
@@ -110,7 +110,7 @@ func (a *App) GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
||||
return nil, model.NewAppError("GetUserForLogin", "store.sql_user.get_for_login.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string) (*model.Session, *model.AppError) {
|
||||
func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string) *model.AppError {
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
var rejectionReason string
|
||||
pluginContext := a.PluginContext()
|
||||
@@ -120,7 +120,7 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
}, plugin.UserWillLogInId)
|
||||
|
||||
if rejectionReason != "" {
|
||||
return nil, model.NewAppError("DoLogin", "Login rejected by plugin: "+rejectionReason, nil, "", http.StatusBadRequest)
|
||||
return model.NewAppError("DoLogin", "Login rejected by plugin: "+rejectionReason, nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
// A special case where we logout of all other sessions with the same Id
|
||||
if err := a.RevokeSessionsForDeviceId(user.Id, deviceId, ""); err != nil {
|
||||
err.StatusCode = http.StatusInternalServerError
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
session.SetExpireInDays(*a.Config().ServiceSettings.SessionLengthWebInDays)
|
||||
@@ -158,10 +158,11 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
var err *model.AppError
|
||||
if session, err = a.CreateSession(session); err != nil {
|
||||
err.StatusCode = http.StatusInternalServerError
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
w.Header().Set(model.HEADER_TOKEN, session.Token)
|
||||
|
||||
a.Session = *session
|
||||
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
@@ -174,10 +175,10 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
})
|
||||
}
|
||||
|
||||
return session, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) AttachSessionCookies(w http.ResponseWriter, r *http.Request, session *model.Session) {
|
||||
func (a *App) AttachSessionCookies(w http.ResponseWriter, r *http.Request) {
|
||||
secure := false
|
||||
if GetProtocol(r) == "https" {
|
||||
secure = true
|
||||
@@ -190,7 +191,7 @@ func (a *App) AttachSessionCookies(w http.ResponseWriter, r *http.Request, sessi
|
||||
expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0)
|
||||
sessionCookie := &http.Cookie{
|
||||
Name: model.SESSION_COOKIE_TOKEN,
|
||||
Value: session.Token,
|
||||
Value: a.Session.Token,
|
||||
Path: subpath,
|
||||
MaxAge: maxAge,
|
||||
Expires: expiresAt,
|
||||
@@ -201,7 +202,7 @@ func (a *App) AttachSessionCookies(w http.ResponseWriter, r *http.Request, sessi
|
||||
|
||||
userCookie := &http.Cookie{
|
||||
Name: model.SESSION_COOKIE_USER,
|
||||
Value: session.UserId,
|
||||
Value: a.Session.UserId,
|
||||
Path: subpath,
|
||||
MaxAge: maxAge,
|
||||
Expires: expiresAt,
|
||||
@@ -211,7 +212,7 @@ func (a *App) AttachSessionCookies(w http.ResponseWriter, r *http.Request, sessi
|
||||
|
||||
csrfCookie := &http.Cookie{
|
||||
Name: model.SESSION_COOKIE_CSRF,
|
||||
Value: session.GetCSRF(),
|
||||
Value: a.Session.GetCSRF(),
|
||||
Path: subpath,
|
||||
MaxAge: maxAge,
|
||||
Expires: expiresAt,
|
||||
|
||||
@@ -1440,6 +1440,17 @@ func TestPluginAPIGetUnsanitizedConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginCallLogAPI(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
pluginID := "com.mattermost.sample"
|
||||
path, _ := fileutils.FindDir("mattermost-server/app/plugin_api_test")
|
||||
pluginCode, err := ioutil.ReadFile(filepath.Join(path, "plugin_using_log_api.go"))
|
||||
assert.NoError(t, err)
|
||||
setupPluginApiTest(t, string(pluginCode),
|
||||
`{"id": "com.mattermost.sample", "server": {"executable": "backend.exe"}, "settings_schema": {"settings": []}}`, pluginID, th.App)
|
||||
}
|
||||
|
||||
func TestPluginAddUserToChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
29
app/plugin_api_test/plugin_using_log_api.go
Обычный файл
29
app/plugin_api_test/plugin_using_log_api.go
Обычный файл
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/plugin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type PluginUsingLogAPI struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
type Foo struct {
|
||||
bar float64
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&PluginUsingLogAPI{})
|
||||
}
|
||||
|
||||
func (p *PluginUsingLogAPI) OnActivate() error {
|
||||
p.API.LogDebug("LogDebug", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogInfo("LogInfo", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogWarn("LogWarn", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogError("LogError", "error", errors.WithStack(errors.New("boom!")))
|
||||
return nil
|
||||
}
|
||||
@@ -694,7 +694,7 @@ func TestUserWillLogIn_Blocked(t *testing.T) {
|
||||
|
||||
r := &http.Request{}
|
||||
w := httptest.NewRecorder()
|
||||
_, err = th.App.DoLogin(w, r, th.BasicUser, "")
|
||||
err = th.App.DoLogin(w, r, th.BasicUser, "")
|
||||
|
||||
assert.Contains(t, err.Id, "Login rejected by plugin", "Expected Login rejected by plugin, got %s", err.Id)
|
||||
}
|
||||
@@ -733,10 +733,10 @@ func TestUserWillLogInIn_Passed(t *testing.T) {
|
||||
|
||||
r := &http.Request{}
|
||||
w := httptest.NewRecorder()
|
||||
session, err := th.App.DoLogin(w, r, th.BasicUser, "")
|
||||
err = th.App.DoLogin(w, r, th.BasicUser, "")
|
||||
|
||||
assert.Nil(t, err, "Expected nil, got %s", err)
|
||||
assert.Equal(t, session.UserId, th.BasicUser.Id)
|
||||
assert.Equal(t, th.App.Session.UserId, th.BasicUser.Id)
|
||||
}
|
||||
|
||||
func TestUserHasLoggedIn(t *testing.T) {
|
||||
@@ -774,7 +774,7 @@ func TestUserHasLoggedIn(t *testing.T) {
|
||||
|
||||
r := &http.Request{}
|
||||
w := httptest.NewRecorder()
|
||||
_, err = th.App.DoLogin(w, r, th.BasicUser, "")
|
||||
err = th.App.DoLogin(w, r, th.BasicUser, "")
|
||||
|
||||
assert.Nil(t, err, "Expected nil, got %s", err)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user