From fd720572e78f45ee3267bb95355e4e617e0dd2e0 Mon Sep 17 00:00:00 2001 From: Kirill Date: Sat, 23 May 2026 11:09:21 +0500 Subject: [PATCH] fix: export build403Html, add unit test for undefined IP fallback --- server/src/plugins/__tests__/ip-gate.test.js | 14 +++++++++++++- server/src/plugins/ip-gate.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/server/src/plugins/__tests__/ip-gate.test.js b/server/src/plugins/__tests__/ip-gate.test.js index 78871f3..08f2f63 100644 --- a/server/src/plugins/__tests__/ip-gate.test.js +++ b/server/src/plugins/__tests__/ip-gate.test.js @@ -1,6 +1,6 @@ import Fastify from 'fastify' import { afterEach, beforeEach, describe, expect, it } from 'vitest' -import { registerIpGate } from '../ip-gate.js' +import { build403Html, registerIpGate } from '../ip-gate.js' function buildApp() { const app = Fastify({ logger: false, trustProxy: true }) @@ -55,6 +55,18 @@ describe('registerIpGate', () => { expect(res.body).toContain('9.9.9.9') }) + it('build403Html показывает "не определён" когда IP не передан', () => { + const html = build403Html() + expect(html).toContain('не определён') + expect(html).toContain('Любимый Креатив') + }) + + it('build403Html показывает переданный IP', () => { + const html = build403Html('9.9.9.9') + expect(html).toContain('9.9.9.9') + expect(html).not.toContain('не определён') + }) + it('403-страница показывает IP по умолчанию (127.0.0.1) когда remoteAddress не указан', async () => { process.env.SITE_ACCESS_IPS = '1.2.3.4' const res = await app.inject({ method: 'GET', url: '/test' }) diff --git a/server/src/plugins/ip-gate.js b/server/src/plugins/ip-gate.js index 9915570..3da7dc0 100644 --- a/server/src/plugins/ip-gate.js +++ b/server/src/plugins/ip-gate.js @@ -12,7 +12,7 @@ function normalizeIp(ip) { return ip } -function build403Html(ip) { +export function build403Html(ip) { const safeIp = ip || 'не определён' return `