summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2018-05-16 13:43:22 -0400
committerGitHub <noreply@github.com>2018-05-16 13:43:22 -0400
commit1f6c271b3bedd6656ae7155714423b1b39a669c1 (patch)
tree9ce6390c237cc5f7c16d63addb4372033807cff8 /app
parent02f8c18f40cd0e973e4c75b751e8fcbbbd019728 (diff)
downloadchat-1f6c271b3bedd6656ae7155714423b1b39a669c1.tar.gz
chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.tar.bz2
chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.zip
MM-8708 Remove api package (#8784)
* Remove api package * Remove api dependency from cmd package * Remove EnableAPIv3 setting * Update web tests * Add more websocket tests * Move some ws and oauth tests to api4 package * Move command tests into api4 package * Test fixes * Fix msg command test * Add some app file tests
Diffstat (limited to 'app')
-rw-r--r--app/auto_channels.go16
-rw-r--r--app/auto_environment.go7
-rw-r--r--app/auto_posts.go10
-rw-r--r--app/auto_teams.go7
-rw-r--r--app/auto_users.go34
-rw-r--r--app/command_loadtest.go12
-rw-r--r--app/diagnostics.go5
-rw-r--r--app/file.go5
-rw-r--r--app/file_test.go61
9 files changed, 99 insertions, 58 deletions
diff --git a/app/auto_channels.go b/app/auto_channels.go
index 78b500961..72561d2b9 100644
--- a/app/auto_channels.go
+++ b/app/auto_channels.go
@@ -9,7 +9,7 @@ import (
)
type AutoChannelCreator struct {
- client *model.Client
+ client *model.Client4
team *model.Team
Fuzzy bool
DisplayNameLen utils.Range
@@ -19,7 +19,7 @@ type AutoChannelCreator struct {
ChannelType string
}
-func NewAutoChannelCreator(client *model.Client, team *model.Team) *AutoChannelCreator {
+func NewAutoChannelCreator(client *model.Client4, team *model.Team) *AutoChannelCreator {
return &AutoChannelCreator{
client: client,
team: team,
@@ -47,14 +47,14 @@ func (cfg *AutoChannelCreator) createRandomChannel() (*model.Channel, bool) {
Name: name,
Type: cfg.ChannelType}
- println(cfg.client.GetTeamRoute())
- result, err := cfg.client.CreateChannel(channel)
- if err != nil {
- println(err.Error())
- println(err.DetailedError)
+ println(cfg.client.GetTeamRoute(cfg.team.Id))
+ channel, resp := cfg.client.CreateChannel(channel)
+ if resp.Error != nil {
+ println(resp.Error.Error())
+ println(resp.Error.DetailedError)
return nil, false
}
- return result.Data.(*model.Channel), true
+ return channel, true
}
func (cfg *AutoChannelCreator) CreateTestChannels(num utils.Range) ([]*model.Channel, bool) {
diff --git a/app/auto_environment.go b/app/auto_environment.go
index 476a1c211..688940337 100644
--- a/app/auto_environment.go
+++ b/app/auto_environment.go
@@ -16,7 +16,7 @@ type TestEnvironment struct {
Environments []TeamEnvironment
}
-func CreateTestEnvironmentWithTeams(a *App, client *model.Client, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnvironment, bool) {
+func CreateTestEnvironmentWithTeams(a *App, client *model.Client4, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnvironment, bool) {
rand.Seed(time.Now().UTC().UnixNano())
teamCreator := NewAutoTeamCreator(client)
@@ -36,7 +36,6 @@ func CreateTestEnvironmentWithTeams(a *App, client *model.Client, rangeTeams uti
return TestEnvironment{}, false
}
client.LoginById(randomUser.Id, USER_PASSWORD)
- client.SetTeamId(team.Id)
teamEnvironment, err := CreateTestEnvironmentInTeam(a, client, team, rangeChannels, rangeUsers, rangePosts, fuzzy)
if !err {
return TestEnvironment{}, false
@@ -47,7 +46,7 @@ func CreateTestEnvironmentWithTeams(a *App, client *model.Client, rangeTeams uti
return environment, true
}
-func CreateTestEnvironmentInTeam(a *App, client *model.Client, team *model.Team, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnvironment, bool) {
+func CreateTestEnvironmentInTeam(a *App, client *model.Client4, team *model.Team, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnvironment, bool) {
rand.Seed(time.Now().UTC().UnixNano())
// We need to create at least one user
@@ -74,7 +73,7 @@ func CreateTestEnvironmentInTeam(a *App, client *model.Client, team *model.Team,
for _, user := range users {
for _, channel := range channels {
client.LoginById(user.Id, USER_PASSWORD)
- client.JoinChannel(channel.Id)
+ client.AddChannelMember(channel.Id, user.Id)
}
}
diff --git a/app/auto_posts.go b/app/auto_posts.go
index a2adb9d6c..23746a9ba 100644
--- a/app/auto_posts.go
+++ b/app/auto_posts.go
@@ -14,7 +14,7 @@ import (
)
type AutoPostCreator struct {
- client *model.Client
+ client *model.Client4
channelid string
Fuzzy bool
TextLength utils.Range
@@ -26,7 +26,7 @@ type AutoPostCreator struct {
}
// Automatic poster used for testing
-func NewAutoPostCreator(client *model.Client, channelid string) *AutoPostCreator {
+func NewAutoPostCreator(client *model.Client4, channelid string) *AutoPostCreator {
return &AutoPostCreator{
client: client,
channelid: channelid,
@@ -56,7 +56,7 @@ func (cfg *AutoPostCreator) UploadTestFile() ([]string, bool) {
return nil, false
}
- resp, appErr := cfg.client.UploadPostAttachment(data.Bytes(), cfg.channelid, filename)
+ resp, appErr := cfg.client.UploadFile(data.Bytes(), cfg.channelid, filename)
if appErr != nil {
return nil, false
}
@@ -85,9 +85,9 @@ func (cfg *AutoPostCreator) CreateRandomPost() (*model.Post, bool) {
ChannelId: cfg.channelid,
Message: postText,
FileIds: fileIds}
- result, err2 := cfg.client.CreatePost(post)
+ rpost, err2 := cfg.client.CreatePost(post)
if err2 != nil {
return nil, false
}
- return result.Data.(*model.Post), true
+ return rpost, true
}
diff --git a/app/auto_teams.go b/app/auto_teams.go
index 9dce5bd15..e322e8c66 100644
--- a/app/auto_teams.go
+++ b/app/auto_teams.go
@@ -14,7 +14,7 @@ type TeamEnvironment struct {
}
type AutoTeamCreator struct {
- client *model.Client
+ client *model.Client4
Fuzzy bool
NameLength utils.Range
NameCharset string
@@ -24,7 +24,7 @@ type AutoTeamCreator struct {
EmailCharset string
}
-func NewAutoTeamCreator(client *model.Client) *AutoTeamCreator {
+func NewAutoTeamCreator(client *model.Client4) *AutoTeamCreator {
return &AutoTeamCreator{
client: client,
Fuzzy: false,
@@ -57,11 +57,10 @@ func (cfg *AutoTeamCreator) createRandomTeam() (*model.Team, bool) {
Type: model.TEAM_OPEN,
}
- result, err := cfg.client.CreateTeam(team)
+ createdTeam, err := cfg.client.CreateTeam(team)
if err != nil {
return nil, false
}
- createdTeam := result.Data.(*model.Team)
return createdTeam, true
}
diff --git a/app/auto_users.go b/app/auto_users.go
index b11f9c572..b61ab053f 100644
--- a/app/auto_users.go
+++ b/app/auto_users.go
@@ -12,7 +12,7 @@ import (
type AutoUserCreator struct {
app *App
- client *model.Client
+ client *model.Client4
team *model.Team
EmailLength utils.Range
EmailCharset string
@@ -21,7 +21,7 @@ type AutoUserCreator struct {
Fuzzy bool
}
-func NewAutoUserCreator(a *App, client *model.Client, team *model.Team) *AutoUserCreator {
+func NewAutoUserCreator(a *App, client *model.Client4, team *model.Team) *AutoUserCreator {
return &AutoUserCreator{
app: a,
client: client,
@@ -35,21 +35,19 @@ func NewAutoUserCreator(a *App, client *model.Client, team *model.Team) *AutoUse
}
// Basic test team and user so you always know one
-func (a *App) CreateBasicUser(client *model.Client) *model.AppError {
- result, _ := client.FindTeamByName(BTEST_TEAM_NAME)
- if !result.Data.(bool) {
+func (a *App) CreateBasicUser(client *model.Client4) *model.AppError {
+ found, _ := client.TeamExists(BTEST_TEAM_NAME, "")
+ if !found {
newteam := &model.Team{DisplayName: BTEST_TEAM_DISPLAY_NAME, Name: BTEST_TEAM_NAME, Email: BTEST_TEAM_EMAIL, Type: BTEST_TEAM_TYPE}
- result, err := client.CreateTeam(newteam)
- if err != nil {
- return err
+ basicteam, resp := client.CreateTeam(newteam)
+ if resp.Error != nil {
+ return resp.Error
}
- basicteam := result.Data.(*model.Team)
newuser := &model.User{Email: BTEST_USER_EMAIL, Nickname: BTEST_USER_NAME, Password: BTEST_USER_PASSWORD}
- result, err = client.CreateUser(newuser, "")
- if err != nil {
- return err
+ ruser, resp := client.CreateUser(newuser)
+ if resp.Error != nil {
+ return resp.Error
}
- ruser := result.Data.(*model.User)
store.Must(a.Srv.Store.User().VerifyEmail(ruser.Id))
store.Must(a.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}, *a.Config().TeamSettings.MaxUsersPerTeam))
}
@@ -72,14 +70,12 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
Nickname: userName,
Password: USER_PASSWORD}
- result, err := cfg.client.CreateUserWithInvite(user, "", "", cfg.team.InviteId)
- if err != nil {
- mlog.Error(err.Error())
+ ruser, resp := cfg.client.CreateUserWithInviteId(user, cfg.team.InviteId)
+ if resp.Error != nil {
+ mlog.Error(resp.Error.Error())
return nil, false
}
- ruser := result.Data.(*model.User)
-
status := &model.Status{UserId: ruser.Id, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
if result := <-cfg.app.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
mlog.Error(result.Err.Error())
@@ -89,7 +85,7 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
// We need to cheat to verify the user's email
store.Must(cfg.app.Srv.Store.User().VerifyEmail(ruser.Id))
- return result.Data.(*model.User), true
+ return ruser, true
}
func (cfg *AutoUserCreator) CreateTestUsers(num utils.Range) ([]*model.User, bool) {
diff --git a/app/command_loadtest.go b/app/command_loadtest.go
index a4a8f003a..8b3cd2e3b 100644
--- a/app/command_loadtest.go
+++ b/app/command_loadtest.go
@@ -159,7 +159,7 @@ func (me *LoadTestProvider) SetupCommand(a *App, args *model.CommandArgs, messag
numPosts, _ = strconv.Atoi(tokens[numArgs+2])
}
}
- client := model.NewClient(args.SiteURL)
+ client := model.NewAPIv4Client(args.SiteURL)
if doTeams {
if err := a.CreateBasicUser(client); err != nil {
@@ -193,7 +193,6 @@ func (me *LoadTestProvider) SetupCommand(a *App, args *model.CommandArgs, messag
}
client.MockSession(args.Session.Token)
- client.SetTeamId(args.TeamId)
CreateTestEnvironmentInTeam(
a,
client,
@@ -228,8 +227,7 @@ func (me *LoadTestProvider) UsersCommand(a *App, args *model.CommandArgs, messag
team = tr.Data.(*model.Team)
}
- client := model.NewClient(args.SiteURL)
- client.SetTeamId(team.Id)
+ client := model.NewAPIv4Client(args.SiteURL)
userCreator := NewAutoUserCreator(a, client, team)
userCreator.Fuzzy = doFuzz
userCreator.CreateTestUsers(usersr)
@@ -258,8 +256,7 @@ func (me *LoadTestProvider) ChannelsCommand(a *App, args *model.CommandArgs, mes
team = tr.Data.(*model.Team)
}
- client := model.NewClient(args.SiteURL)
- client.SetTeamId(team.Id)
+ client := model.NewAPIv4Client(args.SiteURL)
client.MockSession(args.Session.Token)
channelCreator := NewAutoChannelCreator(client, team)
channelCreator.Fuzzy = doFuzz
@@ -301,8 +298,7 @@ func (me *LoadTestProvider) PostsCommand(a *App, args *model.CommandArgs, messag
}
}
- client := model.NewClient(args.SiteURL)
- client.SetTeamId(args.TeamId)
+ client := model.NewAPIv4Client(args.SiteURL)
client.MockSession(args.Session.Token)
testPoster := NewAutoPostCreator(client, args.ChannelId)
testPoster.Fuzzy = doFuzz
diff --git a/app/diagnostics.go b/app/diagnostics.go
index 7dcea839e..fc8a2e886 100644
--- a/app/diagnostics.go
+++ b/app/diagnostics.go
@@ -6,7 +6,6 @@ package app
import (
"encoding/json"
"runtime"
- "sync/atomic"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
@@ -181,10 +180,7 @@ func (a *App) trackActivity() {
"public_channels_deleted": deletedPublicChannelCount,
"private_channels_deleted": deletedPrivateChannelCount,
"posts": postsCount,
- "used_apiv3": atomic.LoadInt32(model.UsedApiV3) == 1,
})
-
- atomic.StoreInt32(model.UsedApiV3, 0)
}
func (a *App) trackConfig() {
@@ -199,7 +195,6 @@ func (a *App) trackConfig() {
"enable_only_admin_integrations": *cfg.ServiceSettings.EnableOnlyAdminIntegrations,
"enable_post_username_override": cfg.ServiceSettings.EnablePostUsernameOverride,
"enable_post_icon_override": cfg.ServiceSettings.EnablePostIconOverride,
- "enable_apiv3": *cfg.ServiceSettings.EnableAPIv3,
"enable_user_access_tokens": *cfg.ServiceSettings.EnableUserAccessTokens,
"enable_custom_emoji": *cfg.ServiceSettings.EnableCustomEmoji,
"enable_emoji_picker": *cfg.ServiceSettings.EnableEmojiPicker,
diff --git a/app/file.go b/app/file.go
index cb8d54cb1..aba09479a 100644
--- a/app/file.go
+++ b/app/file.go
@@ -295,11 +295,6 @@ func (a *App) GeneratePublicLink(siteURL string, info *model.FileInfo) string {
return fmt.Sprintf("%s/files/%v/public?h=%s", siteURL, info.Id, hash)
}
-func (a *App) GeneratePublicLinkV3(siteURL string, info *model.FileInfo) string {
- hash := GeneratePublicLinkHash(info.Id, *a.Config().FileSettings.PublicLinkSalt)
- return fmt.Sprintf("%s%s/public/files/%v/get?h=%s", siteURL, model.API_URL_SUFFIX_V3, info.Id, hash)
-}
-
func GeneratePublicLinkHash(fileId, salt string) string {
hash := sha256.New()
hash.Write([]byte(salt))
diff --git a/app/file_test.go b/app/file_test.go
index 204113782..23750ad6e 100644
--- a/app/file_test.go
+++ b/app/file_test.go
@@ -5,10 +5,16 @@ package app
import (
"fmt"
+ "os"
+ "path/filepath"
"testing"
"time"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/utils"
)
func TestGeneratePublicLinkHash(t *testing.T) {
@@ -100,3 +106,58 @@ func TestDoUploadFile(t *testing.T) {
t.Fatal("stored file at incorrect path", info4.Path)
}
}
+
+func TestGetInfoForFilename(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ post := th.BasicPost
+ teamId := th.BasicTeam.Id
+
+ info := th.App.GetInfoForFilename(post, teamId, "sometestfile")
+ assert.Nil(t, info, "Test bad filename")
+
+ info = th.App.GetInfoForFilename(post, teamId, "/somechannel/someuser/someid/somefile.png")
+ assert.Nil(t, info, "Test non-existent file")
+}
+
+func TestFindTeamIdForFilename(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ teamId := th.App.FindTeamIdForFilename(th.BasicPost, fmt.Sprintf("/%v/%v/%v/blargh.png", th.BasicChannel.Id, th.BasicUser.Id, "someid"))
+ assert.Equal(t, th.BasicTeam.Id, teamId)
+
+ _, err := th.App.CreateTeamWithUser(&model.Team{Email: th.BasicUser.Email, Name: "zz" + model.NewId(), DisplayName: "Joram's Test Team", Type: model.TEAM_OPEN}, th.BasicUser.Id)
+ require.Nil(t, err)
+
+ teamId = th.App.FindTeamIdForFilename(th.BasicPost, fmt.Sprintf("/%v/%v/%v/blargh.png", th.BasicChannel.Id, th.BasicUser.Id, "someid"))
+ assert.Equal(t, "", teamId)
+}
+
+func TestMigrateFilenamesToFileInfos(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ post := th.BasicPost
+ infos := th.App.MigrateFilenamesToFileInfos(post)
+ assert.Equal(t, 0, len(infos))
+
+ post.Filenames = []string{fmt.Sprintf("/%v/%v/%v/blargh.png", th.BasicChannel.Id, th.BasicUser.Id, "someid")}
+ infos = th.App.MigrateFilenamesToFileInfos(post)
+ assert.Equal(t, 0, len(infos))
+
+ path, _ := utils.FindDir("tests")
+ file, fileErr := os.Open(filepath.Join(path, "test.png"))
+ require.Nil(t, fileErr)
+ defer file.Close()
+
+ fpath := fmt.Sprintf("/teams/%v/channels/%v/users/%v/%v/test.png", th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, "someid")
+ _, err := th.App.WriteFile(file, fpath)
+ require.Nil(t, err)
+ rpost, err := th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/test.png", th.BasicChannel.Id, th.BasicUser.Id, "someid")}}, th.BasicChannel, false)
+ require.Nil(t, err)
+
+ infos = th.App.MigrateFilenamesToFileInfos(rpost)
+ assert.Equal(t, 1, len(infos))
+}