Improves notify props validation (#24031)

* Adds the channel member notify props max runes restriction

* Fix translations
Этот коммит содержится в:
Miguel de la Cruz
2023-07-18 17:25:11 +02:00
коммит произвёл GitHub
родитель 3c31629813
Коммит 4803889158
7 изменённых файлов: 97 добавлений и 16 удалений

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

@@ -1082,6 +1082,15 @@ func testChannelSaveMember(t *testing.T, ss store.Store) {
require.IsType(t, &store.ErrConflict{}, nErr)
})
t.Run("should fail if notify props are too big", func(t *testing.T) {
channelID := model.NewId()
props := model.GetDefaultChannelNotifyProps()
props["property"] = strings.Repeat("Z", model.ChannelMemberNotifyPropsMaxRunes)
member := &model.ChannelMember{ChannelId: channelID, UserId: u1.Id, NotifyProps: props}
_, nErr := ss.Channel().SaveMember(member)
require.ErrorContains(t, nErr, "channel_member.is_valid.notify_props")
})
t.Run("insert member correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
team := &model.Team{
DisplayName: "Name",
@@ -1581,6 +1590,15 @@ func testChannelSaveMultipleMembers(t *testing.T, ss store.Store) {
require.IsType(t, &store.ErrConflict{}, nErr)
})
t.Run("should fail if notify props are too big", func(t *testing.T) {
channelID := model.NewId()
props := model.GetDefaultChannelNotifyProps()
props["property"] = strings.Repeat("Z", model.ChannelMemberNotifyPropsMaxRunes)
member := &model.ChannelMember{ChannelId: channelID, UserId: u1.Id, NotifyProps: props}
_, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member})
require.ErrorContains(t, nErr, "channel_member.is_valid.notify_props")
})
t.Run("insert members correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
team := &model.Team{
DisplayName: "Name",
@@ -2109,6 +2127,18 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", appErr.Id)
})
t.Run("should fail with invalid error if notify props are too big", func(t *testing.T) {
props := model.GetDefaultChannelNotifyProps()
props["property"] = strings.Repeat("Z", model.ChannelMemberNotifyPropsMaxRunes)
member := &model.ChannelMember{ChannelId: model.NewId(), UserId: u1.Id, NotifyProps: props}
_, nErr := ss.Channel().UpdateMember(member)
require.Error(t, nErr)
var appErr *model.AppError
require.ErrorAs(t, nErr, &appErr)
require.Equal(t, "model.channel_member.is_valid.notify_props.app_error", appErr.Id)
})
t.Run("insert member correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
team := &model.Team{
DisplayName: "Name",
@@ -2614,6 +2644,18 @@ func testChannelUpdateMultipleMembers(t *testing.T, ss store.Store) {
require.IsType(t, &store.ErrConflict{}, nErr)
})
t.Run("should fail with invalid error if notify props are too big", func(t *testing.T) {
props := model.GetDefaultChannelNotifyProps()
props["property"] = strings.Repeat("Z", model.ChannelMemberNotifyPropsMaxRunes)
member := &model.ChannelMember{ChannelId: model.NewId(), UserId: u1.Id, NotifyProps: props}
_, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member})
require.Error(t, nErr)
var appErr *model.AppError
require.ErrorAs(t, nErr, &appErr)
require.Equal(t, "model.channel_member.is_valid.notify_props.app_error", appErr.Id)
})
t.Run("insert members correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
team := &model.Team{
DisplayName: "Name",
@@ -3152,6 +3194,14 @@ func testChannelUpdateMemberNotifyProps(t *testing.T, ss store.Store) {
require.NoError(t, nErr)
// Verify props.
assert.Equal(t, props, member.NotifyProps)
t.Run("should fail with invalid input if the notify props are too big", func(t *testing.T) {
props["property"] = strings.Repeat("Z", model.ChannelMemberNotifyPropsMaxRunes)
member, err = ss.Channel().UpdateMemberNotifyProps(member.ChannelId, member.UserId, props)
var invErr *store.ErrInvalidInput
require.ErrorAs(t, err, &invErr)
require.Nil(t, member)
})
}
func testChannelRemoveMember(t *testing.T, ss store.Store) {