/
vasya2
/
var
Обзор
Документация
Войти
/
vasya2
/
var
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
api/src/plugins/cors.test.ts
47 строк
1 KB
Oliver Eyton-Williams
fix: only log if the request has an Origin header (#59920)
23 апр 2025, 23:50
Не верифицирован
23 апр 2025, 23:50
db07c71
Код
Авторство
О чём код?
import Fastify, { FastifyInstance, LogLevel } from 'fastify'; import cors from './cors'; const LOG_LEVELS: LogLevel[] = [ 'fatal', 'error', 'warn', 'info', 'debug', 'trace' ]; describe('cors', () => { let fastify: FastifyInstance; beforeAll(async () => { fastify = Fastify({ disableRequestLogging: true }); await fastify.register(cors); }); afterAll(async () => { await fastify.close(); }); it('should not log for /status/* routes', async () => { const logger = fastify.log.child({ req: { url: '/status/ping' } }); const spies = LOG_LEVELS.map(level => jest.spyOn(logger, level)); await fastify.inject({ url: '/status/ping' }); spies.forEach(spy => { expect(spy).not.toHaveBeenCalled(); }); }); it('should not log if the origin is undefined', async () => { const logger = fastify.log.child({ req: { url: '/api/some-endpoint' } }); const spies = LOG_LEVELS.map(level => jest.spyOn(logger, level)); await fastify.inject({ url: '/api/some-endpoint' }); spies.forEach(spy => { expect(spy).not.toHaveBeenCalled(); }); }); });