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
Code scanning - action / CodeQL-Build (push) Failing after 1s
Auto-close duplicate issues / auto-close-duplicates (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,81 @@
import type { ISetting } from '@rocket.chat/core-typings';
import { Button } from '@rocket.chat/fuselage';
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
import { useEndpoint, useSetModal, useToastMessageDispatch, useSettingStructure } from '@rocket.chat/ui-contexts';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import SamlMetadataModal from './SamlMetadataModal';
import type { SamlMetadataValues } from './SamlMetadataModal';
import { useEditableSettings, useEditableSettingsDispatch } from '../../../EditableSettingsContext';
import BaseGroupPage from '../BaseGroupPage';
type SAMLGroupPageProps = ISetting & {
onClickBack?: () => void;
};
function SAMLGroupPage({ _id, i18nLabel, onClickBack, ...group }: SAMLGroupPageProps) {
const { t } = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const parseMetadata = useEndpoint('POST', '/v1/saml.parseMetadata');
const setModal = useSetModal();
const closeModal = useStableCallback(() => setModal());
const dispatch = useEditableSettingsDispatch();
const certSetting = useSettingStructure('SAML_Custom_Default_cert');
const entryPointSetting = useSettingStructure('SAML_Custom_Default_entry_point');
const sloSetting = useSettingStructure('SAML_Custom_Default_idp_slo_redirect_url');
const identifierFormatSetting = useSettingStructure('SAML_Custom_Default_identifier_format');
const editableSettings = useEditableSettings(useMemo(() => ({ group: _id }), [_id]));
const changed = useMemo(() => editableSettings.some(({ changed }) => changed), [editableSettings]);
const handleApply = useStableCallback((values: SamlMetadataValues) => {
// identifier_format is only registered on Enterprise installs; skip any setting that isn't present.
const add = (setting: ISetting | undefined, value?: string) =>
setting && value !== undefined ? [{ _id: setting._id, value, changed: JSON.stringify(setting.value) !== JSON.stringify(value) }] : [];
const changes = [
...add(certSetting, values.cert),
...add(entryPointSetting, values.entryPoint),
...add(sloSetting, values.idpSLORedirectURL),
...add(identifierFormatSetting, values.identifierFormat),
];
dispatch(changes);
closeModal();
if (changes.length === 0) {
dispatchToastMessage({ type: 'warning', message: t('SAML_Metadata_no_values') });
return;
}
dispatchToastMessage({ type: 'success', message: t('SAML_Metadata_applied') });
});
const handleImportClick = () =>
setModal(
<SamlMetadataModal
onClose={closeModal}
onFetch={(url) => parseMetadata({ url })}
onApply={handleApply}
showIdentifierFormat={identifierFormatSetting !== undefined}
/>,
);
return (
<BaseGroupPage
_id={_id}
i18nLabel={i18nLabel}
onClickBack={onClickBack}
{...group}
headerButtons={
<Button disabled={changed} onClick={handleImportClick}>
{t('SAML_Import_metadata')}
</Button>
}
/>
);
}
export default memo(SAMLGroupPage);

View File

@@ -0,0 +1,122 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import SamlMetadataModal from './SamlMetadataModal';
const setup = (overrides: Partial<Parameters<typeof SamlMetadataModal>[0]> = {}) => {
const props = {
onClose: jest.fn(),
onFetch: jest.fn().mockResolvedValue({
cert: 'CERTDATA',
entryPoint: 'https://idp.test/sso',
idpSLORedirectURL: 'https://idp.test/slo',
warnings: [],
}),
onApply: jest.fn(),
...overrides,
};
render(<SamlMetadataModal {...props} />, { wrapper: mockAppRoot().build() });
return props;
};
it('fetches metadata and shows the preview, then applies edited values', async () => {
const props = setup();
await userEvent.type(screen.getByLabelText('SAML_Metadata_url'), 'https://idp.test/metadata.xml');
await userEvent.click(screen.getByText('SAML_Metadata_fetch'));
await waitFor(() => expect(props.onFetch).toHaveBeenCalledWith('https://idp.test/metadata.xml'));
const entryPointInput = await screen.findByLabelText('SAML_Custom_Entry_point');
expect(entryPointInput).toHaveValue('https://idp.test/sso');
expect(screen.getByLabelText('SAML_Custom_Cert')).toHaveValue('CERTDATA');
expect(screen.getByLabelText('SAML_Custom_IDP_SLO_Redirect_URL')).toHaveValue('https://idp.test/slo');
await userEvent.clear(entryPointInput);
await userEvent.type(entryPointInput, 'https://idp.test/sso-edited');
await userEvent.click(screen.getByText('Apply'));
expect(props.onApply).toHaveBeenCalledWith({
cert: 'CERTDATA',
entryPoint: 'https://idp.test/sso-edited',
idpSLORedirectURL: 'https://idp.test/slo',
});
});
it('shows a warning callout when the fetch result carries warnings', async () => {
setup({
onFetch: jest.fn().mockResolvedValue({ cert: 'CERTDATA', warnings: ['SAML_Metadata_warning_multiple_certs'] }),
});
await userEvent.type(screen.getByLabelText('SAML_Metadata_url'), 'https://idp.test/metadata.xml');
await userEvent.click(screen.getByText('SAML_Metadata_fetch'));
expect(await screen.findByText('SAML_Metadata_warning_multiple_certs')).toBeInTheDocument();
});
it('returns to Fetch mode when the URL is edited after a successful fetch', async () => {
setup();
await userEvent.type(screen.getByLabelText('SAML_Metadata_url'), 'https://idp.test/metadata.xml');
await userEvent.click(screen.getByText('SAML_Metadata_fetch'));
expect(await screen.findByText('Apply')).toBeInTheDocument();
await userEvent.type(screen.getByLabelText('SAML_Metadata_url'), '2');
expect(await screen.findByText('SAML_Metadata_fetch')).toBeInTheDocument();
expect(screen.queryByText('Apply')).not.toBeInTheDocument();
});
it('shows the Identifier Format row only when showIdentifierFormat is true', async () => {
setup({
showIdentifierFormat: true,
onFetch: jest.fn().mockResolvedValue({
cert: 'CERTDATA',
entryPoint: 'https://idp.test/sso',
idpSLORedirectURL: 'https://idp.test/slo',
identifierFormat: 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
warnings: [],
}),
});
await userEvent.type(screen.getByLabelText('SAML_Metadata_url'), 'https://idp.test/metadata.xml');
await userEvent.click(screen.getByText('SAML_Metadata_fetch'));
expect(await screen.findByLabelText('SAML_Identifier_Format')).toHaveValue('urn:oasis:names:tc:SAML:2.0:nameid-format:transient');
});
it('does not show the Identifier Format row when showIdentifierFormat is false', async () => {
setup();
await userEvent.type(screen.getByLabelText('SAML_Metadata_url'), 'https://idp.test/metadata.xml');
await userEvent.click(screen.getByText('SAML_Metadata_fetch'));
expect(await screen.findByLabelText('SAML_Custom_Cert')).toBeInTheDocument();
expect(screen.queryByLabelText('SAML_Identifier_Format')).not.toBeInTheDocument();
});
it('calls onClose when Cancel is clicked', async () => {
const props = setup();
await userEvent.click(screen.getByText('Cancel'));
expect(props.onClose).toHaveBeenCalled();
});
it('shows a danger callout and allows retry when fetch fails', async () => {
setup({
onFetch: jest.fn().mockRejectedValueOnce({ success: false, error: 'SAML_Metadata_fetch_failed' }),
});
await userEvent.type(screen.getByLabelText('SAML_Metadata_url'), 'https://idp.test/metadata.xml');
await userEvent.click(screen.getByText('SAML_Metadata_fetch'));
expect(await screen.findByText('SAML_Metadata_fetch_failed')).toBeInTheDocument();
const confirmButton = screen.getByText('SAML_Metadata_fetch');
expect(confirmButton).toBeInTheDocument();
expect(confirmButton).not.toBeDisabled();
const urlInput = screen.getByLabelText('SAML_Metadata_url') as HTMLInputElement;
expect(urlInput.value).toBe('https://idp.test/metadata.xml');
});

View File

@@ -0,0 +1,184 @@
import { Box, Callout, Field, FieldLabel, FieldRow, TextAreaInput, TextInput } from '@rocket.chat/fuselage';
import { GenericModal } from '@rocket.chat/ui-client';
import type { ChangeEvent } from 'react';
import { useId, useState } from 'react';
import { useTranslation } from 'react-i18next';
export type SamlMetadataValues = {
cert?: string;
entryPoint?: string;
idpSLORedirectURL?: string;
identifierFormat?: string;
};
type SamlMetadataFetchResult = SamlMetadataValues & { warnings: string[] };
type SamlMetadataModalProps = {
onClose: () => void;
onFetch: (url: string) => Promise<SamlMetadataFetchResult>;
onApply: (values: SamlMetadataValues) => void;
showIdentifierFormat?: boolean;
};
const KNOWN_SAML_METADATA_ERROR_KEYS = [
'SAML_Metadata_url_blocked',
'SAML_Metadata_fetch_failed',
'SAML_Metadata_too_large',
'SAML_Metadata_invalid',
];
const getSamlMetadataErrorKey = (error: unknown): string => {
const key = (error as { error?: unknown } | undefined)?.error;
return typeof key === 'string' && KNOWN_SAML_METADATA_ERROR_KEYS.includes(key) ? key : 'SAML_Metadata_fetch_failed';
};
const SamlMetadataModal = ({ onClose, onFetch, onApply, showIdentifierFormat = false }: SamlMetadataModalProps) => {
const { t } = useTranslation();
const [url, setUrl] = useState('');
const [fetching, setFetching] = useState(false);
const [error, setError] = useState<string | null>(null);
const [warnings, setWarnings] = useState<string[]>([]);
const [values, setValues] = useState<SamlMetadataValues | null>(null);
const urlFieldId = useId();
const certFieldId = useId();
const entryPointFieldId = useId();
const sloFieldId = useId();
const identifierFormatFieldId = useId();
const handleFetch = async () => {
if (!url.trim()) {
return;
}
setFetching(true);
setError(null);
try {
const { cert, entryPoint, idpSLORedirectURL, identifierFormat, warnings: fetchWarnings } = await onFetch(url.trim());
setValues({ cert, entryPoint, idpSLORedirectURL, identifierFormat });
setWarnings(fetchWarnings);
} catch (e) {
setError(getSamlMetadataErrorKey(e));
} finally {
setFetching(false);
}
};
const handleApply = () => {
if (values) {
onApply(values);
}
};
const setValue = (key: keyof SamlMetadataValues) => (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const { value } = event.currentTarget;
setValues((current) => ({ ...current, [key]: value }));
};
return (
<GenericModal
variant='info'
title={t('SAML_Import_metadata')}
confirmText={values ? t('Apply') : t('SAML_Metadata_fetch')}
cancelText={t('Cancel')}
wrapperFunction={(props) => (
<Box
is='form'
onSubmit={(e) => {
e.preventDefault();
if (values) {
handleApply();
} else {
void handleFetch();
}
}}
{...props}
/>
)}
onCancel={onClose}
onClose={onClose}
confirmDisabled={fetching || (!values && url.trim() === '')}
confirmLoading={fetching}
>
<Box display='flex' flexDirection='column'>
<Box marginBlockEnd={16}>{t('SAML_Metadata_modal_description')}</Box>
<Field>
<FieldLabel htmlFor={urlFieldId}>{t('SAML_Metadata_url')}</FieldLabel>
<FieldRow>
<TextInput
id={urlFieldId}
value={url}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setUrl(e.currentTarget.value);
setValues(null);
setError(null);
setWarnings([]);
}}
/>
</FieldRow>
</Field>
{error && (
<Callout type='danger' marginBlockStart={16}>
{t(error as Parameters<typeof t>[0])}
</Callout>
)}
{warnings.map((warning) => (
<Callout key={warning} type='warning' marginBlockStart={16}>
{t(warning as Parameters<typeof t>[0])}
</Callout>
))}
{values && (
<>
<Field marginBlockStart={16}>
<FieldLabel htmlFor={entryPointFieldId}>{t('SAML_Custom_Entry_point')}</FieldLabel>
<FieldRow>
<TextInput
id={entryPointFieldId}
value={values.entryPoint ?? ''}
placeholder={t('SAML_Metadata_not_found')}
onChange={setValue('entryPoint')}
/>
</FieldRow>
</Field>
<Field marginBlockStart={16}>
<FieldLabel htmlFor={sloFieldId}>{t('SAML_Custom_IDP_SLO_Redirect_URL')}</FieldLabel>
<FieldRow>
<TextInput
id={sloFieldId}
value={values.idpSLORedirectURL ?? ''}
placeholder={t('SAML_Metadata_not_found')}
onChange={setValue('idpSLORedirectURL')}
/>
</FieldRow>
</Field>
<Field marginBlockStart={16}>
<FieldLabel htmlFor={certFieldId}>{t('SAML_Custom_Cert')}</FieldLabel>
<FieldRow>
<TextAreaInput
id={certFieldId}
rows={5}
value={values.cert ?? ''}
placeholder={t('SAML_Metadata_not_found')}
onChange={setValue('cert')}
/>
</FieldRow>
</Field>
{showIdentifierFormat && (
<Field marginBlockStart={16}>
<FieldLabel htmlFor={identifierFormatFieldId}>{t('SAML_Identifier_Format')}</FieldLabel>
<FieldRow>
<TextInput
id={identifierFormatFieldId}
value={values.identifierFormat ?? ''}
placeholder={t('SAML_Metadata_not_found')}
onChange={setValue('identifierFormat')}
/>
</FieldRow>
</Field>
)}
</>
)}
</Box>
</GenericModal>
);
};
export default SamlMetadataModal;

View File

@@ -0,0 +1 @@
export { default } from './SAMLGroupPage';