MM-37417: Push notification authz fix. (#18009)

* MM-37417: Push notification authz fix.

* MM-37417: Tests new app method.
Этот коммит содержится в:
Martin Kraft
2021-07-28 13:47:45 -04:00
коммит произвёл GitHub
родитель 285de45988
Коммит 37b1e6d048
7 изменённых файлов: 99 добавлений и 34 удалений

Просмотреть файл

@@ -2301,3 +2301,29 @@ func TestAutofollowOnPostingAfterUnfollow(t *testing.T) {
require.Nil(t, err)
require.True(t, m.Following)
}
func TestGetPostIfAuthorized(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
privateChannel := th.CreatePrivateChannel(th.BasicTeam)
post, err := th.App.CreatePost(th.Context, &model.Post{UserId: th.BasicUser.Id, ChannelId: privateChannel.Id, Message: "Hello"}, privateChannel, false, false)
require.Nil(t, err)
require.NotNil(t, post)
session1, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}})
require.Nil(t, err)
require.NotNil(t, session1)
session2, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser2.Id, Props: model.StringMap{}})
require.Nil(t, err)
require.NotNil(t, session2)
// User is not authorized to get post
_, err = th.App.GetPostIfAuthorized(post.Id, session2)
require.NotNil(t, err)
// User is authorized to get post
_, err = th.App.GetPostIfAuthorized(post.Id, session1)
require.Nil(t, err)
}