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
|
package platform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -551,3 +552,31 @@ func BenchmarkGetHubForUserId(b *testing.B) {
|
|||||||
hubSink = th.Service.GetHubForUserId(th.BasicUser.Id)
|
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 {
|
type WebsocketBroadcast struct {
|
||||||
OmitUsers map[string]bool `json:"omit_users"` // broadcast is omitted for users listed here
|
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
|
UserId string `json:"user_id"` // broadcast only occurs for this user
|
||||||
ChannelId string `json:"channel_id"` // broadcast only occurs for users in this channel
|
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
|
TeamId string `json:"team_id"` // broadcast only occurs for users in this team
|
||||||
ConnectionId string `json:"connection_id"` // broadcast only occurs for this connection
|
ConnectionId string `json:"connection_id"` // broadcast only occurs for this connection
|
||||||
OmitConnectionId string `json:"omit_connection_id"` // broadcast is omitted for this connection
|
OmitConnectionId string `json:"omit_connection_id"` // broadcast is omitted for this connection
|
||||||
ContainsSanitizedData bool `json:"-"`
|
ContainsSanitizedData bool `json:"contains_sanitized_data,omitempty"` // broadcast only occurs for non-sysadmins
|
||||||
ContainsSensitiveData bool `json:"-"`
|
ContainsSensitiveData bool `json:"contains_sensitive_data,omitempty"` // broadcast only occurs for sysadmins
|
||||||
// ReliableClusterSend indicates whether or not the message should
|
// ReliableClusterSend indicates whether or not the message should
|
||||||
// be sent through the cluster using the reliable, TCP backed channel.
|
// be sent through the cluster using the reliable, TCP backed channel.
|
||||||
ReliableClusterSend bool `json:"-"`
|
ReliableClusterSend bool `json:"-"`
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user