MM-49048: do not omit needed wsbroadcast vars (#22156)

* MM-49048: do not omit needed wsbroadcast vars

It seems that we are omitting ContainsSanitizedData, and
ContainsSensitiveData variables in WebsocketBroadcast.
This created a bug in cluster mode, in which we were sending duplicate
events to users whereas normally they would have access to only one of those.

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Kyriakos Z
2023-01-30 18:10:39 +02:00
коммит произвёл GitHub
родитель 289328c4b4
Коммит 70800b2447
2 изменённых файлов: 37 добавлений и 8 удалений

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

@@ -4,6 +4,7 @@
package platform
import (
"encoding/json"
"net"
"net/http"
"net/http/httptest"
@@ -551,3 +552,31 @@ func BenchmarkGetHubForUserId(b *testing.B) {
hubSink = th.Service.GetHubForUserId(th.BasicUser.Id)
}
}
func TestClusterBroadcast(t *testing.T) {
testCluster := &testlib.FakeClusterInterface{}
th := SetupWithCluster(t, testCluster)
defer th.TearDown()
ev := model.NewWebSocketEvent("test_event", "", "", "", nil, "")
broadcast := &model.WebsocketBroadcast{
ContainsSanitizedData: true,
ContainsSensitiveData: true,
}
ev = ev.SetBroadcast(broadcast)
th.Service.Publish(ev)
messages := testCluster.GetMessages()
var clusterEvent struct {
Event string `json:"event"`
Data map[string]any `json:"data"`
Broadcast *model.WebsocketBroadcast `json:"broadcast"`
Sequence int64 `json:"seq"`
}
err := json.Unmarshal(messages[0].Data, &clusterEvent)
require.NoError(t, err)
require.Equal(t, clusterEvent.Broadcast, broadcast)
}