MM-53687: Block changes to name, display name or purpose for direct and group messages (#24199)
* block changes to name, display name or purpose for direct and group messages * add test * fix condition * update patch_channel * update error message * fix message * fix lint * fix i18n ```release-note NONE ``` --------- Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
947f71ae74
Коммит
de000e888d
@@ -259,6 +259,58 @@ func TestUpdateChannel(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
t.Run("Should block changes to name, display name or purpose for group messages", func(t *testing.T) {
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
user3 := th.CreateUser()
|
||||
|
||||
client.Logout(context.Background())
|
||||
client.Login(context.Background(), user1.Email, user1.Password)
|
||||
|
||||
groupChannel, _, err := client.CreateGroupChannel(context.Background(), []string{user1.Id, user2.Id, user3.Id})
|
||||
require.NoError(t, err)
|
||||
|
||||
updatedChannel := &model.Channel{Id: groupChannel.Id, Name: "test name"}
|
||||
_, resp, err := client.UpdateChannel(context.Background(), updatedChannel)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
updatedChannel2 := &model.Channel{Id: groupChannel.Id, DisplayName: "test display name"}
|
||||
_, resp, err = client.UpdateChannel(context.Background(), updatedChannel2)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
updatedChannel3 := &model.Channel{Id: groupChannel.Id, Purpose: "test purpose"}
|
||||
_, resp, err = client.UpdateChannel(context.Background(), updatedChannel3)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("Should block changes to name, display name or purpose for direct messages", func(t *testing.T) {
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
|
||||
client.Logout(context.Background())
|
||||
client.Login(context.Background(), user1.Email, user1.Password)
|
||||
|
||||
directChannel, _, err := client.CreateDirectChannel(context.Background(), user1.Id, user2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
updatedChannel := &model.Channel{Id: directChannel.Id, Name: "test name"}
|
||||
_, resp, err := client.UpdateChannel(context.Background(), updatedChannel)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
updatedChannel2 := &model.Channel{Id: directChannel.Id, DisplayName: "test display name"}
|
||||
_, resp, err = client.UpdateChannel(context.Background(), updatedChannel2)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
updatedChannel3 := &model.Channel{Id: directChannel.Id, Purpose: "test purpose"}
|
||||
_, resp, err = client.UpdateChannel(context.Background(), updatedChannel3)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPatchChannel(t *testing.T) {
|
||||
@@ -365,6 +417,77 @@ func TestPatchChannel(t *testing.T) {
|
||||
_, resp, err = client.PatchChannel(context.Background(), directChannel.Id, channelPatch)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
t.Run("Should block changes to name, display name or purpose for group messages", func(t *testing.T) {
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
user3 := th.CreateUser()
|
||||
|
||||
client.Logout(context.Background())
|
||||
client.Login(context.Background(), user1.Email, user1.Password)
|
||||
|
||||
groupChannel, _, err := client.CreateGroupChannel(context.Background(), []string{user1.Id, user2.Id, user3.Id})
|
||||
require.NoError(t, err)
|
||||
|
||||
groupChannelPatch := &model.ChannelPatch{
|
||||
Name: new(string),
|
||||
}
|
||||
*groupChannelPatch.Name = "testing"
|
||||
_, resp, err := client.PatchChannel(context.Background(), groupChannel.Id, groupChannelPatch)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
groupChannelPatch2 := &model.ChannelPatch{
|
||||
DisplayName: new(string),
|
||||
}
|
||||
*groupChannelPatch2.DisplayName = "test display name"
|
||||
_, resp, err = client.PatchChannel(context.Background(), groupChannel.Id, groupChannelPatch2)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
groupChannelPatch3 := &model.ChannelPatch{
|
||||
Purpose: new(string),
|
||||
}
|
||||
*groupChannelPatch3.Purpose = "test purpose"
|
||||
_, resp, err = client.PatchChannel(context.Background(), groupChannel.Id, groupChannelPatch3)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("Should block changes to name, display name or purpose for direct messages", func(t *testing.T) {
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
|
||||
client.Logout(context.Background())
|
||||
client.Login(context.Background(), user1.Email, user1.Password)
|
||||
|
||||
directChannel, _, err := client.CreateDirectChannel(context.Background(), user1.Id, user2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
directChannelPatch := &model.ChannelPatch{
|
||||
Name: new(string),
|
||||
}
|
||||
*directChannelPatch.Name = "test"
|
||||
_, resp, err := client.PatchChannel(context.Background(), directChannel.Id, directChannelPatch)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
directChannelPatch2 := &model.ChannelPatch{
|
||||
DisplayName: new(string),
|
||||
}
|
||||
*directChannelPatch2.DisplayName = "test display name"
|
||||
_, resp, err = client.PatchChannel(context.Background(), directChannel.Id, directChannelPatch2)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
directChannelPatch3 := &model.ChannelPatch{
|
||||
Purpose: new(string),
|
||||
}
|
||||
*directChannelPatch3.Purpose = "test purpose"
|
||||
_, resp, err = client.PatchChannel(context.Background(), directChannel.Id, directChannelPatch3)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestChannelUnicodeNames(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user