snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
This commit is contained in:
397
server/platform/services/sharedchannel/membership_recv_test.go
Normal file
397
server/platform/services/sharedchannel/membership_recv_test.go
Normal file
@@ -0,0 +1,397 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package sharedchannel
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin/plugintest/mock"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
|
||||
)
|
||||
|
||||
// setupMembershipTest creates the common test fixtures for membership sync tests.
|
||||
// Returns a Service, the mock stores, and IDs for the channel, remote, and team.
|
||||
func setupMembershipTest(t *testing.T) (*Service, *MockServerIface, *MockAppIface, *mocks.Store, *mocks.SharedChannelStore, *mocks.ChannelStore, *mocks.UserStore) {
|
||||
t.Helper()
|
||||
|
||||
mockServer := &MockServerIface{}
|
||||
logger := mlog.CreateConsoleTestLogger(t)
|
||||
mockServer.On("Log").Return(logger)
|
||||
mockApp := &MockAppIface{}
|
||||
scs := &Service{
|
||||
server: mockServer,
|
||||
app: mockApp,
|
||||
}
|
||||
|
||||
mockStore := &mocks.Store{}
|
||||
mockSharedChannelStore := &mocks.SharedChannelStore{}
|
||||
mockChannelStore := &mocks.ChannelStore{}
|
||||
mockUserStore := &mocks.UserStore{}
|
||||
|
||||
mockStore.On("SharedChannel").Return(mockSharedChannelStore)
|
||||
mockStore.On("Channel").Return(mockChannelStore)
|
||||
mockStore.On("User").Return(mockUserStore)
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
|
||||
mockConfig := model.Config{}
|
||||
mockConfig.SetDefaults()
|
||||
mockServer.On("Config").Return(&mockConfig)
|
||||
|
||||
return scs, mockServer, mockApp, mockStore, mockSharedChannelStore, mockChannelStore, mockUserStore
|
||||
}
|
||||
|
||||
func TestOnReceiveMembershipChanges_ChannelIdMismatch(t *testing.T) {
|
||||
scs, _, _, _, mockSharedChannelStore, mockChannelStore, _ := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
mockSharedChannelStore.On("Get", channelId).Return(&model.SharedChannel{ChannelId: channelId}, nil)
|
||||
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
MembershipChanges: []*model.MembershipChangeMsg{
|
||||
{
|
||||
ChannelId: model.NewId(), // different channel ID
|
||||
UserId: model.NewId(),
|
||||
IsAdd: true,
|
||||
ChangeTime: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := scs.onReceiveMembershipChanges(syncMsg, rc)
|
||||
require.NoError(t, err) // function returns nil even on individual failures
|
||||
}
|
||||
|
||||
func TestProcessMemberAdd_RejectsLocalUser(t *testing.T) {
|
||||
scs, _, mockApp, _, mockSharedChannelStore, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
localUserId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
mockSharedChannelStore.On("Get", channelId).Return(&model.SharedChannel{ChannelId: channelId}, nil)
|
||||
|
||||
// Local user has no remote ID
|
||||
localUser := &model.User{Id: localUserId}
|
||||
mockUserStore.On("Get", mockTypeContext, localUserId).Return(localUser, nil)
|
||||
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
MembershipChanges: []*model.MembershipChangeMsg{
|
||||
{
|
||||
ChannelId: channelId,
|
||||
UserId: localUserId,
|
||||
IsAdd: true,
|
||||
ChangeTime: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := scs.onReceiveMembershipChanges(syncMsg, rc)
|
||||
require.NoError(t, err) // function returns nil even on individual failures
|
||||
|
||||
mockApp.AssertNotCalled(t, "AddUserToChannel", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
|
||||
}
|
||||
|
||||
func TestProcessMemberAdd_RejectsOtherRemoteUser(t *testing.T) {
|
||||
scs, _, mockApp, _, mockSharedChannelStore, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
otherRemoteId := model.NewId()
|
||||
userId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
mockSharedChannelStore.On("Get", channelId).Return(&model.SharedChannel{ChannelId: channelId}, nil)
|
||||
|
||||
// User belongs to a different remote
|
||||
otherRemoteUser := &model.User{Id: userId, RemoteId: &otherRemoteId}
|
||||
mockUserStore.On("Get", mockTypeContext, userId).Return(otherRemoteUser, nil)
|
||||
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
MembershipChanges: []*model.MembershipChangeMsg{
|
||||
{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
IsAdd: true,
|
||||
ChangeTime: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := scs.onReceiveMembershipChanges(syncMsg, rc)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockApp.AssertNotCalled(t, "AddUserToChannel", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
|
||||
}
|
||||
|
||||
func TestProcessMemberAdd_AllowsOwnRemoteUser(t *testing.T) {
|
||||
scs, _, mockApp, _, mockSharedChannelStore, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
userId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
mockSharedChannelStore.On("Get", channelId).Return(&model.SharedChannel{ChannelId: channelId}, nil)
|
||||
|
||||
// User belongs to the sending remote
|
||||
remoteUser := &model.User{Id: userId, RemoteId: &remoteId}
|
||||
mockUserStore.On("Get", mockTypeContext, userId).Return(remoteUser, nil)
|
||||
|
||||
// Expect the add to proceed
|
||||
mockApp.On("AddUserToChannel", mockTypeReqContext, mockTypeUser, mockTypeChannel, true).Return(&model.ChannelMember{}, nil)
|
||||
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
MembershipChanges: []*model.MembershipChangeMsg{
|
||||
{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
IsAdd: true,
|
||||
ChangeTime: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := scs.onReceiveMembershipChanges(syncMsg, rc)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockApp.AssertCalled(t, "AddUserToChannel", mockTypeReqContext, mockTypeUser, mockTypeChannel, true)
|
||||
}
|
||||
|
||||
func TestProcessMemberRemove_RejectsLocalUser(t *testing.T) {
|
||||
scs, _, mockApp, _, mockSharedChannelStore, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
localUserId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
mockSharedChannelStore.On("Get", channelId).Return(&model.SharedChannel{ChannelId: channelId}, nil)
|
||||
|
||||
// Local user has no remote ID
|
||||
localUser := &model.User{Id: localUserId}
|
||||
mockUserStore.On("Get", mockTypeContext, localUserId).Return(localUser, nil)
|
||||
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
MembershipChanges: []*model.MembershipChangeMsg{
|
||||
{
|
||||
ChannelId: channelId,
|
||||
UserId: localUserId,
|
||||
IsAdd: false,
|
||||
ChangeTime: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := scs.onReceiveMembershipChanges(syncMsg, rc)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockApp.AssertNotCalled(t, "RemoveUserFromChannel", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
|
||||
}
|
||||
|
||||
func TestProcessMemberRemove_RejectsOtherRemoteUser(t *testing.T) {
|
||||
scs, _, mockApp, _, mockSharedChannelStore, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
otherRemoteId := model.NewId()
|
||||
userId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
mockSharedChannelStore.On("Get", channelId).Return(&model.SharedChannel{ChannelId: channelId}, nil)
|
||||
|
||||
// User belongs to a different remote
|
||||
otherRemoteUser := &model.User{Id: userId, RemoteId: &otherRemoteId}
|
||||
mockUserStore.On("Get", mockTypeContext, userId).Return(otherRemoteUser, nil)
|
||||
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
MembershipChanges: []*model.MembershipChangeMsg{
|
||||
{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
IsAdd: false,
|
||||
ChangeTime: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := scs.onReceiveMembershipChanges(syncMsg, rc)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockApp.AssertNotCalled(t, "RemoveUserFromChannel", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
|
||||
}
|
||||
|
||||
func TestProcessMemberRemove_AllowsOwnRemoteUser(t *testing.T) {
|
||||
scs, _, mockApp, _, mockSharedChannelStore, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
userId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
mockSharedChannelStore.On("Get", channelId).Return(&model.SharedChannel{ChannelId: channelId}, nil)
|
||||
|
||||
// User belongs to the sending remote
|
||||
remoteUser := &model.User{Id: userId, RemoteId: &remoteId}
|
||||
mockUserStore.On("Get", mockTypeContext, userId).Return(remoteUser, nil)
|
||||
|
||||
// Expect the remove to proceed
|
||||
mockApp.On("RemoveUserFromChannel", mockTypeReqContext, userId, "", channel).Return(nil)
|
||||
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
MembershipChanges: []*model.MembershipChangeMsg{
|
||||
{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
IsAdd: false,
|
||||
ChangeTime: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := scs.onReceiveMembershipChanges(syncMsg, rc)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockApp.AssertCalled(t, "RemoveUserFromChannel", mockTypeReqContext, userId, "", channel)
|
||||
}
|
||||
|
||||
func TestProcessMemberAdd_SkipsLocalUser(t *testing.T) {
|
||||
scs, _, _, _, _, _, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
localUserId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
|
||||
// Local user (no remote ID) — needed for the fallback User().Get path
|
||||
mockUserStore.On("Get", mockTypeContext, localUserId).Return(&model.User{Id: localUserId}, nil)
|
||||
|
||||
change := &model.MembershipChangeMsg{
|
||||
ChannelId: channelId,
|
||||
UserId: localUserId,
|
||||
IsAdd: true,
|
||||
ChangeTime: 1000,
|
||||
}
|
||||
syncMsg := &model.SyncMsg{
|
||||
ChannelId: channelId,
|
||||
}
|
||||
|
||||
err := scs.processMemberAdd(change, channel, rc, syncMsg)
|
||||
require.NoError(t, err, "local users should be silently skipped")
|
||||
}
|
||||
|
||||
func TestProcessMemberRemove_SkipsLocalUser(t *testing.T) {
|
||||
scs, _, _, _, _, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
localUserId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
|
||||
// Local user (no remote ID)
|
||||
mockUserStore.On("Get", mockTypeContext, localUserId).Return(&model.User{Id: localUserId}, nil)
|
||||
|
||||
change := &model.MembershipChangeMsg{
|
||||
ChannelId: channelId,
|
||||
UserId: localUserId,
|
||||
IsAdd: false,
|
||||
ChangeTime: 1000,
|
||||
}
|
||||
|
||||
err := scs.processMemberRemove(change, rc)
|
||||
require.NoError(t, err, "local users should be silently skipped")
|
||||
}
|
||||
|
||||
func TestProcessMemberAdd_IdempotentForExistingMember(t *testing.T) {
|
||||
scs, _, mockApp, _, _, _, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
userId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
|
||||
// User belongs to the sending remote
|
||||
remoteUser := &model.User{Id: userId, RemoteId: &remoteId}
|
||||
mockUserStore.On("Get", mockTypeContext, userId).Return(remoteUser, nil)
|
||||
|
||||
// Simulate "already added" error from AddUserToChannel
|
||||
alreadyAddedErr := model.NewAppError("AddUserToChannel", errIDSaveMemberExists, nil, "", http.StatusBadRequest)
|
||||
mockApp.On("AddUserToChannel", mockTypeReqContext, mockTypeUser, mockTypeChannel, true).Return(nil, alreadyAddedErr)
|
||||
|
||||
syncMsg := &model.SyncMsg{ChannelId: channelId}
|
||||
change := &model.MembershipChangeMsg{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
IsAdd: true,
|
||||
ChangeTime: 1000,
|
||||
}
|
||||
|
||||
err := scs.processMemberAdd(change, channel, rc, syncMsg)
|
||||
require.NoError(t, err, "should succeed for already-added user (idempotent)")
|
||||
}
|
||||
|
||||
func TestProcessMemberRemove_IdempotentForNonMember(t *testing.T) {
|
||||
scs, _, mockApp, _, _, mockChannelStore, mockUserStore := setupMembershipTest(t)
|
||||
|
||||
channelId := model.NewId()
|
||||
remoteId := model.NewId()
|
||||
userId := model.NewId()
|
||||
rc := &model.RemoteCluster{RemoteId: remoteId}
|
||||
channel := &model.Channel{Id: channelId, Type: model.ChannelTypeOpen}
|
||||
|
||||
mockChannelStore.On("Get", channelId, true).Return(channel, nil)
|
||||
|
||||
// User belongs to the sending remote
|
||||
remoteUser := &model.User{Id: userId, RemoteId: &remoteId}
|
||||
mockUserStore.On("Get", mockTypeContext, userId).Return(remoteUser, nil)
|
||||
|
||||
// Simulate "not found" error from RemoveUserFromChannel
|
||||
notFoundErr := model.NewAppError("RemoveUserFromChannel", errIDGetChannelMemberMissing, nil, "", http.StatusNotFound)
|
||||
mockApp.On("RemoveUserFromChannel", mockTypeReqContext, userId, "", channel).Return(notFoundErr)
|
||||
|
||||
change := &model.MembershipChangeMsg{
|
||||
ChannelId: channelId,
|
||||
UserId: userId,
|
||||
IsAdd: false,
|
||||
ChangeTime: 1000,
|
||||
}
|
||||
|
||||
err := scs.processMemberRemove(change, rc)
|
||||
require.NoError(t, err, "should succeed for already-removed user (idempotent)")
|
||||
}
|
||||
Reference in New Issue
Block a user