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 Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-16 00:29:55 +05:00
commit 240db4e2a7
15309 changed files with 2173406 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {expect, test} from '@mattermost/playwright-lib';
/**
* Coverage for MM-68952 / PR #36815 — per-viewer resolution of `~channel` mentions.
*
* The server populates `post.props.channel_mentions` for the post creator, then strips it
* per-viewer using `HasPermissionToResolveChannelMention`. The webapp only renders a clickable
* `a.mention-link` (display name) when the viewer's `channel_mentions` still contains the channel;
* otherwise it renders the literal `~slug` text.
*
* `HasPermissionToResolveChannelMention` resolves PUBLIC channels for any team member (independent
* of Compliance Monitoring), but keeps PRIVATE/DM/GM and cross-team channels stripped.
*/
test.describe('channel mention resolution', () => {
/**
* @objective A public channel mention authored on one team renders as the raw `~slug`
* (unresolved, non-clickable) for a viewer who does not belong to that channel's team.
*
* @precondition The viewer shares only a DM with the author and never joins the author's team.
*
* This is the license-free half of the fix (cross-team disclosure stays prevented) and is the
* simplest scenario whose rendering differs from the pre-fix behavior without Compliance Monitoring.
*/
test(
'keeps a cross-team public channel mention unresolved for a non-team viewer',
{tag: '@mentions'},
async ({pw}) => {
// # Initialize the author on team A
const {adminClient, user: author, userClient, team: teamA} = await pw.initSetup();
// # Create a public channel on team A with a display name distinct from its slug, so a
// resolved mention (display name) is clearly distinguishable from an unresolved one (slug)
const channelName = `cross-team-public-${pw.random.id()}`;
const channelDisplayName = 'Cross Team Secret';
const publicChannel = await adminClient.createChannel({
team_id: teamA.id,
name: channelName,
display_name: channelDisplayName,
type: 'O',
});
await adminClient.addToChannel(author.id, publicChannel.id);
// # Create a viewer that belongs only to a different team B (never to team A)
const viewer = await pw.createNewUserProfile(adminClient);
const teamB = await pw.createNewTeam(adminClient);
await adminClient.addToTeam(teamB.id, viewer.id);
// # Open a DM between author and viewer (DMs are the only cross-team-visible channel)
const dmChannel = await adminClient.createDirectChannel([author.id, viewer.id]);
// # Author posts the public channel mention into the DM. current_team_id scopes the
// server-side name lookup to team A so the mention resolves for the author at creation time.
await userClient.createPost({
channel_id: dmChannel.id,
message: `Check out ~${channelName}`,
user_id: author.id,
props: {current_team_id: teamA.id},
});
// # Log in as the viewer and open the DM via team B
const {channelsPage} = await pw.testBrowser.login(viewer);
await channelsPage.goto(teamB.name, `@${author.username}`);
await channelsPage.toBeVisible();
const lastPost = await channelsPage.getLastPost();
// * The mention is NOT resolved into a clickable channel link for the cross-team viewer
await expect(lastPost.body.locator('a.mention-link[data-channel-mention]')).toHaveCount(0);
// * The raw `~slug` is rendered as plain text and the display name is never disclosed
await expect(lastPost.body).toContainText(`~${channelName}`);
await expect(lastPost.body).not.toContainText(channelDisplayName);
},
);
/**
* @objective With Compliance Monitoring enabled, a public channel mention resolves into a
* clickable `a.mention-link` (display name) for a team member who is NOT a member of the channel.
*
* @precondition Enterprise license + Compliance Monitoring. This is the exact regression from
* MM-68952: before the fix the per-viewer permission check (HasPermissionToReadChannel) failed
* under Compliance for non-members, so the mention was stripped to the raw `~slug`.
*/
test(
'resolves a public channel mention for a non-member team member when Compliance Monitoring is on',
{tag: '@mentions'},
async ({pw}) => {
// Requires an enterprise license; skipped on unlicensed servers (e.g. local dev).
await pw.skipIfNoLicense();
const {adminClient, user: author, userClient, team} = await pw.initSetup();
// NOTE: ComplianceSettings is a global, server-wide setting. Toggling it can affect other
// tests running in parallel; we restore it in a finally block to limit the blast radius.
await adminClient.patchConfig({ComplianceSettings: {Enable: true}});
try {
// # Create a public channel; the author is a member, the viewer will not be
const channelName = `compliance-public-${pw.random.id()}`;
const channelDisplayName = 'Compliance Public Channel';
const publicChannel = await adminClient.createChannel({
team_id: team.id,
name: channelName,
display_name: channelDisplayName,
type: 'O',
});
await adminClient.addToChannel(author.id, publicChannel.id);
// # Create a viewer who is a team member but NOT a member of the public channel
const viewer = await pw.createNewUserProfile(adminClient);
await adminClient.addToTeam(team.id, viewer.id);
// # Author posts the mention in town-square (both users are members)
const townSquare = await adminClient.getChannelByName(team.id, 'town-square');
await userClient.createPost({
channel_id: townSquare.id,
message: `Please see ~${channelName}`,
user_id: author.id,
});
// # Log in as the viewer and open town-square
const {channelsPage} = await pw.testBrowser.login(viewer);
await channelsPage.goto(team.name, 'town-square');
await channelsPage.toBeVisible();
const lastPost = await channelsPage.getLastPost();
// * The mention resolves to a clickable channel link showing the display name
const mentionLink = lastPost.body.locator(`a.mention-link[data-channel-mention="${channelName}"]`);
await expect(mentionLink).toBeVisible();
await expect(mentionLink).toContainText(channelDisplayName);
} finally {
await adminClient.patchConfig({ComplianceSettings: {Enable: false}});
}
},
);
});