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>
Этот коммит содержится в:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ type WebSocketMessage interface {
|
||||
}
|
||||
|
||||
type WebsocketBroadcast struct {
|
||||
OmitUsers map[string]bool `json:"omit_users"` // broadcast is omitted for users listed here
|
||||
UserId string `json:"user_id"` // broadcast only occurs for this user
|
||||
ChannelId string `json:"channel_id"` // broadcast only occurs for users in this channel
|
||||
TeamId string `json:"team_id"` // broadcast only occurs for users in this team
|
||||
ConnectionId string `json:"connection_id"` // broadcast only occurs for this connection
|
||||
OmitConnectionId string `json:"omit_connection_id"` // broadcast is omitted for this connection
|
||||
ContainsSanitizedData bool `json:"-"`
|
||||
ContainsSensitiveData bool `json:"-"`
|
||||
OmitUsers map[string]bool `json:"omit_users"` // broadcast is omitted for users listed here
|
||||
UserId string `json:"user_id"` // broadcast only occurs for this user
|
||||
ChannelId string `json:"channel_id"` // broadcast only occurs for users in this channel
|
||||
TeamId string `json:"team_id"` // broadcast only occurs for users in this team
|
||||
ConnectionId string `json:"connection_id"` // broadcast only occurs for this connection
|
||||
OmitConnectionId string `json:"omit_connection_id"` // broadcast is omitted for this connection
|
||||
ContainsSanitizedData bool `json:"contains_sanitized_data,omitempty"` // broadcast only occurs for non-sysadmins
|
||||
ContainsSensitiveData bool `json:"contains_sensitive_data,omitempty"` // broadcast only occurs for sysadmins
|
||||
// ReliableClusterSend indicates whether or not the message should
|
||||
// be sent through the cluster using the reliable, TCP backed channel.
|
||||
ReliableClusterSend bool `json:"-"`
|
||||
|
||||
Ссылка в новой задаче
Block a user