Перенесена кодовая база и инфраструктура lab6: NestJS-приложение (API +
worker, RabbitMQ, outbox, S3, OpenTelemetry), Dockerfile, compose.yaml,
infra/{grafana,haproxy,loki,minio,otel/collector.yaml,prometheus,
rabbitmq,tempo}, docs/runbooks, стендовые скрипты, scripts/lab{4,5,6} и
contracts/extensions.openapi.json.
Задание lab7 оставлено своим: README, REPORT, COURSE, CONTRIBUTING,
MAINTAINERS, lab.json, contracts/{openapi,infrastructure,jobs.schema,
attachment-states,examples,observability,trust-matrix,README},
security/THREAT_MODEL.md, tests (включая security.py), compose.example.yaml,
infra/{openbao,otel}/README.md, .github/pull_request_template.md.
Не переносились старые evidence/lab4..lab6 (18 МБ трека lab6) и
неотслеживаемый docs/lab6.html.
Адаптации при переносе:
- docker-проект mtusi-lab6 -> mtusi-lab7, тег образа mtusi-messenger:lab7
и папка Grafana Messenger lab7 (compose.yaml, scripts/stop-one.sh,
.env.example, infra/README.md, infra/grafana/provisioning/dashboards),
чтобы тома и контейнеры не пересекались с lab6;
- Makefile: сохранены BASE_URL=https://localhost:8443 и цель test-security
из skeleton lab7, добавлены стендовые и проверочные цели lab6;
- .env.example: рабочие переменные приложения и стенда lab6 + блок
переменных lab7 (PUBLIC_BASE_URL, TLS_*, BAO_*, ARGON2_*) из skeleton.
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { validate } from 'class-validator';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { CodePointLength } from './code-point-length.js';
|
|
|
|
class Sample {
|
|
@CodePointLength(3, 5)
|
|
value!: string;
|
|
}
|
|
|
|
async function fails(value: unknown): Promise<boolean> {
|
|
const sample = new Sample();
|
|
(sample as { value: unknown }).value = value;
|
|
const errors = await validate(sample);
|
|
return errors.length > 0;
|
|
}
|
|
|
|
describe('CodePointLength', () => {
|
|
it('counts Unicode code points instead of UTF-16 units', async () => {
|
|
// '🔐' is one code point but two UTF-16 units.
|
|
expect(await fails('🔐🔐')).toBe(true);
|
|
expect(await fails('🔐🔐🔐')).toBe(false);
|
|
expect(await fails('🔐🔐🔐🔐🔐')).toBe(false);
|
|
expect(await fails('🔐🔐🔐🔐🔐🔐')).toBe(true);
|
|
// Combining marks are separate code points, not grapheme clusters:
|
|
// three 'é' sequences are six code points and exceed the maximum.
|
|
expect(await fails('e\u0301e\u0301')).toBe(false);
|
|
expect(await fails('e\u0301e\u0301e\u0301')).toBe(true);
|
|
});
|
|
|
|
it('applies to BMP text boundaries', async () => {
|
|
expect(await fails('ab')).toBe(true);
|
|
expect(await fails('abc')).toBe(false);
|
|
expect(await fails('abcde')).toBe(false);
|
|
expect(await fails('abcdef')).toBe(true);
|
|
});
|
|
|
|
it('rejects empty and non-string values', async () => {
|
|
expect(await fails('')).toBe(true);
|
|
expect(await fails(undefined)).toBe(true);
|
|
expect(await fails(12345)).toBe(true);
|
|
expect(await fails(['a', 'b', 'c'])).toBe(true);
|
|
});
|
|
});
|