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
80 lines
3.4 KiB
TypeScript
80 lines
3.4 KiB
TypeScript
/**
|
|
* @jest-environment node
|
|
*/
|
|
import { ajv } from '@rocket.chat/rest-typings';
|
|
|
|
import type { ClassificationBannersConfig } from './types';
|
|
import schema from '../../../../../../../ee/packages/abac/docs/classification-banners.schema.json';
|
|
|
|
const validate = ajv.compile(schema);
|
|
|
|
const validConfig: ClassificationBannersConfig & { $schema: string } = {
|
|
$schema: 'https://rocket.chat/schemas/classification-banners/v1.json',
|
|
version: 1,
|
|
enabled: true,
|
|
banner: {
|
|
style: 'classic',
|
|
uppercase: true,
|
|
monospace: false,
|
|
delimiter: ' // ',
|
|
colorMode: 'highest',
|
|
fallbackText: 'NO CLASSIFICATION DATA',
|
|
fallbackColor: '#6C727A',
|
|
},
|
|
attributes: [
|
|
{
|
|
id: 'classification',
|
|
source: 'clearance.level',
|
|
label: 'Classification level',
|
|
showInBanner: true,
|
|
showLabel: false,
|
|
bannerLabel: '',
|
|
labelSeparator: '',
|
|
valueSeparator: '/',
|
|
sortAlpha: false,
|
|
groupThreshold: 0,
|
|
multipleLabel: '',
|
|
drivesColor: true,
|
|
values: [
|
|
{ source: 'TS', label: 'TOP SECRET', color: '#ff8c00' },
|
|
{ source: 'U', label: 'UNCLASSIFIED', color: '#007a33' },
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const { banner } = validConfig;
|
|
const [attribute] = validConfig.attributes;
|
|
const [value] = attribute.values;
|
|
|
|
describe('classification banners JSON schema (v1 enforcement contract)', () => {
|
|
it('accepts a complete document typed as ClassificationBannersConfig', () => {
|
|
expect(validate(validConfig)).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
['wrong version', { ...validConfig, version: 2 }],
|
|
['missing banner option (colorMode)', { ...validConfig, banner: { ...banner, colorMode: undefined } }],
|
|
['empty delimiter', { ...validConfig, banner: { ...banner, delimiter: '' } }],
|
|
['oversized delimiter', { ...validConfig, banner: { ...banner, delimiter: 'x'.repeat(9) } }],
|
|
['empty fallbackText', { ...validConfig, banner: { ...banner, fallbackText: '' } }],
|
|
['malformed fallbackColor', { ...validConfig, banner: { ...banner, fallbackColor: 'red' } }],
|
|
['unknown banner option', { ...validConfig, banner: { ...banner, position: 'top' } }],
|
|
['unknown top-level property', { ...validConfig, source: 'idp' }],
|
|
['empty attributes', { ...validConfig, attributes: [] }],
|
|
['identical duplicate attributes', { ...validConfig, attributes: [attribute, attribute] }],
|
|
['missing attribute field (drivesColor)', { ...validConfig, attributes: [{ ...attribute, drivesColor: undefined }] }],
|
|
['uppercase attribute id', { ...validConfig, attributes: [{ ...attribute, id: 'Classification' }] }],
|
|
['invalid labelSeparator', { ...validConfig, attributes: [{ ...attribute, labelSeparator: '::' }] }],
|
|
['invalid valueSeparator', { ...validConfig, attributes: [{ ...attribute, valueSeparator: '|' }] }],
|
|
['groupThreshold of 1', { ...validConfig, attributes: [{ ...attribute, groupThreshold: 1 }] }],
|
|
['groupThreshold above 20', { ...validConfig, attributes: [{ ...attribute, groupThreshold: 21 }] }],
|
|
['empty values', { ...validConfig, attributes: [{ ...attribute, values: [] }] }],
|
|
['identical duplicate values', { ...validConfig, attributes: [{ ...attribute, values: [value, value] }] }],
|
|
['value with 3-digit color', { ...validConfig, attributes: [{ ...attribute, values: [{ ...value, color: '#fff' }] }] }],
|
|
['value missing label', { ...validConfig, attributes: [{ ...attribute, values: [{ ...value, label: undefined }] }] }],
|
|
])('rejects %s', (_name, config) => {
|
|
expect(validate(config)).toBe(false);
|
|
});
|
|
});
|