summaryrefslogtreecommitdiffstats
path: root/api4/post_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-07-31 12:59:32 -0400
committerGitHub <noreply@github.com>2017-07-31 12:59:32 -0400
commit59992ae4a4638006ec1489dd834151b258c1728c (patch)
tree8bc5c0fa8f6a4d6a40026c965bd865c1110af838 /api4/post_test.go
parented62660e96528920b0ecb8c755265c6c8d2756c4 (diff)
downloadchat-59992ae4a4638006ec1489dd834151b258c1728c.tar.gz
chat-59992ae4a4638006ec1489dd834151b258c1728c.tar.bz2
chat-59992ae4a4638006ec1489dd834151b258c1728c.zip
PLT-6763 Implement user access tokens and new roles (server-side) (#6972)
* Implement user access tokens and new roles * Update config.json * Add public post permission to apiv3 * Remove old comment * Fix model unit test * Updates to store per feedback * Updates per feedback from CS
Diffstat (limited to 'api4/post_test.go')
-rw-r--r--api4/post_test.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/api4/post_test.go b/api4/post_test.go
index d554ca472..53babc6e6 100644
--- a/api4/post_test.go
+++ b/api4/post_test.go
@@ -197,7 +197,7 @@ func testCreatePostWithOutgoingHook(
if triggerWord != "" {
triggerWords = []string{triggerWord}
}
-
+
hook = &model.OutgoingWebhook{
ChannelId: channel.Id,
TeamId: team.Id,
@@ -257,6 +257,51 @@ func TestCreatePostWithOutgoingHook_no_content_type(t *testing.T) {
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TRIGGERWORDS_STARTS_WITH)
}
+func TestCreatePostPublic(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ post := &model.Post{ChannelId: th.BasicChannel.Id, Message: "#hashtag a" + model.NewId() + "a"}
+
+ user := model.User{Email: GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.ROLE_SYSTEM_USER.Id}
+
+ ruser, resp := Client.CreateUser(&user)
+ CheckNoError(t, resp)
+
+ Client.Login(user.Email, user.Password)
+
+ _, resp = Client.CreatePost(post)
+ CheckForbiddenStatus(t, resp)
+
+ app.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL_PUBLIC.Id)
+ app.InvalidateAllCaches()
+
+ Client.Login(user.Email, user.Password)
+
+ _, resp = Client.CreatePost(post)
+ CheckNoError(t, resp)
+
+ post.ChannelId = th.BasicPrivateChannel.Id
+ _, resp = Client.CreatePost(post)
+ CheckForbiddenStatus(t, resp)
+
+ app.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id)
+ app.JoinUserToTeam(th.BasicTeam, ruser, "")
+ app.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.ROLE_TEAM_USER.Id+" "+model.ROLE_TEAM_POST_ALL_PUBLIC.Id)
+ app.InvalidateAllCaches()
+
+ Client.Login(user.Email, user.Password)
+
+ post.ChannelId = th.BasicPrivateChannel.Id
+ _, resp = Client.CreatePost(post)
+ CheckForbiddenStatus(t, resp)
+
+ post.ChannelId = th.BasicChannel.Id
+ _, resp = Client.CreatePost(post)
+ CheckNoError(t, resp)
+}
+
func TestUpdatePost(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()