snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-16 01:21:02 +05:00
commit 30810eecd7
10161 changed files with 987110 additions and 0 deletions

View File

@@ -0,0 +1,154 @@
import { MockedServerContext, MockedSettingsContext, MockedUserContext } from '@rocket.chat/mock-providers';
import { render } from '@testing-library/react';
import { Meteor } from 'meteor/meteor';
import SAMLLoginRoute from './SAMLLoginRoute';
import RouterContextMock from '../../../tests/mocks/client/RouterContextMock';
import { useSamlInviteToken } from '../invite/hooks/useSamlInviteToken';
jest.mock('../invite/hooks/useSamlInviteToken');
const mockUseSamlInviteToken = jest.mocked(useSamlInviteToken);
const navigateStub = jest.fn();
beforeAll(() => {
jest.spyOn(Storage.prototype, 'getItem');
});
beforeEach(() => {
jest.clearAllMocks();
navigateStub.mockClear();
(Meteor.loginWithSamlToken as jest.Mock<any>).mockClear();
});
it('should redirect to /home', async () => {
mockUseSamlInviteToken.mockReturnValue([null, () => ({})]);
render(
<MockedServerContext>
<MockedUserContext>
<RouterContextMock navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedUserContext>
</MockedServerContext>,
);
expect(navigateStub).toHaveBeenCalledTimes(1);
expect(navigateStub).toHaveBeenLastCalledWith(expect.objectContaining({ pathname: '/home' }), expect.anything());
});
it('should redirect to /home when userId is null and the stored invite token is not valid', async () => {
mockUseSamlInviteToken.mockReturnValue([null, () => ({})]);
render(
<MockedServerContext>
<RouterContextMock searchParameters={{ redirectUrl: 'http://rocket.chat' }} navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedServerContext>,
);
expect(navigateStub).toHaveBeenCalledTimes(1);
expect(navigateStub).toHaveBeenLastCalledWith(expect.objectContaining({ pathname: '/home' }), expect.anything());
});
it('should redirect to the invite page with the stored invite token when it is valid', async () => {
mockUseSamlInviteToken.mockReturnValue(['test', () => ({})]);
render(
<MockedServerContext>
<RouterContextMock navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedServerContext>,
);
expect(navigateStub).toHaveBeenCalledTimes(1);
expect(navigateStub).toHaveBeenLastCalledWith(expect.objectContaining({ pathname: '/invite/test' }), expect.anything());
});
it('should call loginWithSamlToken when component is mounted', async () => {
render(
<MockedServerContext>
<RouterContextMock navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedServerContext>,
);
expect(Meteor.loginWithSamlToken).toHaveBeenCalledTimes(1);
expect(Meteor.loginWithSamlToken).toHaveBeenLastCalledWith(undefined, expect.any(Function));
});
it('should call loginWithSamlToken with the token when it is present', async () => {
render(
<MockedUserContext>
<RouterContextMock routeParameters={{ token: 'testToken' }} navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedUserContext>,
);
expect(Meteor.loginWithSamlToken).toHaveBeenCalledTimes(1);
expect(Meteor.loginWithSamlToken).toHaveBeenLastCalledWith('testToken', expect.any(Function));
});
jest.mock('../../lib/buildAuthDeeplinkURL', () => ({ buildSamlDeepLinkURL: jest.fn() }));
describe('native client handoff', () => {
const { buildSamlDeepLinkURL } = jest.requireMock('../../lib/buildAuthDeeplinkURL') as { buildSamlDeepLinkURL: jest.Mock };
const navigableDeepLink = `${window.location.origin}/#deep-link`;
beforeEach(() => {
mockUseSamlInviteToken.mockReturnValue([null, () => ({})]);
buildSamlDeepLinkURL.mockReturnValue(navigableDeepLink);
});
afterEach(() => {
window.location.hash = '';
});
it.each(['mobile', 'desktop'])('should hand the credential token to the %s client without logging in', async (loginClient) => {
render(
<MockedServerContext>
<RouterContextMock routeParameters={{ token: 'testToken' }} searchParameters={{ loginClient }} navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedServerContext>,
);
// The browser must never authenticate: the app redeems the credential on its own connection.
expect(Meteor.loginWithSamlToken).not.toHaveBeenCalled();
expect(navigateStub).not.toHaveBeenCalled();
expect(buildSamlDeepLinkURL).toHaveBeenCalledTimes(1);
expect(buildSamlDeepLinkURL).toHaveBeenLastCalledWith('testToken');
expect(window.location.href).toBe(navigableDeepLink);
});
it('should log in normally for an unrecognized loginClient', async () => {
render(
<MockedServerContext>
<RouterContextMock routeParameters={{ token: 'testToken' }} searchParameters={{ loginClient: 'web' }} navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedServerContext>,
);
expect(buildSamlDeepLinkURL).not.toHaveBeenCalled();
expect(Meteor.loginWithSamlToken).toHaveBeenCalledTimes(1);
});
it('should ignore loginClient and log in normally when the modern flow is disabled', async () => {
render(
<MockedServerContext>
<MockedSettingsContext settings={{ Accounts_OAuth_Use_Modern_Flow: false }}>
<RouterContextMock routeParameters={{ token: 'testToken' }} searchParameters={{ loginClient: 'desktop' }} navigate={navigateStub}>
<SAMLLoginRoute />
</RouterContextMock>
</MockedSettingsContext>
</MockedServerContext>,
);
expect(buildSamlDeepLinkURL).not.toHaveBeenCalled();
expect(Meteor.loginWithSamlToken).toHaveBeenCalledTimes(1);
});
});